Linux premium155.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
LiteSpeed
: 162.0.235.200 | : 3.137.162.21
Cant Read [ /etc/named.conf ]
7.4.33
varifktc
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
opt /
cloudlinux /
venv /
lib /
python3.11 /
site-packages /
[ HOME SHELL ]
Name
Size
Permission
Action
GitPython-3.1.32.dist-info
[ DIR ]
drwxr-xr-x
Jinja2-3.0.3.dist-info
[ DIR ]
drwxr-xr-x
Mako-1.2.4.dist-info
[ DIR ]
drwxr-xr-x
MarkupSafe-2.1.3.dist-info
[ DIR ]
drwxr-xr-x
PyJWT-2.8.0.dist-info
[ DIR ]
drwxr-xr-x
PyMySQL-1.1.0.dist-info
[ DIR ]
drwxr-xr-x
PyVirtualDisplay-3.0.dist-info
[ DIR ]
drwxr-xr-x
PyYAML-6.0.1.dist-info
[ DIR ]
drwxr-xr-x
SQLAlchemy-1.3.24.dist-info
[ DIR ]
drwxr-xr-x
__pycache__
[ DIR ]
drwxr-xr-x
_distutils_hack
[ DIR ]
drwxr-xr-x
_pytest
[ DIR ]
drwxr-xr-x
_yaml
[ DIR ]
drwxr-xr-x
aiohttp
[ DIR ]
drwxr-xr-x
aiohttp-3.9.2.dist-info
[ DIR ]
drwxr-xr-x
aiosignal
[ DIR ]
drwxr-xr-x
aiosignal-1.3.1.dist-info
[ DIR ]
drwxr-xr-x
alembic
[ DIR ]
drwxr-xr-x
alembic-1.11.1.dist-info
[ DIR ]
drwxr-xr-x
annotated_types
[ DIR ]
drwxr-xr-x
annotated_types-0.6.0.dist-inf...
[ DIR ]
drwxr-xr-x
astroid
[ DIR ]
drwxr-xr-x
astroid-2.15.6.dist-info
[ DIR ]
drwxr-xr-x
async_timeout
[ DIR ]
drwxr-xr-x
async_timeout-4.0.3.dist-info
[ DIR ]
drwxr-xr-x
attr
[ DIR ]
drwxr-xr-x
attrs
[ DIR ]
drwxr-xr-x
attrs-23.1.0.dist-info
[ DIR ]
drwxr-xr-x
certifi
[ DIR ]
drwxr-xr-x
certifi-2023.7.22.dist-info
[ DIR ]
drwxr-xr-x
cffi
[ DIR ]
drwxr-xr-x
cffi-1.15.1.dist-info
[ DIR ]
drwxr-xr-x
chardet
[ DIR ]
drwxr-xr-x
chardet-5.2.0.dist-info
[ DIR ]
drwxr-xr-x
charset_normalizer
[ DIR ]
drwxr-xr-x
charset_normalizer-2.1.1.dist-...
[ DIR ]
drwxr-xr-x
cl_dom_collector
[ DIR ]
drwxr-xr-x
clcagefslib
[ DIR ]
drwxr-xr-x
clcommon
[ DIR ]
drwxr-xr-x
clconfig
[ DIR ]
drwxr-xr-x
clconfigure
[ DIR ]
drwxr-xr-x
cldashboard
[ DIR ]
drwxr-xr-x
clevents
[ DIR ]
drwxr-xr-x
clflags
[ DIR ]
drwxr-xr-x
cllicense
[ DIR ]
drwxr-xr-x
cllimits
[ DIR ]
drwxr-xr-x
cllimits_validator
[ DIR ]
drwxr-xr-x
cllimitslib_v2
[ DIR ]
drwxr-xr-x
cllvectl
[ DIR ]
drwxr-xr-x
clpackages
[ DIR ]
drwxr-xr-x
clquota
[ DIR ]
drwxr-xr-x
clselect
[ DIR ]
drwxr-xr-x
clselector
[ DIR ]
drwxr-xr-x
clsentry
[ DIR ]
drwxr-xr-x
clsummary
[ DIR ]
drwxr-xr-x
clveconfig
[ DIR ]
drwxr-xr-x
clwizard
[ DIR ]
drwxr-xr-x
colorama
[ DIR ]
drwxr-xr-x
colorama-0.4.6.dist-info
[ DIR ]
drwxr-xr-x
contextlib2
[ DIR ]
drwxr-xr-x
contextlib2-21.6.0.dist-info
[ DIR ]
drwxr-xr-x
coverage
[ DIR ]
drwxr-xr-x
coverage-7.2.7.dist-info
[ DIR ]
drwxr-xr-x
cryptography
[ DIR ]
drwxr-xr-x
cryptography-41.0.2.dist-info
[ DIR ]
drwxr-xr-x
ddt-1.4.4.dist-info
[ DIR ]
drwxr-xr-x
dill
[ DIR ]
drwxr-xr-x
dill-0.3.7.dist-info
[ DIR ]
drwxr-xr-x
distlib
[ DIR ]
drwxr-xr-x
distlib-0.3.8.dist-info
[ DIR ]
drwxr-xr-x
docopt-0.6.2.dist-info
[ DIR ]
drwxr-xr-x
dodgy
[ DIR ]
drwxr-xr-x
dodgy-0.2.1.dist-info
[ DIR ]
drwxr-xr-x
filelock
[ DIR ]
drwxr-xr-x
filelock-3.13.1.dist-info
[ DIR ]
drwxr-xr-x
flake8
[ DIR ]
drwxr-xr-x
flake8-5.0.4.dist-info
[ DIR ]
drwxr-xr-x
flake8_polyfill
[ DIR ]
drwxr-xr-x
flake8_polyfill-1.0.2.dist-inf...
[ DIR ]
drwxr-xr-x
frozenlist
[ DIR ]
drwxr-xr-x
frozenlist-1.4.0.dist-info
[ DIR ]
drwxr-xr-x
future
[ DIR ]
drwxr-xr-x
future-0.18.3.dist-info
[ DIR ]
drwxr-xr-x
git
[ DIR ]
drwxr-xr-x
gitdb
[ DIR ]
drwxr-xr-x
gitdb-4.0.10.dist-info
[ DIR ]
drwxr-xr-x
guppy
[ DIR ]
drwxr-xr-x
guppy3-3.1.3.dist-info
[ DIR ]
drwxr-xr-x
hc_json_rpc_client
[ DIR ]
drwxr-xr-x
hc_json_rpc_client-1.0.1.dist-...
[ DIR ]
drwxr-xr-x
idna
[ DIR ]
drwxr-xr-x
idna-3.4.dist-info
[ DIR ]
drwxr-xr-x
iniconfig
[ DIR ]
drwxr-xr-x
iniconfig-2.0.0.dist-info
[ DIR ]
drwxr-xr-x
isort
[ DIR ]
drwxr-xr-x
isort-5.12.0.dist-info
[ DIR ]
drwxr-xr-x
jinja2
[ DIR ]
drwxr-xr-x
jsonschema
[ DIR ]
drwxr-xr-x
jsonschema-3.2.0.dist-info
[ DIR ]
drwxr-xr-x
jwt
[ DIR ]
drwxr-xr-x
lazy_object_proxy
[ DIR ]
drwxr-xr-x
lazy_object_proxy-1.9.0.dist-i...
[ DIR ]
drwxr-xr-x
libfuturize
[ DIR ]
drwxr-xr-x
libpasteurize
[ DIR ]
drwxr-xr-x
lve_stats-2.0.dist-info
[ DIR ]
drwxr-xr-x
lve_utils
[ DIR ]
drwxr-xr-x
lvemanager
[ DIR ]
drwxr-xr-x
lvestats
[ DIR ]
drwxr-xr-x
lxml
[ DIR ]
drwxr-xr-x
lxml-4.9.2.dist-info
[ DIR ]
drwxr-xr-x
mako
[ DIR ]
drwxr-xr-x
markupsafe
[ DIR ]
drwxr-xr-x
mccabe-0.7.0.dist-info
[ DIR ]
drwxr-xr-x
mock
[ DIR ]
drwxr-xr-x
mock-5.1.0.dist-info
[ DIR ]
drwxr-xr-x
multidict
[ DIR ]
drwxr-xr-x
multidict-6.0.4.dist-info
[ DIR ]
drwxr-xr-x
numpy
[ DIR ]
drwxr-xr-x
numpy-1.25.1.dist-info
[ DIR ]
drwxr-xr-x
numpy.libs
[ DIR ]
drwxr-xr-x
packaging
[ DIR ]
drwxr-xr-x
packaging-23.1.dist-info
[ DIR ]
drwxr-xr-x
past
[ DIR ]
drwxr-xr-x
pep8_naming-0.10.0.dist-info
[ DIR ]
drwxr-xr-x
pip
[ DIR ]
drwxr-xr-x
pip-24.1.2.dist-info
[ DIR ]
drwxr-xr-x
pkg_resources
[ DIR ]
drwxr-xr-x
platformdirs
[ DIR ]
drwxr-xr-x
platformdirs-3.11.0.dist-info
[ DIR ]
drwxr-xr-x
pluggy
[ DIR ]
drwxr-xr-x
pluggy-1.2.0.dist-info
[ DIR ]
drwxr-xr-x
prettytable
[ DIR ]
drwxr-xr-x
prettytable-3.8.0.dist-info
[ DIR ]
drwxr-xr-x
prometheus_client
[ DIR ]
drwxr-xr-x
prometheus_client-0.8.0.dist-i...
[ DIR ]
drwxr-xr-x
prospector
[ DIR ]
drwxr-xr-x
prospector-1.10.2.dist-info
[ DIR ]
drwxr-xr-x
psutil
[ DIR ]
drwxr-xr-x
psutil-5.9.5.dist-info
[ DIR ]
drwxr-xr-x
psycopg2
[ DIR ]
drwxr-xr-x
psycopg2_binary-2.9.6.dist-inf...
[ DIR ]
drwxr-xr-x
psycopg2_binary.libs
[ DIR ]
drwxr-xr-x
pycodestyle-2.9.1.dist-info
[ DIR ]
drwxr-xr-x
pycparser
[ DIR ]
drwxr-xr-x
pycparser-2.21.dist-info
[ DIR ]
drwxr-xr-x
pydantic
[ DIR ]
drwxr-xr-x
pydantic-2.4.2.dist-info
[ DIR ]
drwxr-xr-x
pydantic_core
[ DIR ]
drwxr-xr-x
pydantic_core-2.10.1.dist-info
[ DIR ]
drwxr-xr-x
pydocstyle
[ DIR ]
drwxr-xr-x
pydocstyle-6.3.0.dist-info
[ DIR ]
drwxr-xr-x
pyfakefs
[ DIR ]
drwxr-xr-x
pyfakefs-5.2.3.dist-info
[ DIR ]
drwxr-xr-x
pyflakes
[ DIR ]
drwxr-xr-x
pyflakes-2.5.0.dist-info
[ DIR ]
drwxr-xr-x
pylint
[ DIR ]
drwxr-xr-x
pylint-2.17.4.dist-info
[ DIR ]
drwxr-xr-x
pylint_celery
[ DIR ]
drwxr-xr-x
pylint_celery-0.3.dist-info
[ DIR ]
drwxr-xr-x
pylint_django
[ DIR ]
drwxr-xr-x
pylint_django-2.5.3.dist-info
[ DIR ]
drwxr-xr-x
pylint_flask
[ DIR ]
drwxr-xr-x
pylint_flask-0.6.dist-info
[ DIR ]
drwxr-xr-x
pylint_plugin_utils
[ DIR ]
drwxr-xr-x
pylint_plugin_utils-0.7.dist-i...
[ DIR ]
drwxr-xr-x
pylve-2.1-py3.11.egg-info
[ DIR ]
drwxr-xr-x
pymysql
[ DIR ]
drwxr-xr-x
pyparsing
[ DIR ]
drwxr-xr-x
pyparsing-3.0.9.dist-info
[ DIR ]
drwxr-xr-x
pyrsistent
[ DIR ]
drwxr-xr-x
pyrsistent-0.19.3.dist-info
[ DIR ]
drwxr-xr-x
pytest
[ DIR ]
drwxr-xr-x
pytest-7.4.0.dist-info
[ DIR ]
drwxr-xr-x
pytest_subprocess
[ DIR ]
drwxr-xr-x
pytest_subprocess-1.5.0.dist-i...
[ DIR ]
drwxr-xr-x
pyvirtualdisplay
[ DIR ]
drwxr-xr-x
raven
[ DIR ]
drwxr-xr-x
raven-6.10.0.dist-info
[ DIR ]
drwxr-xr-x
requests
[ DIR ]
drwxr-xr-x
requests-2.31.0.dist-info
[ DIR ]
drwxr-xr-x
requirements_detector
[ DIR ]
drwxr-xr-x
requirements_detector-1.2.2.di...
[ DIR ]
drwxr-xr-x
schema-0.7.5.dist-info
[ DIR ]
drwxr-xr-x
semver
[ DIR ]
drwxr-xr-x
semver-3.0.1.dist-info
[ DIR ]
drwxr-xr-x
sentry_sdk
[ DIR ]
drwxr-xr-x
sentry_sdk-1.29.2.dist-info
[ DIR ]
drwxr-xr-x
setoptconf
[ DIR ]
drwxr-xr-x
setoptconf_tmp-0.3.1.dist-info
[ DIR ]
drwxr-xr-x
setuptools
[ DIR ]
drwxr-xr-x
setuptools-70.2.0.dist-info
[ DIR ]
drwxr-xr-x
simplejson
[ DIR ]
drwxr-xr-x
simplejson-3.19.1.dist-info
[ DIR ]
drwxr-xr-x
six-1.16.0.dist-info
[ DIR ]
drwxr-xr-x
smmap
[ DIR ]
drwxr-xr-x
smmap-5.0.0.dist-info
[ DIR ]
drwxr-xr-x
snowballstemmer
[ DIR ]
drwxr-xr-x
snowballstemmer-2.2.0.dist-inf...
[ DIR ]
drwxr-xr-x
sqlalchemy
[ DIR ]
drwxr-xr-x
ssa
[ DIR ]
drwxr-xr-x
svgwrite
[ DIR ]
drwxr-xr-x
svgwrite-1.4.3.dist-info
[ DIR ]
drwxr-xr-x
tap
[ DIR ]
drwxr-xr-x
tap.py-3.1.dist-info
[ DIR ]
drwxr-xr-x
testfixtures
[ DIR ]
drwxr-xr-x
testfixtures-7.1.0.dist-info
[ DIR ]
drwxr-xr-x
toml
[ DIR ]
drwxr-xr-x
toml-0.10.2.dist-info
[ DIR ]
drwxr-xr-x
tomlkit
[ DIR ]
drwxr-xr-x
tomlkit-0.11.8.dist-info
[ DIR ]
drwxr-xr-x
typing_extensions-4.8.0.dist-i...
[ DIR ]
drwxr-xr-x
unshare-0.22.dist-info
[ DIR ]
drwxr-xr-x
urllib3
[ DIR ]
drwxr-xr-x
urllib3-2.0.4.dist-info
[ DIR ]
drwxr-xr-x
vendors_api
[ DIR ]
drwxr-xr-x
virtualenv
[ DIR ]
drwxr-xr-x
virtualenv-20.21.1.dist-info
[ DIR ]
drwxr-xr-x
wcwidth
[ DIR ]
drwxr-xr-x
wcwidth-0.2.6.dist-info
[ DIR ]
drwxr-xr-x
wmt
[ DIR ]
drwxr-xr-x
wrapt
[ DIR ]
drwxr-xr-x
wrapt-1.15.0.dist-info
[ DIR ]
drwxr-xr-x
yaml
[ DIR ]
drwxr-xr-x
yarl
[ DIR ]
drwxr-xr-x
yarl-1.9.2.dist-info
[ DIR ]
drwxr-xr-x
_cffi_backend.cpython-311-x86_...
267.63
KB
-rwxr-xr-x
_pyrsistent_version.py
23
B
-rw-r--r--
cl_proc_hidepid.py
4.53
KB
-rw-r--r--
clcontrollib.py
51.73
KB
-rw-r--r--
cldetectlib.py
18.13
KB
-rw-r--r--
cldiaglib.py
45.57
KB
-rw-r--r--
clhooklib.py
1.27
KB
-rw-r--r--
cli_utils.py
1.66
KB
-rw-r--r--
cllicenselib.py
9.1
KB
-rw-r--r--
clsetuplib.py
4.35
KB
-rw-r--r--
clsudo.py
14.42
KB
-rw-r--r--
ddt.py
12.43
KB
-rw-r--r--
distutils-precedence.pth
151
B
-rw-r--r--
docopt.py
19.48
KB
-rw-r--r--
hc_lve_profiler.py
6.2
KB
-rw-------
lveapi.py
19.53
KB
-rw-r--r--
lvectllib.py
102.55
KB
-rw-r--r--
lvestat.py
6.83
KB
-rw-r--r--
mccabe.py
10.4
KB
-rw-r--r--
pep8ext_naming.py
18.61
KB
-rw-r--r--
py.py
263
B
-rw-r--r--
pycodestyle.py
101.08
KB
-rw-r--r--
pylve.cpython-311-x86_64-linux...
25.48
KB
-rwxr-xr-x
remove_ubc.py
5.73
KB
-rwxr-xr-x
schema.py
29.51
KB
-rw-r--r--
secureio.py
18.83
KB
-rw-r--r--
simple_rpm.so
11.29
KB
-rwxr-xr-x
six.py
33.74
KB
-rw-r--r--
typing_extensions.py
100.97
KB
-rw-r--r--
unshare.cpython-311-x86_64-lin...
8.17
KB
-rwxr-xr-x
Delete
Unzip
Zip
${this.title}
Close
Code Editor : ddt.py
# -*- coding: utf-8 -*- # This file is a part of DDT (https://github.com/datadriventests/ddt) # Copyright 2012-2015 Carles Barrobés and DDT contributors # For the exact contribution history, see the git revision log. # DDT is licensed under the MIT License, included in # https://github.com/datadriventests/ddt/blob/master/LICENSE.md import codecs import inspect import json import os import re from enum import Enum, unique from functools import wraps try: import yaml except ImportError: # pragma: no cover _have_yaml = False else: _have_yaml = True __version__ = '1.4.4' # These attributes will not conflict with any real python attribute # They are added to the decorated test method and processed later # by the `ddt` class decorator. DATA_ATTR = '%values' # store the data the test must run with FILE_ATTR = '%file_path' # store the path to JSON file YAML_LOADER_ATTR = '%yaml_loader' # store custom yaml loader for serialization UNPACK_ATTR = '%unpack' # remember that we have to unpack values INDEX_LEN = '%index_len' # store the index length of the data try: trivial_types = (type(None), bool, int, float, basestring) except NameError: trivial_types = (type(None), bool, int, float, str) @unique class TestNameFormat(Enum): """ An enum to configure how ``mk_test_name()`` to compose a test name. Given the following example: .. code-block:: python @data("a", "b") def testSomething(self, value): ... if using just ``@ddt`` or together with ``DEFAULT``: * ``testSomething_1_a`` * ``testSomething_2_b`` if using ``INDEX_ONLY``: * ``testSomething_1`` * ``testSomething_2`` """ DEFAULT = 0 INDEX_ONLY = 1 def is_trivial(value): if isinstance(value, trivial_types): return True elif isinstance(value, (list, tuple)): return all(map(is_trivial, value)) return False def unpack(func): """ Method decorator to add unpack feature. """ setattr(func, UNPACK_ATTR, True) return func def data(*values): """ Method decorator to add to your test methods. Should be added to methods of instances of ``unittest.TestCase``. """ return idata(values) def idata(iterable, index_len=None): """ Method decorator to add to your test methods. Should be added to methods of instances of ``unittest.TestCase``. :param iterable: iterable of the values to provide to the test function. :param index_len: an optional integer specifying the width to zero-pad the test identifier indices to. If not provided, this will add the fewest zeros necessary to make all identifiers the same length. """ if index_len is None: # Avoid consuming a one-time-use generator. iterable = tuple(iterable) index_len = len(str(len(iterable))) def wrapper(func): setattr(func, DATA_ATTR, iterable) setattr(func, INDEX_LEN, index_len) return func return wrapper def file_data(value, yaml_loader=None): """ Method decorator to add to your test methods. Should be added to methods of instances of ``unittest.TestCase``. ``value`` should be a path relative to the directory of the file containing the decorated ``unittest.TestCase``. The file should contain JSON encoded data, that can either be a list or a dict. In case of a list, each value in the list will correspond to one test case, and the value will be concatenated to the test method name. In case of a dict, keys will be used as suffixes to the name of the test case, and values will be fed as test data. ``yaml_loader`` can be used to customize yaml deserialization. The default is ``None``, which results in using the ``yaml.safe_load`` method. """ def wrapper(func): setattr(func, FILE_ATTR, value) if yaml_loader: setattr(func, YAML_LOADER_ATTR, yaml_loader) return func return wrapper def mk_test_name(name, value, index=0, index_len=5, name_fmt=TestNameFormat.DEFAULT): """ Generate a new name for a test case. It will take the original test name and append an ordinal index and a string representation of the value, and convert the result into a valid python identifier by replacing extraneous characters with ``_``. We avoid doing str(value) if dealing with non-trivial values. The problem is possible different names with different runs, e.g. different order of dictionary keys (see PYTHONHASHSEED) or dealing with mock objects. Trivial scalar values are passed as is. A "trivial" value is a plain scalar, or a tuple or list consisting only of trivial values. The test name format is controlled by enum ``TestNameFormat`` as well. See the enum documentation for further details. """ # Add zeros before index to keep order index = "{0:0{1}}".format(index + 1, index_len) if name_fmt is TestNameFormat.INDEX_ONLY or not is_trivial(value): return "{0}_{1}".format(name, index) try: value = str(value) except UnicodeEncodeError: # fallback for python2 value = value.encode('ascii', 'backslashreplace') test_name = "{0}_{1}_{2}".format(name, index, value) return re.sub(r'\W|^(?=\d)', '_', test_name) def feed_data(func, new_name, test_data_docstring, *args, **kwargs): """ This internal method decorator feeds the test data item to the test. """ @wraps(func) def wrapper(self): return func(self, *args, **kwargs) wrapper.__name__ = new_name wrapper.__wrapped__ = func # set docstring if exists if test_data_docstring is not None: wrapper.__doc__ = test_data_docstring else: # Try to call format on the docstring if func.__doc__: try: wrapper.__doc__ = func.__doc__.format(*args, **kwargs) except (IndexError, KeyError): # Maybe the user has added some of the formating strings # unintentionally in the docstring. Do not raise an exception # as it could be that user is not aware of the # formating feature. pass return wrapper def add_test(cls, test_name, test_docstring, func, *args, **kwargs): """ Add a test case to this class. The test will be based on an existing function but will give it a new name. """ setattr(cls, test_name, feed_data(func, test_name, test_docstring, *args, **kwargs)) def process_file_data(cls, name, func, file_attr): """ Process the parameter in the `file_data` decorator. """ cls_path = os.path.abspath(inspect.getsourcefile(cls)) data_file_path = os.path.join(os.path.dirname(cls_path), file_attr) def create_error_func(message): # pylint: disable-msg=W0613 def func(*args): raise ValueError(message % file_attr) return func # If file does not exist, provide an error function instead if not os.path.exists(data_file_path): test_name = mk_test_name(name, "error") test_docstring = """Error!""" add_test(cls, test_name, test_docstring, create_error_func("%s does not exist"), None) return _is_yaml_file = data_file_path.endswith((".yml", ".yaml")) # Don't have YAML but want to use YAML file. if _is_yaml_file and not _have_yaml: test_name = mk_test_name(name, "error") test_docstring = """Error!""" add_test( cls, test_name, test_docstring, create_error_func("%s is a YAML file, please install PyYAML"), None ) return with codecs.open(data_file_path, 'r', 'utf-8') as f: # Load the data from YAML or JSON if _is_yaml_file: if hasattr(func, YAML_LOADER_ATTR): yaml_loader = getattr(func, YAML_LOADER_ATTR) data = yaml.load(f, Loader=yaml_loader) else: data = yaml.safe_load(f) else: data = json.load(f) _add_tests_from_data(cls, name, func, data) def _add_tests_from_data(cls, name, func, data): """ Add tests from data loaded from the data file into the class """ index_len = len(str(len(data))) for i, elem in enumerate(data): if isinstance(data, dict): key, value = elem, data[elem] test_name = mk_test_name(name, key, i, index_len) elif isinstance(data, list): value = elem test_name = mk_test_name(name, value, i, index_len) if isinstance(value, dict): add_test(cls, test_name, test_name, func, **value) else: add_test(cls, test_name, test_name, func, value) def _is_primitive(obj): """Finds out if the obj is a "primitive". It is somewhat hacky but it works. """ return not hasattr(obj, '__dict__') def _get_test_data_docstring(func, value): """Returns a docstring based on the following resolution strategy: 1. Passed value is not a "primitive" and has a docstring, then use it. 2. In all other cases return None, i.e the test name is used. """ if not _is_primitive(value) and value.__doc__: return value.__doc__ else: return None def ddt(arg=None, **kwargs): """ Class decorator for subclasses of ``unittest.TestCase``. Apply this decorator to the test case class, and then decorate test methods with ``@data``. For each method decorated with ``@data``, this will effectively create as many methods as data items are passed as parameters to ``@data``. The names of the test methods follow the pattern ``original_test_name_{ordinal}_{data}``. ``ordinal`` is the position of the data argument, starting with 1. For data we use a string representation of the data value converted into a valid python identifier. If ``data.__name__`` exists, we use that instead. For each method decorated with ``@file_data('test_data.json')``, the decorator will try to load the test_data.json file located relative to the python file containing the method that is decorated. It will, for each ``test_name`` key create as many methods in the list of values from the ``data`` key. Decorating with the keyword argument ``testNameFormat`` can control the format of the generated test names. For example: - ``@ddt(testNameFormat=TestNameFormat.DEFAULT)`` will be index and values. - ``@ddt(testNameFormat=TestNameFormat.INDEX_ONLY)`` will be index only. - ``@ddt`` is the same as DEFAULT. """ fmt_test_name = kwargs.get("testNameFormat", TestNameFormat.DEFAULT) def wrapper(cls): for name, func in list(cls.__dict__.items()): if hasattr(func, DATA_ATTR): index_len = getattr(func, INDEX_LEN) for i, v in enumerate(getattr(func, DATA_ATTR)): test_name = mk_test_name( name, getattr(v, "__name__", v), i, index_len, fmt_test_name ) test_data_docstring = _get_test_data_docstring(func, v) if hasattr(func, UNPACK_ATTR): if isinstance(v, tuple) or isinstance(v, list): add_test( cls, test_name, test_data_docstring, func, *v ) else: # unpack dictionary add_test( cls, test_name, test_data_docstring, func, **v ) else: add_test(cls, test_name, test_data_docstring, func, v) delattr(cls, name) elif hasattr(func, FILE_ATTR): file_attr = getattr(func, FILE_ATTR) process_file_data(cls, name, func, file_attr) delattr(cls, name) return cls # ``arg`` is the unittest's test class when decorating with ``@ddt`` while # it is ``None`` when decorating a test class with ``@ddt(k=v)``. return wrapper(arg) if inspect.isclass(arg) else wrapper
Close