From f3a11f97912e360c4a11ff8e50f67032716748ac Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 15 Sep 2022 19:16:52 +0200 Subject: [PATCH] Improved version command & fixed unittests --- src/cpl_cli/command/version_service.py | 35 ++++++------------ src/cpl_discord/container/guild.py | 2 +- src/cpl_query/iterable/iterable_abc.py | 7 +++- unittests/unittests_cli/version_test_case.py | 37 +++++++------------ .../iterable_query_test_case.py | 4 +- .../unittests_query/performance_test_case.py | 4 +- unittests/unittests_shared/cli_commands.py | 2 +- 7 files changed, 36 insertions(+), 55 deletions(-) diff --git a/src/cpl_cli/command/version_service.py b/src/cpl_cli/command/version_service.py index 7b74b007..3f5d705d 100644 --- a/src/cpl_cli/command/version_service.py +++ b/src/cpl_cli/command/version_service.py @@ -31,6 +31,16 @@ class VersionService(CommandABC): :param args: :return: """ + packages = [] + cpl_packages = [] + dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set) + for p in dependencies: + if str(p).startswith('cpl-'): + cpl_packages.append([p, dependencies[p]]) + continue + + packages.append([p, dependencies[p]]) + Console.set_foreground_color(ForegroundColorEnum.yellow) Console.banner('CPL CLI') Console.set_foreground_color(ForegroundColorEnum.default) @@ -40,31 +50,8 @@ class VersionService(CommandABC): Console.write_line(f'Python: ') Console.write(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}') - Console.write_line(f'OS: {platform.system()} {platform.processor()}') - Console.write_line('\nCPL packages:') - cpl_packages = [ - 'cpl_core', - 'cpl_cli', - 'cpl_query' - ] - packages = [] - for modname in cpl_packages: - module = pkgutil.find_loader(modname) - if module is None: - break - - module = module.load_module(modname) - if '__version__' in dir(module): - packages.append([f'{modname}', module.__version__]) - - Console.table(['Name', 'Version'], packages) - + Console.table(['Name', 'Version'], cpl_packages) Console.write_line('\nPython packages:') - packages = [] - dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set) - for p in dependencies: - packages.append([p, dependencies[p]]) - Console.table(['Name', 'Version'], packages) diff --git a/src/cpl_discord/container/guild.py b/src/cpl_discord/container/guild.py index 83055d44..5a5a1055 100644 --- a/src/cpl_discord/container/guild.py +++ b/src/cpl_discord/container/guild.py @@ -10,7 +10,7 @@ from cpl_discord.helper.to_containers_converter import ToContainersConverter from cpl_query.extension import List -class Guild(discord.Guild, Container): +class Guild(Container, discord.Guild): def __init__(self, _t: discord.Guild): self._object: discord.Guild = _t diff --git a/src/cpl_query/iterable/iterable_abc.py b/src/cpl_query/iterable/iterable_abc.py index cc6672a4..5c6c47db 100644 --- a/src/cpl_query/iterable/iterable_abc.py +++ b/src/cpl_query/iterable/iterable_abc.py @@ -10,8 +10,13 @@ class IterableABC(list, QueryableABC): @abstractmethod def __init__(self, t: type = None, values: Iterable = None): + values = [] if values is None else values + list.__init__(self, values) + + if t is None and len(values) > 0: + t = type(values[0]) + self._type = t - list.__init__(self, [] if values is None else values) def __repr__(self): return f'<{type(self).__name__} {list(self).__repr__()}>' diff --git a/unittests/unittests_cli/version_test_case.py b/unittests/unittests_cli/version_test_case.py index 73a7053a..18e63b14 100644 --- a/unittests/unittests_cli/version_test_case.py +++ b/unittests/unittests_cli/version_test_case.py @@ -42,15 +42,25 @@ class VersionTestCase(unittest.TestCase): if 7 <= index <= 9: self._block_version += f'{line}\n' - if 10 <= index <= 15: + if 10 <= index <= 16: self._block_cpl_packages += f'{line}\n' - if index >= 17: + if index >= 18: self._block_packages += f'{line}\n' index += 1 def test_version(self): + packages = [] + cpl_packages = [] + dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set) + for p in dependencies: + if str(p).startswith('cpl-'): + cpl_packages.append([p, dependencies[p]]) + continue + + packages.append([p, dependencies[p]]) + version = CLICommands.version() self._get_version_output(version) reference_banner = colored(text2art(self._name), ForegroundColorEnum.yellow.value).split('\n') @@ -63,32 +73,11 @@ class VersionTestCase(unittest.TestCase): colored(f'OS: {colored(f"{platform.system()} {platform.processor()}")}') + '\n' ] self.assertEqual('\n'.join(reference_version), self._block_version) - packages = [] - cpl_packages = [ - 'cpl_core', - 'cpl_cli', - 'cpl_query' - ] - for modname in cpl_packages: - module = pkgutil.find_loader(modname) - if module is None: - break - - module = module.load_module(modname) - if '__version__' in dir(module): - packages.append([f'{modname}', module.__version__]) - reference_cpl_packages = [ colored(colored(f'CPL packages:')), - colored(f'{tabulate(packages, headers=["Name", "Version"])}') + '\n' + colored(f'{tabulate(cpl_packages, headers=["Name", "Version"])}') + '\n' ] self.assertEqual('\n'.join(reference_cpl_packages), self._block_cpl_packages) - - packages = [] - dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set) - for p in dependencies: - packages.append([p, dependencies[p]]) - reference_packages = [ colored(colored(f'Python packages:')), colored(f'{tabulate(packages, headers=["Name", "Version"])}'), diff --git a/unittests/unittests_query/iterable_query_test_case.py b/unittests/unittests_query/iterable_query_test_case.py index c3618e17..626a4905 100644 --- a/unittests/unittests_query/iterable_query_test_case.py +++ b/unittests/unittests_query/iterable_query_test_case.py @@ -181,7 +181,7 @@ class IterableQueryTestCase(unittest.TestCase): res = self._tests.max(lambda u: u.address.nr) self.assertEqual(res, self._t_user.address.nr) - tests = List(values=list(range(0, 100))) + tests = List(int, list(range(0, 100))) self.assertEqual(99, tests.max()) def invalid(): @@ -194,7 +194,7 @@ class IterableQueryTestCase(unittest.TestCase): res = self._tests.min(lambda u: u.address.nr) self.assertEqual(1, res) - tests = List(values=list(range(0, 100))) + tests = List(int, list(range(0, 100))) self.assertEqual(0, tests.min()) def invalid(): diff --git a/unittests/unittests_query/performance_test_case.py b/unittests/unittests_query/performance_test_case.py index bc4af12e..904cc4e9 100644 --- a/unittests/unittests_query/performance_test_case.py +++ b/unittests/unittests_query/performance_test_case.py @@ -5,8 +5,8 @@ import unittest from cpl_query.enumerable import Enumerable from cpl_query.iterable import Iterable -VALUES = 1000 -COUNT = 75 +VALUES = 10000 +COUNT = 50 class PerformanceTestCase(unittest.TestCase): diff --git a/unittests/unittests_shared/cli_commands.py b/unittests/unittests_shared/cli_commands.py index 70570bc7..8ca6ccfc 100644 --- a/unittests/unittests_shared/cli_commands.py +++ b/unittests/unittests_shared/cli_commands.py @@ -23,7 +23,7 @@ class CLICommands: @staticmethod def _run_with_output(cmd: str, *args) -> str: env_vars = os.environ - env_vars['CPL_IS_UNITTEST'] = 'NO' + # env_vars['CPL_IS_UNITTEST'] = 'NO' command = ['python', CLI_PATH, cmd] for arg in args: