2022.10.5 Improved version command & fixed unittests (#97) #107
@ -31,6 +31,16 @@ class VersionService(CommandABC):
|
|||||||
:param args:
|
:param args:
|
||||||
:return:
|
: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.set_foreground_color(ForegroundColorEnum.yellow)
|
||||||
Console.banner('CPL CLI')
|
Console.banner('CPL CLI')
|
||||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||||
@ -40,31 +50,8 @@ class VersionService(CommandABC):
|
|||||||
|
|
||||||
Console.write_line(f'Python: ')
|
Console.write_line(f'Python: ')
|
||||||
Console.write(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')
|
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(f'OS: {platform.system()} {platform.processor()}')
|
||||||
|
|
||||||
Console.write_line('\nCPL packages:')
|
Console.write_line('\nCPL packages:')
|
||||||
cpl_packages = [
|
Console.table(['Name', 'Version'], 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.write_line('\nPython 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)
|
Console.table(['Name', 'Version'], packages)
|
||||||
|
@ -10,7 +10,7 @@ from cpl_discord.helper.to_containers_converter import ToContainersConverter
|
|||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
|
|
||||||
|
|
||||||
class Guild(discord.Guild, Container):
|
class Guild(Container, discord.Guild):
|
||||||
|
|
||||||
def __init__(self, _t: discord.Guild):
|
def __init__(self, _t: discord.Guild):
|
||||||
self._object: discord.Guild = _t
|
self._object: discord.Guild = _t
|
||||||
|
@ -10,8 +10,13 @@ class IterableABC(list, QueryableABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __init__(self, t: type = None, values: Iterable = None):
|
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
|
self._type = t
|
||||||
list.__init__(self, [] if values is None else values)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<{type(self).__name__} {list(self).__repr__()}>'
|
return f'<{type(self).__name__} {list(self).__repr__()}>'
|
||||||
|
@ -42,15 +42,25 @@ class VersionTestCase(unittest.TestCase):
|
|||||||
if 7 <= index <= 9:
|
if 7 <= index <= 9:
|
||||||
self._block_version += f'{line}\n'
|
self._block_version += f'{line}\n'
|
||||||
|
|
||||||
if 10 <= index <= 15:
|
if 10 <= index <= 16:
|
||||||
self._block_cpl_packages += f'{line}\n'
|
self._block_cpl_packages += f'{line}\n'
|
||||||
|
|
||||||
if index >= 17:
|
if index >= 18:
|
||||||
self._block_packages += f'{line}\n'
|
self._block_packages += f'{line}\n'
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
def test_version(self):
|
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()
|
version = CLICommands.version()
|
||||||
self._get_version_output(version)
|
self._get_version_output(version)
|
||||||
reference_banner = colored(text2art(self._name), ForegroundColorEnum.yellow.value).split('\n')
|
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'
|
colored(f'OS: {colored(f"{platform.system()} {platform.processor()}")}') + '\n'
|
||||||
]
|
]
|
||||||
self.assertEqual('\n'.join(reference_version), self._block_version)
|
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 = [
|
reference_cpl_packages = [
|
||||||
colored(colored(f'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)
|
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 = [
|
reference_packages = [
|
||||||
colored(colored(f'Python packages:')),
|
colored(colored(f'Python packages:')),
|
||||||
colored(f'{tabulate(packages, headers=["Name", "Version"])}'),
|
colored(f'{tabulate(packages, headers=["Name", "Version"])}'),
|
||||||
|
@ -181,7 +181,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
|||||||
res = self._tests.max(lambda u: u.address.nr)
|
res = self._tests.max(lambda u: u.address.nr)
|
||||||
self.assertEqual(res, self._t_user.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())
|
self.assertEqual(99, tests.max())
|
||||||
|
|
||||||
def invalid():
|
def invalid():
|
||||||
@ -194,7 +194,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
|||||||
res = self._tests.min(lambda u: u.address.nr)
|
res = self._tests.min(lambda u: u.address.nr)
|
||||||
self.assertEqual(1, res)
|
self.assertEqual(1, res)
|
||||||
|
|
||||||
tests = List(values=list(range(0, 100)))
|
tests = List(int, list(range(0, 100)))
|
||||||
self.assertEqual(0, tests.min())
|
self.assertEqual(0, tests.min())
|
||||||
|
|
||||||
def invalid():
|
def invalid():
|
||||||
|
@ -5,8 +5,8 @@ import unittest
|
|||||||
from cpl_query.enumerable import Enumerable
|
from cpl_query.enumerable import Enumerable
|
||||||
from cpl_query.iterable import Iterable
|
from cpl_query.iterable import Iterable
|
||||||
|
|
||||||
VALUES = 1000
|
VALUES = 10000
|
||||||
COUNT = 75
|
COUNT = 50
|
||||||
|
|
||||||
|
|
||||||
class PerformanceTestCase(unittest.TestCase):
|
class PerformanceTestCase(unittest.TestCase):
|
||||||
|
@ -23,7 +23,7 @@ class CLICommands:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def _run_with_output(cmd: str, *args) -> str:
|
def _run_with_output(cmd: str, *args) -> str:
|
||||||
env_vars = os.environ
|
env_vars = os.environ
|
||||||
env_vars['CPL_IS_UNITTEST'] = 'NO'
|
# env_vars['CPL_IS_UNITTEST'] = 'NO'
|
||||||
|
|
||||||
command = ['python', CLI_PATH, cmd]
|
command = ['python', CLI_PATH, cmd]
|
||||||
for arg in args:
|
for arg in args:
|
||||||
|
Loading…
Reference in New Issue
Block a user