Updated docs
This commit is contained in:
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -9,7 +9,6 @@ from unittests_translation.translation_test_suite import TranslationTestSuite
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
|
@@ -7,5 +7,5 @@ def main():
|
||||
app_builder.build().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@@ -2,8 +2,8 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "unittests",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "12",
|
||||
"Major": "2023",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.0"
|
||||
"cpl-core>=2023.2.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -22,7 +22,7 @@ class CommandTestCase(unittest.TestCase):
|
||||
os.makedirs(PLAYGROUND_PATH)
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
except Exception as e:
|
||||
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
|
||||
print(f"Setup of {__name__} failed: {traceback.format_exc()}")
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
@@ -35,4 +35,4 @@ class CommandTestCase(unittest.TestCase):
|
||||
if os.path.exists(PLAYGROUND_PATH):
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
|
||||
except Exception as e:
|
||||
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')
|
||||
print(f"Cleanup of {__name__} failed: {traceback.format_exc()}")
|
||||
|
@@ -8,15 +8,14 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class AddTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'add-test-project'
|
||||
self._target = 'add-test-library'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._source = "add-test-project"
|
||||
self._target = "add-test-library"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -26,18 +25,18 @@ class AddTestCase(CommandTestCase):
|
||||
def setUp(self):
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
CLICommands.new('library', self._target, '--ab', '--s')
|
||||
CLICommands.new("library", self._target, "--ab", "--s")
|
||||
|
||||
def test_add(self):
|
||||
CLICommands.add(self._source, self._target)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('ProjectReferences', settings['BuildSettings'])
|
||||
self.assertIn('BuildSettings', settings)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("ProjectReferences", settings["BuildSettings"])
|
||||
self.assertIn("BuildSettings", settings)
|
||||
self.assertIn(
|
||||
f'../{String.convert_to_snake_case(self._target)}/{self._target}.json',
|
||||
settings['BuildSettings']['ProjectReferences']
|
||||
f"../{String.convert_to_snake_case(self._target)}/{self._target}.json",
|
||||
settings["BuildSettings"]["ProjectReferences"],
|
||||
)
|
||||
|
@@ -10,14 +10,13 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class BuildTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'build-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._source = "build-test-source"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -25,17 +24,17 @@ class BuildTestCase(CommandTestCase):
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "w", encoding="utf-8") as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
if not os.path.exists(PLAYGROUND_PATH):
|
||||
os.makedirs(PLAYGROUND_PATH)
|
||||
|
||||
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def _are_dir_trees_equal(self, dir1, dir2):
|
||||
@@ -51,7 +50,7 @@ class BuildTestCase(CommandTestCase):
|
||||
@return: True if the directory trees are the same and
|
||||
there were no errors while accessing the directories or files,
|
||||
False otherwise.
|
||||
"""
|
||||
"""
|
||||
|
||||
dirs_cmp = filecmp.dircmp(dir1, dir2)
|
||||
if len(dirs_cmp.left_only) > 0 or len(dirs_cmp.right_only) > 0 or len(dirs_cmp.funny_files) > 0:
|
||||
@@ -72,12 +71,16 @@ class BuildTestCase(CommandTestCase):
|
||||
|
||||
def test_build(self):
|
||||
CLICommands.build()
|
||||
dist_path = './dist'
|
||||
full_dist_path = f'{dist_path}/{self._source}/build/{String.convert_to_snake_case(self._source)}'
|
||||
dist_path = "./dist"
|
||||
full_dist_path = f"{dist_path}/{self._source}/build/{String.convert_to_snake_case(self._source)}"
|
||||
self.assertTrue(os.path.exists(dist_path))
|
||||
self.assertTrue(os.path.exists(full_dist_path))
|
||||
self.assertFalse(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
with open(f'{full_dist_path}/{self._source}.json', 'w') as file:
|
||||
self.assertFalse(
|
||||
self._are_dir_trees_equal(f"./src/{String.convert_to_snake_case(self._source)}", full_dist_path)
|
||||
)
|
||||
with open(f"{full_dist_path}/{self._source}.json", "w") as file:
|
||||
file.write(json.dumps(self._get_project_settings(), indent=2))
|
||||
file.close()
|
||||
self.assertTrue(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
self.assertTrue(
|
||||
self._are_dir_trees_equal(f"./src/{String.convert_to_snake_case(self._source)}", full_dist_path)
|
||||
)
|
||||
|
@@ -21,7 +21,6 @@ from unittests_cli.version_test_case import VersionTestCase
|
||||
|
||||
|
||||
class CLITestSuite(unittest.TestSuite):
|
||||
|
||||
def __init__(self):
|
||||
unittest.TestSuite.__init__(self)
|
||||
|
||||
@@ -41,7 +40,7 @@ class CLITestSuite(unittest.TestSuite):
|
||||
StartTestCase,
|
||||
# workspace needed
|
||||
AddTestCase,
|
||||
RemoveTestCase
|
||||
RemoveTestCase,
|
||||
]
|
||||
|
||||
if self._is_online:
|
||||
@@ -60,7 +59,7 @@ class CLITestSuite(unittest.TestSuite):
|
||||
os.makedirs(PLAYGROUND_PATH)
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
except Exception as e:
|
||||
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
|
||||
print(f"Setup of {__name__} failed: {traceback.format_exc()}")
|
||||
|
||||
def _cleanup(self):
|
||||
try:
|
||||
@@ -70,7 +69,7 @@ class CLITestSuite(unittest.TestSuite):
|
||||
if os.path.exists(PLAYGROUND_PATH):
|
||||
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
|
||||
except Exception as e:
|
||||
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')
|
||||
print(f"Cleanup of {__name__} failed: {traceback.format_exc()}")
|
||||
|
||||
def run(self, *args):
|
||||
self._setup()
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import os
|
||||
|
||||
base = ''
|
||||
if not os.getcwd().endswith('unittests'):
|
||||
base = '../'
|
||||
base = ""
|
||||
if not os.getcwd().endswith("unittests"):
|
||||
base = "../"
|
||||
|
||||
PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}test_cli_playground'))
|
||||
TRANSLATION_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}unittests_translation'))
|
||||
CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}../src/cpl_cli/main.py'))
|
||||
PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), f"{base}test_cli_playground"))
|
||||
TRANSLATION_PATH = os.path.abspath(os.path.join(os.getcwd(), f"{base}unittests_translation"))
|
||||
CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), f"{base}../src/cpl_cli/main.py"))
|
||||
|
@@ -2,7 +2,6 @@ from unittests_cli.abc.command_test_case import CommandTestCase
|
||||
|
||||
|
||||
class CustomTestCase(CommandTestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
|
@@ -7,13 +7,13 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class GenerateTestCase(CommandTestCase):
|
||||
_project = 'test-console'
|
||||
_t_path = 'test'
|
||||
_project = "test-console"
|
||||
_t_path = "test"
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
CommandTestCase.setUpClass()
|
||||
CLICommands.new('console', cls._project, '--ab', '--s', '--venv')
|
||||
CLICommands.new("console", cls._project, "--ab", "--s", "--venv")
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
@@ -23,8 +23,8 @@ class GenerateTestCase(CommandTestCase):
|
||||
expected_path = f'generated_file{"_on_ready" if schematic == "event" else ""}{suffix}.py'
|
||||
|
||||
if path is not None:
|
||||
file = f'{path}/{file}'
|
||||
expected_path = f'{path}/{expected_path}'
|
||||
file = f"{path}/{file}"
|
||||
expected_path = f"{path}/{expected_path}"
|
||||
|
||||
CLICommands.generate(schematic, file)
|
||||
file_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, expected_path))
|
||||
@@ -47,54 +47,54 @@ class GenerateTestCase(CommandTestCase):
|
||||
self.assertTrue(os.path.exists(file_path))
|
||||
|
||||
def test_abc(self):
|
||||
self._test_file('abc', '_abc')
|
||||
self._test_file('abc', '_abc', path=self._t_path)
|
||||
self._test_file('abc', '_abc', path=f'{self._t_path}/{self._t_path}')
|
||||
self._test_file_with_project('abc', '_abc', path=self._project)
|
||||
os.chdir(f'src/{String.convert_to_snake_case(self._project)}')
|
||||
self._test_file_with_project('abc', '_abc', path='test', enter=False)
|
||||
self._test_file("abc", "_abc")
|
||||
self._test_file("abc", "_abc", path=self._t_path)
|
||||
self._test_file("abc", "_abc", path=f"{self._t_path}/{self._t_path}")
|
||||
self._test_file_with_project("abc", "_abc", path=self._project)
|
||||
os.chdir(f"src/{String.convert_to_snake_case(self._project)}")
|
||||
self._test_file_with_project("abc", "_abc", path="test", enter=False)
|
||||
|
||||
def test_class(self):
|
||||
self._test_file('class', '')
|
||||
self._test_file('class', '', path=self._t_path)
|
||||
self._test_file_with_project('class', '', path=self._project)
|
||||
self._test_file("class", "")
|
||||
self._test_file("class", "", path=self._t_path)
|
||||
self._test_file_with_project("class", "", path=self._project)
|
||||
|
||||
def test_enum(self):
|
||||
self._test_file('enum', '_enum')
|
||||
self._test_file('enum', '_enum', path=self._t_path)
|
||||
self._test_file_with_project('enum', '_enum', path=self._project)
|
||||
os.chdir(f'src/{String.convert_to_snake_case(self._project)}')
|
||||
self._test_file_with_project('enum', '_enum', path='test', enter=False)
|
||||
self._test_file("enum", "_enum")
|
||||
self._test_file("enum", "_enum", path=self._t_path)
|
||||
self._test_file_with_project("enum", "_enum", path=self._project)
|
||||
os.chdir(f"src/{String.convert_to_snake_case(self._project)}")
|
||||
self._test_file_with_project("enum", "_enum", path="test", enter=False)
|
||||
|
||||
def test_pipe(self):
|
||||
self._test_file('pipe', '_pipe')
|
||||
self._test_file('pipe', '_pipe', path=self._t_path)
|
||||
self._test_file_with_project('pipe', '_pipe', path=self._project)
|
||||
self._test_file("pipe", "_pipe")
|
||||
self._test_file("pipe", "_pipe", path=self._t_path)
|
||||
self._test_file_with_project("pipe", "_pipe", path=self._project)
|
||||
|
||||
def test_service(self):
|
||||
self._test_file('service', '_service')
|
||||
self._test_file_with_project('service', '_service', path=self._project)
|
||||
self._test_file("service", "_service")
|
||||
self._test_file_with_project("service", "_service", path=self._project)
|
||||
|
||||
def test_settings(self):
|
||||
self._test_file('settings', '_settings')
|
||||
self._test_file_with_project('settings', '_settings', path=self._project)
|
||||
self._test_file("settings", "_settings")
|
||||
self._test_file_with_project("settings", "_settings", path=self._project)
|
||||
|
||||
def test_test_case(self):
|
||||
self._test_file('test-case', '_test_case')
|
||||
self._test_file_with_project('test-case', '_test_case', path=self._project)
|
||||
self._test_file("test-case", "_test_case")
|
||||
self._test_file_with_project("test-case", "_test_case", path=self._project)
|
||||
|
||||
def test_thread(self):
|
||||
self._test_file('thread', '_thread')
|
||||
self._test_file_with_project('thread', '_thread', path=self._project)
|
||||
self._test_file("thread", "_thread")
|
||||
self._test_file_with_project("thread", "_thread", path=self._project)
|
||||
|
||||
def test_validator(self):
|
||||
self._test_file('validator', '_validator')
|
||||
self._test_file_with_project('validator', '_validator', path=self._project)
|
||||
self._test_file("validator", "_validator")
|
||||
self._test_file_with_project("validator", "_validator", path=self._project)
|
||||
|
||||
def test_discord_command(self):
|
||||
self._test_file('command', '_command')
|
||||
self._test_file_with_project('command', '_command', path=self._project)
|
||||
self._test_file("command", "_command")
|
||||
self._test_file_with_project("command", "_command", path=self._project)
|
||||
|
||||
def test_discord_event(self):
|
||||
self._test_file('event', '_event')
|
||||
self._test_file_with_project('event', '_event', path=self._project)
|
||||
self._test_file("event", "_event")
|
||||
self._test_file_with_project("event", "_event", path=self._project)
|
||||
|
@@ -12,14 +12,13 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class InstallTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'install-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._source = "install-test-source"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -27,7 +26,7 @@ class InstallTestCase(CommandTestCase):
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "w", encoding="utf-8") as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
@@ -37,94 +36,73 @@ class InstallTestCase(CommandTestCase):
|
||||
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s', '--venv')
|
||||
CLICommands.new("console", self._source, "--ab", "--s", "--venv")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def _get_installed_packages(self) -> dict:
|
||||
reqs = subprocess.check_output([os.path.join(os.getcwd(), 'venv/bin/python'), '-m', 'pip', 'freeze'])
|
||||
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||
reqs = subprocess.check_output([os.path.join(os.getcwd(), "venv/bin/python"), "-m", "pip", "freeze"])
|
||||
return dict([tuple(r.decode().split("==")) for r in reqs.split()])
|
||||
|
||||
def test_install_package(self):
|
||||
version = '1.7.3'
|
||||
package_name = 'discord.py'
|
||||
package = f'{package_name}=={version}'
|
||||
version = "1.7.3"
|
||||
package_name = "discord.py"
|
||||
package = f"{package_name}=={version}"
|
||||
CLICommands.install(package)
|
||||
settings = self._get_project_settings()
|
||||
|
||||
with self.subTest(msg='Project deps'):
|
||||
with self.subTest(msg="Project deps"):
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertIn(package, settings["ProjectSettings"]["Dependencies"])
|
||||
|
||||
with self.subTest(msg='PIP'):
|
||||
with self.subTest(msg="PIP"):
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(package_name, packages)
|
||||
self.assertEqual(version, packages[package_name])
|
||||
|
||||
def test_dev_install_package(self):
|
||||
version = '1.7.3'
|
||||
package_name = 'discord.py'
|
||||
package = f'{package_name}=={version}'
|
||||
version = "1.7.3"
|
||||
package_name = "discord.py"
|
||||
package = f"{package_name}=={version}"
|
||||
CLICommands.install(package, is_dev=True)
|
||||
settings = self._get_project_settings()
|
||||
|
||||
with self.subTest(msg='Project deps'):
|
||||
with self.subTest(msg="Project deps"):
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn(
|
||||
package,
|
||||
settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertIn("DevDependencies", settings["ProjectSettings"])
|
||||
self.assertNotIn(package, settings["ProjectSettings"]["Dependencies"])
|
||||
self.assertIn(package, settings["ProjectSettings"]["DevDependencies"])
|
||||
|
||||
with self.subTest(msg='PIP'):
|
||||
with self.subTest(msg="PIP"):
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(package_name, packages)
|
||||
self.assertEqual(version, packages[package_name])
|
||||
|
||||
def _test_install_all(self):
|
||||
version = '1.7.3'
|
||||
package_name = 'discord.py'
|
||||
package = f'{package_name}=={version}'
|
||||
version = "1.7.3"
|
||||
package_name = "discord.py"
|
||||
package = f"{package_name}=={version}"
|
||||
settings = self._get_project_settings()
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
settings['ProjectSettings']['Dependencies'].append(package)
|
||||
settings['ProjectSettings']['DevDependencies'].append(package)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertIn("DevDependencies", settings["ProjectSettings"])
|
||||
self.assertNotIn(package, settings["ProjectSettings"]["Dependencies"])
|
||||
self.assertIn("DevDependencies", settings["ProjectSettings"])
|
||||
self.assertNotIn(package, settings["ProjectSettings"]["Dependencies"])
|
||||
settings["ProjectSettings"]["Dependencies"].append(package)
|
||||
settings["ProjectSettings"]["DevDependencies"].append(package)
|
||||
self._save_project_settings(settings)
|
||||
CLICommands.install()
|
||||
new_settings = self._get_project_settings()
|
||||
self.assertEqual(settings, new_settings)
|
||||
self.assertIn('ProjectSettings', new_settings)
|
||||
self.assertIn('Dependencies', new_settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', new_settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
package,
|
||||
new_settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn(
|
||||
package,
|
||||
new_settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", new_settings)
|
||||
self.assertIn("Dependencies", new_settings["ProjectSettings"])
|
||||
self.assertIn("DevDependencies", new_settings["ProjectSettings"])
|
||||
self.assertIn(package, new_settings["ProjectSettings"]["Dependencies"])
|
||||
self.assertIn(package, new_settings["ProjectSettings"]["DevDependencies"])
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(package_name, packages)
|
||||
self.assertEqual(version, packages[package_name])
|
||||
|
@@ -9,7 +9,6 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class NewTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
|
||||
@@ -18,61 +17,63 @@ class NewTestCase(CommandTestCase):
|
||||
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name))
|
||||
self.assertTrue(os.path.exists(workspace_path))
|
||||
if test_venv:
|
||||
with self.subTest(msg='Venv exists'):
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
self.assertTrue(os.path.islink(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
with self.subTest(msg="Venv exists"):
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, "venv")))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, "venv/bin")))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, "venv/bin/python")))
|
||||
self.assertTrue(os.path.islink(os.path.join(workspace_path, "venv/bin/python")))
|
||||
|
||||
base = 'src'
|
||||
if '--base' in args and '/' in name:
|
||||
base = name.split('/')[0]
|
||||
name = name.replace(f'{name.split("/")[0]}/', '')
|
||||
base = "src"
|
||||
if "--base" in args and "/" in name:
|
||||
base = name.split("/")[0]
|
||||
name = name.replace(f'{name.split("/")[0]}/', "")
|
||||
|
||||
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name, base, String.convert_to_snake_case(name)))
|
||||
if without_ws:
|
||||
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, base, name, 'src/', String.convert_to_snake_case(name)))
|
||||
project_path = os.path.abspath(
|
||||
os.path.join(PLAYGROUND_PATH, base, name, "src/", String.convert_to_snake_case(name))
|
||||
)
|
||||
|
||||
with self.subTest(msg='Project json exists'):
|
||||
with self.subTest(msg="Project json exists"):
|
||||
self.assertTrue(os.path.exists(project_path))
|
||||
self.assertTrue(os.path.exists(os.path.join(project_path, f'{name}.json')))
|
||||
self.assertTrue(os.path.exists(os.path.join(project_path, f"{name}.json")))
|
||||
|
||||
if project_type == 'library':
|
||||
with self.subTest(msg='Library class1 exists'):
|
||||
self.assertTrue(os.path.exists(os.path.join(project_path, f'class1.py')))
|
||||
if project_type == "library":
|
||||
with self.subTest(msg="Library class1 exists"):
|
||||
self.assertTrue(os.path.exists(os.path.join(project_path, f"class1.py")))
|
||||
return
|
||||
|
||||
with self.subTest(msg='Project main.py exists'):
|
||||
self.assertTrue(os.path.exists(os.path.join(project_path, f'main.py')))
|
||||
with self.subTest(msg="Project main.py exists"):
|
||||
self.assertTrue(os.path.exists(os.path.join(project_path, f"main.py")))
|
||||
|
||||
with self.subTest(msg='Application base'):
|
||||
if '--ab' in args:
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'application.py')))
|
||||
with self.subTest(msg="Application base"):
|
||||
if "--ab" in args:
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"application.py")))
|
||||
else:
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'application.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"application.py")))
|
||||
|
||||
# s depends on ab
|
||||
with self.subTest(msg='Startup'):
|
||||
if '--ab' in args and '--s' in args:
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'startup.py')))
|
||||
with self.subTest(msg="Startup"):
|
||||
if "--ab" in args and "--s" in args:
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"startup.py")))
|
||||
else:
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'startup.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"startup.py")))
|
||||
|
||||
with self.subTest(msg='Unittest'):
|
||||
if project_type == 'unittest':
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'test_case.py')))
|
||||
with self.subTest(msg="Unittest"):
|
||||
if project_type == "unittest":
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"test_case.py")))
|
||||
else:
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'test_case.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"test_case.py")))
|
||||
|
||||
with self.subTest(msg='Discord'):
|
||||
if project_type == 'discord-bot':
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'events/__init__.py')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'events/on_ready_event.py')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'commands/__init__.py')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'commands/ping_command.py')))
|
||||
with self.subTest(msg="Discord"):
|
||||
if project_type == "discord-bot":
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"events/__init__.py")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"events/on_ready_event.py")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"commands/__init__.py")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"commands/ping_command.py")))
|
||||
else:
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'events/on_ready_event.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'commands/ping_command.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"events/on_ready_event.py")))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"commands/ping_command.py")))
|
||||
|
||||
def _test_sub_project(self, project_type: str, name: str, workspace_name: str, *args, test_venv=False):
|
||||
os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name)))
|
||||
@@ -80,91 +81,111 @@ class NewTestCase(CommandTestCase):
|
||||
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name))
|
||||
self.assertTrue(os.path.exists(workspace_path))
|
||||
if test_venv:
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
self.assertTrue(os.path.islink(os.path.join(workspace_path, 'venv/bin/python')))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, "venv")))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, "venv/bin")))
|
||||
self.assertTrue(os.path.exists(os.path.join(workspace_path, "venv/bin/python")))
|
||||
self.assertTrue(os.path.islink(os.path.join(workspace_path, "venv/bin/python")))
|
||||
|
||||
base = 'src'
|
||||
if '--base' in args and '/' in name:
|
||||
base = name.split('/')[0]
|
||||
name = name.replace(f'{name.split("/")[0]}/', '')
|
||||
base = "src"
|
||||
if "--base" in args and "/" in name:
|
||||
base = name.split("/")[0]
|
||||
name = name.replace(f'{name.split("/")[0]}/', "")
|
||||
|
||||
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, base, String.convert_to_snake_case(name)))
|
||||
project_path = os.path.abspath(
|
||||
os.path.join(PLAYGROUND_PATH, workspace_name, base, String.convert_to_snake_case(name))
|
||||
)
|
||||
self.assertTrue(os.path.exists(project_path))
|
||||
self.assertTrue(os.path.join(project_path, f'{name}.json'))
|
||||
self.assertTrue(os.path.join(project_path, f"{name}.json"))
|
||||
|
||||
if project_type == 'discord-bot':
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'events/__init__.py')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'events/on_ready_event.py')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'commands/__init__.py')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f'commands/ping_command.py')))
|
||||
if project_type == "discord-bot":
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"events/__init__.py")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"events/on_ready_event.py")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"commands/__init__.py")))
|
||||
self.assertTrue(os.path.isfile(os.path.join(project_path, f"commands/ping_command.py")))
|
||||
else:
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'events/on_ready_event.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f'commands/ping_command.py')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"events/on_ready_event.py")))
|
||||
self.assertFalse(os.path.isfile(os.path.join(project_path, f"commands/ping_command.py")))
|
||||
|
||||
def _test_sub_directory_project(self, project_type: str, directory: str, name: str, workspace_name: str, *args):
|
||||
os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name)))
|
||||
CLICommands.new(project_type, f'{directory}/{name}', *args)
|
||||
CLICommands.new(project_type, f"{directory}/{name}", *args)
|
||||
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name))
|
||||
self.assertTrue(os.path.exists(workspace_path))
|
||||
|
||||
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, f'src/{directory}', String.convert_to_snake_case(name)))
|
||||
project_path = os.path.abspath(
|
||||
os.path.join(PLAYGROUND_PATH, workspace_name, f"src/{directory}", String.convert_to_snake_case(name))
|
||||
)
|
||||
self.assertTrue(os.path.exists(project_path))
|
||||
project_file = os.path.join(project_path, f'{name}.json')
|
||||
project_file = os.path.join(project_path, f"{name}.json")
|
||||
self.assertTrue(os.path.exists(project_file))
|
||||
with open(project_file, 'r', encoding='utf-8') as cfg:
|
||||
with open(project_file, "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
project_settings = project_json['ProjectSettings']
|
||||
build_settings = project_json['BuildSettings']
|
||||
project_settings = project_json["ProjectSettings"]
|
||||
build_settings = project_json["BuildSettings"]
|
||||
|
||||
self.assertEqual(project_settings['Name'], name)
|
||||
self.assertEqual(build_settings['ProjectType'], 'library')
|
||||
self.assertEqual(build_settings['OutputPath'], '../../dist')
|
||||
self.assertEqual(build_settings['Main'], f'{String.convert_to_snake_case(name)}.main')
|
||||
self.assertEqual(build_settings['EntryPoint'], name)
|
||||
self.assertEqual(project_settings["Name"], name)
|
||||
self.assertEqual(build_settings["ProjectType"], "library")
|
||||
self.assertEqual(build_settings["OutputPath"], "../../dist")
|
||||
self.assertEqual(build_settings["Main"], f"{String.convert_to_snake_case(name)}.main")
|
||||
self.assertEqual(build_settings["EntryPoint"], name)
|
||||
|
||||
def test_console(self):
|
||||
self._test_project('console', 'test-console', '--ab', '--s', '--venv', test_venv=True)
|
||||
self._test_project("console", "test-console", "--ab", "--s", "--venv", test_venv=True)
|
||||
|
||||
def test_console_with_other_base(self):
|
||||
self._test_project('console', 'tools/test-console', '--ab', '--s', '--venv', '--base', test_venv=True, without_ws=True)
|
||||
self._test_project(
|
||||
"console", "tools/test-console", "--ab", "--s", "--venv", "--base", test_venv=True, without_ws=True
|
||||
)
|
||||
|
||||
def test_console_without_s(self):
|
||||
self._test_project('console', 'test-console-without-s', '--ab')
|
||||
self._test_project("console", "test-console-without-s", "--ab")
|
||||
|
||||
def test_console_without_ab(self):
|
||||
self._test_project('console', 'test-console-without-ab', '--sp')
|
||||
self._test_project("console", "test-console-without-ab", "--sp")
|
||||
|
||||
def test_console_without_anything(self):
|
||||
self._test_project('console', 'test-console-without-anything', '--n')
|
||||
self._test_project("console", "test-console-without-anything", "--n")
|
||||
|
||||
def test_console_sub(self):
|
||||
self._test_sub_project('console', 'test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', test_venv=True)
|
||||
self._test_sub_project(
|
||||
"console", "test-sub-console", "test-console", "--ab", "--s", "--sp", "--venv", test_venv=True
|
||||
)
|
||||
|
||||
def test_console_sub_with_other_base(self):
|
||||
self._test_sub_project('console', 'tools/test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', '--base', test_venv=True)
|
||||
self._test_sub_project(
|
||||
"console",
|
||||
"tools/test-sub-console",
|
||||
"test-console",
|
||||
"--ab",
|
||||
"--s",
|
||||
"--sp",
|
||||
"--venv",
|
||||
"--base",
|
||||
test_venv=True,
|
||||
)
|
||||
|
||||
def test_discord_bot(self):
|
||||
self._test_project('discord-bot', 'test-bot', '--ab', '--s', '--venv', test_venv=True)
|
||||
self._test_project("discord-bot", "test-bot", "--ab", "--s", "--venv", test_venv=True)
|
||||
|
||||
def test_discord_bot_sub(self):
|
||||
self._test_sub_project('discord-bot', 'test-bot-sub', 'test-console', '--ab', '--s', '--venv', test_venv=True)
|
||||
self._test_sub_project("discord-bot", "test-bot-sub", "test-console", "--ab", "--s", "--venv", test_venv=True)
|
||||
|
||||
def test_library(self):
|
||||
self._test_project('library', 'test-library', '--ab', '--s', '--sp')
|
||||
self._test_project("library", "test-library", "--ab", "--s", "--sp")
|
||||
|
||||
def test_library_sub(self):
|
||||
self._test_sub_project('library', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
|
||||
self._test_sub_project("library", "test-sub-library", "test-console", "--ab", "--s", "--sp")
|
||||
|
||||
def test_library_sub_directory(self):
|
||||
self._test_sub_directory_project('library', 'directory', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
|
||||
self._test_sub_directory_project(
|
||||
"library", "directory", "test-sub-library", "test-console", "--ab", "--s", "--sp"
|
||||
)
|
||||
|
||||
def test_unittest(self):
|
||||
self._test_project('unittest', 'test-unittest', '--ab')
|
||||
self._test_project("unittest", "test-unittest", "--ab")
|
||||
|
||||
def test_unittest_sub(self):
|
||||
self._test_sub_project('unittest', 'test-unittest', 'test-console', '--ab', '--s', '--sp')
|
||||
self._test_sub_project("unittest", "test-unittest", "test-console", "--ab", "--s", "--sp")
|
||||
|
@@ -10,11 +10,10 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class PublishTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'publish-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._source = "publish-test-source"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
|
||||
def setUp(self):
|
||||
if not os.path.exists(PLAYGROUND_PATH):
|
||||
@@ -22,7 +21,7 @@ class PublishTestCase(CommandTestCase):
|
||||
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def _are_dir_trees_equal(self, dir1, dir2):
|
||||
@@ -38,7 +37,7 @@ class PublishTestCase(CommandTestCase):
|
||||
@return: True if the directory trees are the same and
|
||||
there were no errors while accessing the directories or files,
|
||||
False otherwise.
|
||||
"""
|
||||
"""
|
||||
|
||||
dirs_cmp = filecmp.dircmp(dir1, dir2)
|
||||
if len(dirs_cmp.left_only) > 0 or len(dirs_cmp.right_only) > 0 or len(dirs_cmp.funny_files) > 0:
|
||||
@@ -59,17 +58,28 @@ class PublishTestCase(CommandTestCase):
|
||||
|
||||
def test_publish(self):
|
||||
CLICommands.publish()
|
||||
dist_path = './dist'
|
||||
setup_path = f'{dist_path}/{self._source}/publish/setup'
|
||||
full_dist_path = f'{dist_path}/{self._source}/publish/build/lib/{String.convert_to_snake_case(self._source)}'
|
||||
dist_path = "./dist"
|
||||
setup_path = f"{dist_path}/{self._source}/publish/setup"
|
||||
full_dist_path = f"{dist_path}/{self._source}/publish/build/lib/{String.convert_to_snake_case(self._source)}"
|
||||
self.assertTrue(os.path.exists(dist_path))
|
||||
self.assertTrue(os.path.exists(setup_path))
|
||||
self.assertTrue(os.path.exists(os.path.join(setup_path, f'{self._source}-0.0.0.tar.gz')))
|
||||
self.assertTrue(os.path.exists(os.path.join(setup_path, f'{String.convert_to_snake_case(self._source)}-0.0.0-py3-none-any.whl')))
|
||||
self.assertTrue(os.path.exists(os.path.join(setup_path, f"{self._source}-0.0.0.tar.gz")))
|
||||
self.assertTrue(
|
||||
os.path.exists(
|
||||
os.path.join(setup_path, f"{String.convert_to_snake_case(self._source)}-0.0.0-py3-none-any.whl")
|
||||
)
|
||||
)
|
||||
self.assertTrue(os.path.exists(full_dist_path))
|
||||
self.assertFalse(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
self.assertFalse(
|
||||
self._are_dir_trees_equal(f"./src/{String.convert_to_snake_case(self._source)}", full_dist_path)
|
||||
)
|
||||
|
||||
shutil.copyfile(os.path.join(os.getcwd(), self._project_file), f'{full_dist_path}/{self._source}.json')
|
||||
shutil.copyfile(os.path.join(os.getcwd(), os.path.dirname(self._project_file), 'appsettings.json'), f'{full_dist_path}/appsettings.json')
|
||||
shutil.copyfile(os.path.join(os.getcwd(), self._project_file), f"{full_dist_path}/{self._source}.json")
|
||||
shutil.copyfile(
|
||||
os.path.join(os.getcwd(), os.path.dirname(self._project_file), "appsettings.json"),
|
||||
f"{full_dist_path}/appsettings.json",
|
||||
)
|
||||
|
||||
self.assertTrue(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))
|
||||
self.assertTrue(
|
||||
self._are_dir_trees_equal(f"./src/{String.convert_to_snake_case(self._source)}", full_dist_path)
|
||||
)
|
||||
|
@@ -9,15 +9,14 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class RemoveTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'add-test-project'
|
||||
self._target = 'add-test-library'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._source = "add-test-project"
|
||||
self._target = "add-test-library"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -27,25 +26,25 @@ class RemoveTestCase(CommandTestCase):
|
||||
def setUp(self):
|
||||
if not os.path.exists(PLAYGROUND_PATH):
|
||||
os.makedirs(PLAYGROUND_PATH)
|
||||
|
||||
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
CLICommands.new('console', self._target, '--ab', '--s')
|
||||
CLICommands.new("console", self._target, "--ab", "--s")
|
||||
CLICommands.add(self._source, self._target)
|
||||
|
||||
def test_remove(self):
|
||||
CLICommands.remove(self._target)
|
||||
path = os.path.abspath(os.path.join(os.getcwd(), f'../{String.convert_to_snake_case(self._target)}'))
|
||||
path = os.path.abspath(os.path.join(os.getcwd(), f"../{String.convert_to_snake_case(self._target)}"))
|
||||
self.assertTrue(os.path.exists(os.getcwd()))
|
||||
self.assertTrue(os.path.exists(os.path.join(os.getcwd(), self._project_file)))
|
||||
self.assertFalse(os.path.exists(path))
|
||||
settings = self._get_project_settings()
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('ProjectReferences', settings['BuildSettings'])
|
||||
self.assertIn('BuildSettings', settings)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("ProjectReferences", settings["BuildSettings"])
|
||||
self.assertIn("BuildSettings", settings)
|
||||
self.assertNotIn(
|
||||
f'../{String.convert_to_snake_case(self._target)}/{self._target}.json',
|
||||
settings['BuildSettings']['ProjectReferences']
|
||||
f"../{String.convert_to_snake_case(self._target)}/{self._target}.json",
|
||||
settings["BuildSettings"]["ProjectReferences"],
|
||||
)
|
||||
|
@@ -10,12 +10,11 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class RunTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'run-test'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
|
||||
self._source = "run-test"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
self._application = f"src/{String.convert_to_snake_case(self._source)}/application.py"
|
||||
self._test_code = f"""
|
||||
import json
|
||||
import os
|
||||
@@ -34,11 +33,11 @@ class RunTestCase(CommandTestCase):
|
||||
"""
|
||||
|
||||
def _get_appsettings(self, is_dev=False):
|
||||
appsettings = f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
appsettings = f"dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json"
|
||||
if is_dev:
|
||||
appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
appsettings = f"src/{String.convert_to_snake_case(self._source)}/appsettings.json"
|
||||
|
||||
with open(os.path.join(os.getcwd(), appsettings), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), appsettings), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -46,85 +45,73 @@ class RunTestCase(CommandTestCase):
|
||||
return project_json
|
||||
|
||||
def _save_appsettings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'), 'w', encoding='utf-8') as project_file:
|
||||
with open(
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}/appsettings.json"),
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
settings = {'RunTest': {'WasStarted': 'False'}}
|
||||
settings = {"RunTest": {"WasStarted": "False"}}
|
||||
self._save_appsettings(settings)
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'\t\t{self._test_code}')
|
||||
with open(os.path.join(os.getcwd(), self._application), "a", encoding="utf-8") as file:
|
||||
file.write(f"\t\t{self._test_code}")
|
||||
file.close()
|
||||
|
||||
def test_run(self):
|
||||
CLICommands.run()
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertNotEqual(
|
||||
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}"), settings["RunTest"]["Path"]
|
||||
)
|
||||
self.assertEqual(
|
||||
os.path.join(os.getcwd(), f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
os.path.join(os.getcwd(), f"dist/{self._source}/build/{String.convert_to_snake_case(self._source)}"),
|
||||
settings["RunTest"]["Path"],
|
||||
)
|
||||
|
||||
def test_run_by_project(self):
|
||||
CLICommands.run(self._source)
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertNotEqual(
|
||||
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}"), settings["RunTest"]["Path"]
|
||||
)
|
||||
self.assertEqual(
|
||||
os.path.join(os.getcwd(), f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
os.path.join(os.getcwd(), f"dist/{self._source}/build/{String.convert_to_snake_case(self._source)}"),
|
||||
settings["RunTest"]["Path"],
|
||||
)
|
||||
|
||||
def test_run_dev(self):
|
||||
CLICommands.run(is_dev=True)
|
||||
settings = self._get_appsettings(is_dev=True)
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertEqual(
|
||||
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}"), settings["RunTest"]["Path"]
|
||||
)
|
||||
|
||||
def test_run_dev_by_project(self):
|
||||
CLICommands.run(self._source, is_dev=True)
|
||||
settings = self._get_appsettings(is_dev=True)
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertEqual(
|
||||
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}"), settings["RunTest"]["Path"]
|
||||
)
|
||||
|
@@ -12,13 +12,12 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class StartTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'start-test'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
self._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
|
||||
self._source = "start-test"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
self._appsettings = f"src/{String.convert_to_snake_case(self._source)}/appsettings.json"
|
||||
self._application = f"src/{String.convert_to_snake_case(self._source)}/application.py"
|
||||
self._test_code = f"""
|
||||
import json
|
||||
import os
|
||||
@@ -40,11 +39,11 @@ class StartTestCase(CommandTestCase):
|
||||
"""
|
||||
|
||||
def _get_appsettings(self, is_dev=False):
|
||||
appsettings = f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
appsettings = f"dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json"
|
||||
if is_dev:
|
||||
appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
appsettings = f"src/{String.convert_to_snake_case(self._source)}/appsettings.json"
|
||||
|
||||
with open(os.path.join(os.getcwd(), appsettings), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), appsettings), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -52,7 +51,11 @@ class StartTestCase(CommandTestCase):
|
||||
return project_json
|
||||
|
||||
def _save_appsettings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'), 'w', encoding='utf-8') as project_file:
|
||||
with open(
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}/appsettings.json"),
|
||||
"w",
|
||||
encoding="utf-8",
|
||||
) as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
@@ -62,12 +65,12 @@ class StartTestCase(CommandTestCase):
|
||||
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
settings = {'RunTest': {'WasStarted': 'False', 'WasRestarted': 'False'}}
|
||||
settings = {"RunTest": {"WasStarted": "False", "WasRestarted": "False"}}
|
||||
self._save_appsettings(settings)
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'\t\t{self._test_code}')
|
||||
with open(os.path.join(os.getcwd(), self._application), "a", encoding="utf-8") as file:
|
||||
file.write(f"\t\t{self._test_code}")
|
||||
file.close()
|
||||
|
||||
def test_start(self):
|
||||
@@ -76,32 +79,23 @@ class StartTestCase(CommandTestCase):
|
||||
time.sleep(5)
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'# trigger restart (comment generated by unittest)')
|
||||
with open(os.path.join(os.getcwd(), self._application), "a", encoding="utf-8") as file:
|
||||
file.write(f"# trigger restart (comment generated by unittest)")
|
||||
file.close()
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertIn('WasRestarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasRestarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertIn("WasRestarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasRestarted"])
|
||||
|
||||
def test_start_dev(self):
|
||||
thread = StartTestThread(is_dev=True)
|
||||
@@ -109,29 +103,20 @@ class StartTestCase(CommandTestCase):
|
||||
time.sleep(1)
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'# trigger restart (comment generated by unittest)')
|
||||
with open(os.path.join(os.getcwd(), self._application), "a", encoding="utf-8") as file:
|
||||
file.write(f"# trigger restart (comment generated by unittest)")
|
||||
file.close()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
settings = self._get_appsettings(is_dev=True)
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertIn('WasRestarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasRestarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertIn("WasRestarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasRestarted"])
|
||||
|
@@ -4,7 +4,6 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class StartTestThread(threading.Thread):
|
||||
|
||||
def __init__(self, is_dev=False):
|
||||
threading.Thread.__init__(self, daemon=True)
|
||||
self._is_dev = is_dev
|
||||
|
@@ -12,17 +12,16 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class UninstallTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'uninstall-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._version = '1.7.3'
|
||||
self._package_name = 'discord.py'
|
||||
self._package = f'{self._package_name}=={self._version}'
|
||||
self._source = "uninstall-test-source"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
self._version = "1.7.3"
|
||||
self._package_name = "discord.py"
|
||||
self._package = f"{self._package_name}=={self._version}"
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -35,28 +34,22 @@ class UninstallTestCase(CommandTestCase):
|
||||
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
|
||||
def _get_installed_packages(self) -> dict:
|
||||
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||
reqs = subprocess.check_output([sys.executable, "-m", "pip", "freeze"])
|
||||
return dict([tuple(r.decode().split("==")) for r in reqs.split()])
|
||||
|
||||
def test_uninstall(self):
|
||||
CLICommands.install(self._package)
|
||||
CLICommands.uninstall(self._package)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertNotIn(self._package, settings["ProjectSettings"]["Dependencies"])
|
||||
self.assertNotIn(self._package, settings["ProjectSettings"]["DevDependencies"])
|
||||
packages = self._get_installed_packages()
|
||||
self.assertNotIn(self._package_name, packages)
|
||||
|
||||
@@ -65,16 +58,10 @@ class UninstallTestCase(CommandTestCase):
|
||||
CLICommands.uninstall(self._package, is_dev=True)
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn('DevDependencies', settings['ProjectSettings'])
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertNotIn(
|
||||
self._package,
|
||||
settings['ProjectSettings']['DevDependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertIn("DevDependencies", settings["ProjectSettings"])
|
||||
self.assertNotIn(self._package, settings["ProjectSettings"]["Dependencies"])
|
||||
self.assertNotIn(self._package, settings["ProjectSettings"]["DevDependencies"])
|
||||
packages = self._get_installed_packages()
|
||||
self.assertNotIn(self._package_name, packages)
|
||||
|
@@ -2,8 +2,8 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "unittest_cli",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "12",
|
||||
"Major": "2023",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
@@ -16,8 +16,8 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.0",
|
||||
"cpl-cli>=2022.12.0"
|
||||
"cpl-core>=2023.2.0",
|
||||
"cpl-cli>=2023.2.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -12,32 +12,31 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class UpdateTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._source = 'install-test-source'
|
||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
||||
self._source = "install-test-source"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
|
||||
self._old_version = '1.7.1'
|
||||
self._old_package_name = 'discord.py'
|
||||
self._old_package = f'{self._old_package_name}=={self._old_version}'
|
||||
self._old_version = "1.7.1"
|
||||
self._old_package_name = "discord.py"
|
||||
self._old_package = f"{self._old_package_name}=={self._old_version}"
|
||||
|
||||
# todo: better way to do shit required
|
||||
self._new_version = '2.1.0'
|
||||
self._new_package_name = 'discord.py'
|
||||
self._new_package = f'{self._new_package_name}=={self._new_version}'
|
||||
self._new_version = "2.1.0"
|
||||
self._new_package_name = "discord.py"
|
||||
self._new_package = f"{self._new_package_name}=={self._new_version}"
|
||||
|
||||
def setUp(self):
|
||||
CLICommands.uninstall(self._old_package)
|
||||
CLICommands.uninstall(self._new_package)
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
CLICommands.install(self._old_package)
|
||||
|
||||
def _get_project_settings(self):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'r', encoding='utf-8') as cfg:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -45,23 +44,20 @@ class UpdateTestCase(CommandTestCase):
|
||||
return project_json
|
||||
|
||||
def _save_project_settings(self, settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
|
||||
with open(os.path.join(os.getcwd(), self._project_file), "w", encoding="utf-8") as project_file:
|
||||
project_file.write(json.dumps(settings, indent=2))
|
||||
project_file.close()
|
||||
|
||||
def _get_installed_packages(self) -> dict:
|
||||
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
|
||||
return dict([tuple(r.decode().split('==')) for r in reqs.split()])
|
||||
reqs = subprocess.check_output([sys.executable, "-m", "pip", "freeze"])
|
||||
return dict([tuple(r.decode().split("==")) for r in reqs.split()])
|
||||
|
||||
def test_install_package(self):
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
self._old_package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertIn(self._old_package, settings["ProjectSettings"]["Dependencies"])
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(self._old_package_name, packages)
|
||||
self.assertEqual(self._old_version, packages[self._old_package_name])
|
||||
@@ -70,12 +66,9 @@ class UpdateTestCase(CommandTestCase):
|
||||
|
||||
settings = self._get_project_settings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('ProjectSettings', settings)
|
||||
self.assertIn('Dependencies', settings['ProjectSettings'])
|
||||
self.assertIn(
|
||||
self._new_package,
|
||||
settings['ProjectSettings']['Dependencies']
|
||||
)
|
||||
self.assertIn("ProjectSettings", settings)
|
||||
self.assertIn("Dependencies", settings["ProjectSettings"])
|
||||
self.assertIn(self._new_package, settings["ProjectSettings"]["Dependencies"])
|
||||
packages = self._get_installed_packages()
|
||||
self.assertIn(self._new_package_name, packages)
|
||||
self.assertEqual(self._new_version, packages[self._new_package_name])
|
||||
|
@@ -17,7 +17,6 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class VersionTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
CommandTestCase.__init__(self, method_name)
|
||||
self._block_banner = ""
|
||||
@@ -33,21 +32,21 @@ class VersionTestCase(CommandTestCase):
|
||||
def _get_version_output(self, version: str):
|
||||
index = 0
|
||||
|
||||
for line in version.split('\n'):
|
||||
for line in version.split("\n"):
|
||||
if line == "":
|
||||
continue
|
||||
|
||||
if index <= 5:
|
||||
self._block_banner += f'{line}\n'
|
||||
self._block_banner += f"{line}\n"
|
||||
|
||||
if 7 <= index <= 9:
|
||||
self._block_version += f'{line}\n'
|
||||
self._block_version += f"{line}\n"
|
||||
|
||||
if 10 <= index <= 16:
|
||||
self._block_cpl_packages += f'{line}\n'
|
||||
self._block_cpl_packages += f"{line}\n"
|
||||
|
||||
if index >= 18:
|
||||
self._block_packages += f'{line}\n'
|
||||
self._block_packages += f"{line}\n"
|
||||
|
||||
index += 1
|
||||
|
||||
@@ -56,7 +55,7 @@ class VersionTestCase(CommandTestCase):
|
||||
cpl_packages = []
|
||||
dependencies = dict(tuple(str(ws).split()) for ws in pkg_resources.working_set)
|
||||
for p in dependencies:
|
||||
if str(p).startswith('cpl-'):
|
||||
if str(p).startswith("cpl-"):
|
||||
cpl_packages.append([p, dependencies[p]])
|
||||
continue
|
||||
|
||||
@@ -64,32 +63,34 @@ class VersionTestCase(CommandTestCase):
|
||||
|
||||
version = CLICommands.version()
|
||||
self._get_version_output(version)
|
||||
reference_banner = colored(text2art(self._name), ForegroundColorEnum.yellow.value).split('\n')
|
||||
reference_banner = "\n".join(reference_banner[:len(reference_banner) - 1]) + '\n'
|
||||
reference_banner = colored(text2art(self._name), ForegroundColorEnum.yellow.value).split("\n")
|
||||
reference_banner = "\n".join(reference_banner[: len(reference_banner) - 1]) + "\n"
|
||||
|
||||
with self.subTest(msg='Block banner'):
|
||||
with self.subTest(msg="Block banner"):
|
||||
self.assertEqual(reference_banner, self._block_banner)
|
||||
|
||||
reference_version = [
|
||||
colored(f'{colored("Common Python library CLI: ")}{colored(cpl_cli.__version__)}'),
|
||||
colored(f'{colored("Python: ")}{colored(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")}'),
|
||||
colored(f'OS: {colored(f"{platform.system()} {platform.processor()}")}') + '\n'
|
||||
colored(
|
||||
f'{colored("Python: ")}{colored(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")}'
|
||||
),
|
||||
colored(f'OS: {colored(f"{platform.system()} {platform.processor()}")}') + "\n",
|
||||
]
|
||||
with self.subTest(msg='Block version'):
|
||||
self.assertEqual('\n'.join(reference_version), self._block_version)
|
||||
with self.subTest(msg="Block version"):
|
||||
self.assertEqual("\n".join(reference_version), self._block_version)
|
||||
reference_cpl_packages = [
|
||||
colored(colored(f'CPL packages:')),
|
||||
colored(f'{tabulate(cpl_packages, headers=["Name", "Version"])}') + '\n'
|
||||
colored(colored(f"CPL packages:")),
|
||||
colored(f'{tabulate(cpl_packages, headers=["Name", "Version"])}') + "\n",
|
||||
]
|
||||
with self.subTest(msg='Block cpl packages'):
|
||||
self.assertEqual('\n'.join(reference_cpl_packages), self._block_cpl_packages)
|
||||
with self.subTest(msg="Block cpl packages"):
|
||||
self.assertEqual("\n".join(reference_cpl_packages), self._block_cpl_packages)
|
||||
reference_packages = [
|
||||
colored(colored(f'Python packages:')),
|
||||
colored(colored(f"Python packages:")),
|
||||
colored(f'{tabulate(packages, headers=["Name", "Version"])}'),
|
||||
'\x1b[0m\x1b[0m\n\x1b[0m\x1b[0m\n\x1b[0m\x1b[0m\n' # fix colored codes
|
||||
"\x1b[0m\x1b[0m\n\x1b[0m\x1b[0m\n\x1b[0m\x1b[0m\n", # fix colored codes
|
||||
]
|
||||
|
||||
self.maxDiff = None
|
||||
with self.subTest(msg='Block packages'):
|
||||
ref_packages = '\n'.join(reference_packages)
|
||||
with self.subTest(msg="Block packages"):
|
||||
ref_packages = "\n".join(reference_packages)
|
||||
self.assertEqual(ref_packages, self._block_packages)
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -2,8 +2,8 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "unittest_core",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "12",
|
||||
"Major": "2023",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.0"
|
||||
"cpl-core>=2023.2.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -9,32 +9,18 @@ from unittests_query.models import User, Address
|
||||
|
||||
|
||||
class EnumerableQueryTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
users = []
|
||||
for i in range(0, 100):
|
||||
users.append(User(
|
||||
String.random_string(string.ascii_letters, 8).lower(),
|
||||
Address(
|
||||
String.random_string(string.ascii_letters, 10).lower(),
|
||||
randint(1, 10)
|
||||
users.append(
|
||||
User(
|
||||
String.random_string(string.ascii_letters, 8).lower(),
|
||||
Address(String.random_string(string.ascii_letters, 10).lower(), randint(1, 10)),
|
||||
)
|
||||
))
|
||||
)
|
||||
|
||||
self._t_user = User(
|
||||
'Test user',
|
||||
Address(
|
||||
'teststr.',
|
||||
15
|
||||
)
|
||||
)
|
||||
self._t_user2 = User(
|
||||
'Test user',
|
||||
Address(
|
||||
'teststr.',
|
||||
14
|
||||
)
|
||||
)
|
||||
self._t_user = User("Test user", Address("teststr.", 15))
|
||||
self._t_user2 = User("Test user", Address("teststr.", 14))
|
||||
|
||||
users.append(self._t_user)
|
||||
users.append(self._t_user2)
|
||||
@@ -76,7 +62,7 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(avg, res)
|
||||
|
||||
def invalid():
|
||||
tests = Enumerable(str, ['hello', 'world'])
|
||||
tests = Enumerable(str, ["hello", "world"])
|
||||
e_res = tests.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
@@ -172,10 +158,7 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
|
||||
def test_for_each(self):
|
||||
users = []
|
||||
self._tests.for_each(lambda user: (
|
||||
users.append(user)
|
||||
)
|
||||
)
|
||||
self._tests.for_each(lambda user: (users.append(user)))
|
||||
|
||||
self.assertEqual(len(users), len(self._tests))
|
||||
|
||||
@@ -187,7 +170,7 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(99, tests.max())
|
||||
|
||||
def invalid():
|
||||
tests = Enumerable(str, ['hello', 'world'])
|
||||
tests = Enumerable(str, ["hello", "world"])
|
||||
e_res = tests.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
@@ -200,7 +183,7 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(0, tests.min())
|
||||
|
||||
def invalid():
|
||||
tests = Enumerable(str, ['hello', 'world'])
|
||||
tests = Enumerable(str, ["hello", "world"])
|
||||
e_res = tests.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
@@ -238,7 +221,11 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(res, s_res)
|
||||
|
||||
def test_then_by_descending(self):
|
||||
res = self._tests.order_by_descending(lambda user: user.address.street).then_by_descending(lambda user: user.address.nr).to_list()
|
||||
res = (
|
||||
self._tests.order_by_descending(lambda user: user.address.street)
|
||||
.then_by_descending(lambda user: user.address.nr)
|
||||
.to_list()
|
||||
)
|
||||
|
||||
s_res = self._tests.to_list()
|
||||
s_res.sort(key=lambda user: (user.address.street, user.address.nr), reverse=True)
|
||||
@@ -268,7 +255,10 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
selected_range = range_list.select(lambda x: [x, x])
|
||||
|
||||
self.assertEqual(selected_range.to_list(), [[x, x] for x in range(0, 100)])
|
||||
self.assertEqual(selected_range.select_many(lambda x: x).to_list(), [_x for _l in [2 * [x] for x in range(0, 100)] for _x in _l])
|
||||
self.assertEqual(
|
||||
selected_range.select_many(lambda x: x).to_list(),
|
||||
[_x for _l in [2 * [x] for x in range(0, 100)] for _x in _l],
|
||||
)
|
||||
|
||||
class TestClass:
|
||||
def __init__(self, i, is_sub=False):
|
||||
@@ -323,7 +313,7 @@ class EnumerableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(0, tests.min())
|
||||
|
||||
def invalid():
|
||||
tests2 = Enumerable(str, ['hello', 'world'])
|
||||
tests2 = Enumerable(str, ["hello", "world"])
|
||||
e_res = tests2.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
|
@@ -4,13 +4,12 @@ from cpl_query.enumerable.enumerable import Enumerable
|
||||
|
||||
|
||||
class EnumerableTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self._list = Enumerable(int, list(range(1, 4)))
|
||||
|
||||
def test_append(self):
|
||||
self.assertEqual(self._list.to_list(), [1, 2, 3])
|
||||
self.assertRaises(Exception, lambda v: self._list.add(v), '3')
|
||||
self.assertRaises(Exception, lambda v: self._list.add(v), "3")
|
||||
|
||||
def test_default(self):
|
||||
self.assertEqual(Enumerable.empty().to_list(), [])
|
||||
|
@@ -10,23 +10,10 @@ from unittests_query.models import User, Address
|
||||
|
||||
|
||||
class IterableQueryTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self._tests = List(User)
|
||||
self._t_user = User(
|
||||
'Test user',
|
||||
Address(
|
||||
'teststr.',
|
||||
15
|
||||
)
|
||||
)
|
||||
self._t_user2 = User(
|
||||
'Test user',
|
||||
Address(
|
||||
'teststr.',
|
||||
14
|
||||
)
|
||||
)
|
||||
self._t_user = User("Test user", Address("teststr.", 15))
|
||||
self._t_user2 = User("Test user", Address("teststr.", 14))
|
||||
|
||||
self._generate_test_data()
|
||||
|
||||
@@ -34,10 +21,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
for i in range(0, 100):
|
||||
user = User(
|
||||
String.random_string(string.ascii_letters, 8).lower(),
|
||||
Address(
|
||||
String.random_string(string.ascii_letters, 10).lower(),
|
||||
randint(1, 10)
|
||||
)
|
||||
Address(String.random_string(string.ascii_letters, 10).lower(), randint(1, 10)),
|
||||
)
|
||||
|
||||
self._tests.append(user)
|
||||
@@ -80,7 +64,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(avg, res)
|
||||
|
||||
def invalid():
|
||||
tests = List(str, ['hello', 'world'])
|
||||
tests = List(str, ["hello", "world"])
|
||||
e_res = tests.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
@@ -204,10 +188,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
|
||||
def test_for_each(self):
|
||||
users = []
|
||||
self._tests.for_each(lambda user: (
|
||||
users.append(user)
|
||||
)
|
||||
)
|
||||
self._tests.for_each(lambda user: (users.append(user)))
|
||||
|
||||
self.assertEqual(len(users), len(self._tests))
|
||||
|
||||
@@ -219,7 +200,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(99, tests.max())
|
||||
|
||||
def invalid():
|
||||
tests = List(str, ['hello', 'world'])
|
||||
tests = List(str, ["hello", "world"])
|
||||
e_res = tests.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
@@ -232,7 +213,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(0, tests.min())
|
||||
|
||||
def invalid():
|
||||
tests = List(str, ['hello', 'world'])
|
||||
tests = List(str, ["hello", "world"])
|
||||
e_res = tests.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
@@ -270,7 +251,11 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(res, s_res)
|
||||
|
||||
def test_then_by_descending(self):
|
||||
res = self._tests.order_by_descending(lambda user: user.address.street).then_by_descending(lambda user: user.address.nr).to_list()
|
||||
res = (
|
||||
self._tests.order_by_descending(lambda user: user.address.street)
|
||||
.then_by_descending(lambda user: user.address.nr)
|
||||
.to_list()
|
||||
)
|
||||
|
||||
s_res = self._tests.to_list()
|
||||
s_res.sort(key=lambda user: (user.address.street, user.address.nr), reverse=True)
|
||||
@@ -300,7 +285,10 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
selected_range = range_list.select(lambda x: [x, x])
|
||||
|
||||
self.assertEqual(selected_range.to_list(), [[x, x] for x in range(0, 100)])
|
||||
self.assertEqual(selected_range.select_many(lambda x: x).to_list(), [_x for _l in [2 * [x] for x in range(0, 100)] for _x in _l])
|
||||
self.assertEqual(
|
||||
selected_range.select_many(lambda x: x).to_list(),
|
||||
[_x for _l in [2 * [x] for x in range(0, 100)] for _x in _l],
|
||||
)
|
||||
|
||||
class TestClass:
|
||||
def __init__(self, i, is_sub=False):
|
||||
@@ -342,7 +330,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(skipped.to_list(), self._tests[:-5])
|
||||
self.assertEqual(skipped.last(), self._tests[:-5][len(self._tests[:-5]) - 1])
|
||||
|
||||
def test_sum(self) -> List['int']:
|
||||
def test_sum(self) -> List["int"]:
|
||||
res = self._tests.sum(lambda u: u.address.nr)
|
||||
|
||||
s_res = 0
|
||||
@@ -355,7 +343,7 @@ class IterableQueryTestCase(unittest.TestCase):
|
||||
self.assertEqual(0, tests.min())
|
||||
|
||||
def invalid():
|
||||
tests2 = List(str, ['hello', 'world'])
|
||||
tests2 = List(str, ["hello", "world"])
|
||||
e_res = tests2.average()
|
||||
|
||||
self.assertRaises(InvalidTypeException, invalid)
|
||||
|
@@ -4,7 +4,6 @@ from cpl_query.extension.list import List
|
||||
|
||||
|
||||
class IterableTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self._list = List(int)
|
||||
|
||||
@@ -18,7 +17,7 @@ class IterableTestCase(unittest.TestCase):
|
||||
self._list.append(3)
|
||||
|
||||
self.assertEqual(self._list.to_list(), [1, 2, 3])
|
||||
self.assertRaises(Exception, lambda v: self._list.append(v), '3')
|
||||
self.assertRaises(Exception, lambda v: self._list.append(v), "3")
|
||||
|
||||
def test_assign(self):
|
||||
self._list.append(1)
|
||||
@@ -32,4 +31,4 @@ class IterableTestCase(unittest.TestCase):
|
||||
del self._list[3]
|
||||
|
||||
self.assertEqual(self._list.to_list(), [1, 2, 3])
|
||||
self.assertRaises(Exception, lambda v: self._list.append(v), '3')
|
||||
self.assertRaises(Exception, lambda v: self._list.append(v), "3")
|
||||
|
@@ -1,18 +1,16 @@
|
||||
class User:
|
||||
|
||||
def __init__(self, name, address):
|
||||
self.name = name
|
||||
self.address = address
|
||||
|
||||
def __repr__(self):
|
||||
return f'<{type(self).__name__} {self.name} {self.address}>'
|
||||
return f"<{type(self).__name__} {self.name} {self.address}>"
|
||||
|
||||
|
||||
class Address:
|
||||
|
||||
def __init__(self, street, nr):
|
||||
self.street = street
|
||||
self.nr = nr
|
||||
|
||||
def __repr__(self):
|
||||
return f'<{type(self).__name__} {self.street} {self.nr}>'
|
||||
return f"<{type(self).__name__} {self.street} {self.nr}>"
|
||||
|
@@ -10,7 +10,6 @@ COUNT = 50
|
||||
|
||||
|
||||
class PerformanceTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
i = 0
|
||||
self.values = []
|
||||
@@ -23,10 +22,10 @@ class PerformanceTestCase(unittest.TestCase):
|
||||
iterable = timeit.timeit(lambda: Iterable.range(0, VALUES), number=COUNT)
|
||||
enumerable = timeit.timeit(lambda: Enumerable.range(0, VALUES), number=COUNT)
|
||||
|
||||
print('Range')
|
||||
print(f'd: {default}s')
|
||||
print(f'i: {iterable}s')
|
||||
print(f'e: {enumerable}s')
|
||||
print("Range")
|
||||
print(f"d: {default}s")
|
||||
print(f"i: {iterable}s")
|
||||
print(f"e: {enumerable}s")
|
||||
|
||||
self.assertAlmostEqual(round(default, 3), round(enumerable, 3))
|
||||
self.assertAlmostEqual(round(default, 3), round(iterable, 3))
|
||||
@@ -36,17 +35,16 @@ class PerformanceTestCase(unittest.TestCase):
|
||||
iterable = timeit.timeit(lambda: Iterable.range(0, VALUES).where(lambda x: x == 50).single(), number=COUNT)
|
||||
enumerable = timeit.timeit(lambda: Enumerable.range(0, VALUES).where(lambda x: x == 50).single(), number=COUNT)
|
||||
|
||||
print('Where single')
|
||||
print(f'd: {default}s')
|
||||
print(f'i: {iterable}s')
|
||||
print(f'e: {enumerable}s')
|
||||
print("Where single")
|
||||
print(f"d: {default}s")
|
||||
print(f"i: {iterable}s")
|
||||
print(f"e: {enumerable}s")
|
||||
|
||||
self.assertLess(default, enumerable)
|
||||
self.assertLess(default, iterable)
|
||||
|
||||
def test_where_single_complex(self):
|
||||
class TestModel:
|
||||
|
||||
def __init__(self, v, tm=None):
|
||||
self.value = v
|
||||
self.tm = tm
|
||||
@@ -56,13 +54,17 @@ class PerformanceTestCase(unittest.TestCase):
|
||||
values.append(TestModel(i, TestModel(i + 1)))
|
||||
|
||||
default = timeit.timeit(lambda: [x for x in values if x.tm.value == 50], number=COUNT)
|
||||
iterable = timeit.timeit(lambda: Iterable(TestModel, values).where(lambda x: x.tm.value == 50).single(), number=COUNT)
|
||||
enumerable = timeit.timeit(lambda: Enumerable(TestModel, values).where(lambda x: x.tm.value == 50).single(), number=COUNT)
|
||||
iterable = timeit.timeit(
|
||||
lambda: Iterable(TestModel, values).where(lambda x: x.tm.value == 50).single(), number=COUNT
|
||||
)
|
||||
enumerable = timeit.timeit(
|
||||
lambda: Enumerable(TestModel, values).where(lambda x: x.tm.value == 50).single(), number=COUNT
|
||||
)
|
||||
|
||||
print('Complex where single')
|
||||
print(f'd: {default}s')
|
||||
print(f'i: {iterable}s')
|
||||
print(f'e: {enumerable}s')
|
||||
print("Complex where single")
|
||||
print(f"d: {default}s")
|
||||
print(f"i: {iterable}s")
|
||||
print(f"e: {enumerable}s")
|
||||
|
||||
self.assertLess(default, enumerable)
|
||||
self.assertLess(default, iterable)
|
||||
|
@@ -8,7 +8,6 @@ from unittests_query.sequence_test_case import SequenceTestCase
|
||||
|
||||
|
||||
class QueryTestSuite(unittest.TestSuite):
|
||||
|
||||
def __init__(self):
|
||||
unittest.TestSuite.__init__(self)
|
||||
|
||||
|
@@ -6,7 +6,6 @@ from cpl_query.iterable import Iterable
|
||||
|
||||
|
||||
class SequenceTestCase(unittest.TestCase):
|
||||
|
||||
def test_to_list(self):
|
||||
_list = List().extend(range(0, 100))
|
||||
enumerable = Enumerable.range(0, 100)
|
||||
|
@@ -2,9 +2,9 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "unittest_query",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "12",
|
||||
"Micro": "dev134"
|
||||
"Major": "2023",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
@@ -16,8 +16,8 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.0",
|
||||
"cpl-query>=2022.12.dev134"
|
||||
"cpl-core>=2023.2.0",
|
||||
"cpl-query>=2023.2.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -6,27 +6,28 @@ from unittests_cli.constants import CLI_PATH
|
||||
|
||||
|
||||
class CLICommands:
|
||||
|
||||
@staticmethod
|
||||
def _run(cmd: str, *args, output=False):
|
||||
env_vars = os.environ
|
||||
env_vars['CPL_IS_UNITTEST'] = 'NO' if output else 'YES'
|
||||
env_vars["CPL_IS_UNITTEST"] = "NO" if output else "YES"
|
||||
|
||||
command = ['python', CLI_PATH, cmd]
|
||||
command = ["python", CLI_PATH, cmd]
|
||||
for arg in args:
|
||||
command.append(arg)
|
||||
|
||||
if output:
|
||||
subprocess.run(command, env=env_vars)
|
||||
else:
|
||||
subprocess.run(command, env=env_vars, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)
|
||||
subprocess.run(
|
||||
command, env=env_vars, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL
|
||||
)
|
||||
|
||||
@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]
|
||||
command = ["python", CLI_PATH, cmd]
|
||||
for arg in args:
|
||||
command.append(arg)
|
||||
|
||||
@@ -34,63 +35,63 @@ class CLICommands:
|
||||
|
||||
@classmethod
|
||||
def add(cls, source: str, target: str, output=False):
|
||||
cls._run('add', source, target, output=output)
|
||||
cls._run("add", source, target, output=output)
|
||||
|
||||
@classmethod
|
||||
def build(cls, output=False):
|
||||
cls._run('build', output=output)
|
||||
cls._run("build", output=output)
|
||||
|
||||
@classmethod
|
||||
def generate(cls, schematic: str, name: str, output=False):
|
||||
cls._run('generate', schematic, name, output=output)
|
||||
cls._run("generate", schematic, name, output=output)
|
||||
|
||||
@classmethod
|
||||
def install(cls, package: str = None, is_dev=False, output=False):
|
||||
if package is None:
|
||||
cls._run('install', output=output)
|
||||
cls._run("install", output=output)
|
||||
return
|
||||
|
||||
cls._run('install', package, '--dev' if is_dev else '', output=output)
|
||||
cls._run("install", package, "--dev" if is_dev else "", output=output)
|
||||
|
||||
@classmethod
|
||||
def new(cls, project_type: str, name: str, *args, output=False):
|
||||
cls._run('new', project_type, name, *args, output=output)
|
||||
cls._run("new", project_type, name, *args, output=output)
|
||||
|
||||
@classmethod
|
||||
def publish(cls, output=False):
|
||||
cls._run('publish', output=output)
|
||||
cls._run("publish", output=output)
|
||||
|
||||
@classmethod
|
||||
def remove(cls, project: str, output=False):
|
||||
cls._run('remove', project, output=output)
|
||||
cls._run("remove", project, output=output)
|
||||
|
||||
@classmethod
|
||||
def run(cls, project: str = None, is_dev=False, output=False):
|
||||
args = []
|
||||
if is_dev:
|
||||
args.append('--dev')
|
||||
args.append("--dev")
|
||||
|
||||
if project is None:
|
||||
cls._run('run', *args, output=output)
|
||||
cls._run("run", *args, output=output)
|
||||
return
|
||||
cls._run('run', project, *args, output=output)
|
||||
cls._run("run", project, *args, output=output)
|
||||
|
||||
@classmethod
|
||||
def start(cls, is_dev=False, output=False):
|
||||
args = []
|
||||
if is_dev:
|
||||
args.append('--dev')
|
||||
args.append("--dev")
|
||||
|
||||
cls._run('start', *args, output=output)
|
||||
cls._run("start", *args, output=output)
|
||||
|
||||
@classmethod
|
||||
def uninstall(cls, package: str, is_dev=False, output=False):
|
||||
cls._run('uninstall', package, '--dev' if is_dev else '', output=output)
|
||||
cls._run("uninstall", package, "--dev" if is_dev else "", output=output)
|
||||
|
||||
@classmethod
|
||||
def update(cls, output=False):
|
||||
cls._run('update', output=output)
|
||||
cls._run("update", output=output)
|
||||
|
||||
@classmethod
|
||||
def version(cls) -> str:
|
||||
return cls._run_with_output('version')
|
||||
return cls._run_with_output("version")
|
||||
|
@@ -2,8 +2,8 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "unittest_shared",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "12",
|
||||
"Major": "2023",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.0"
|
||||
"cpl-core>=2023.2.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
@@ -1 +1 @@
|
||||
# imports:
|
||||
# imports:
|
||||
|
@@ -7,7 +7,6 @@ from unittests_cli.constants import TRANSLATION_PATH
|
||||
|
||||
|
||||
class TranslationTestCase(unittest.TestCase):
|
||||
|
||||
def __init__(self, methodName: str):
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
self._translation: Optional[TranslationService] = None
|
||||
@@ -17,51 +16,45 @@ class TranslationTestCase(unittest.TestCase):
|
||||
os.chdir(os.path.abspath(TRANSLATION_PATH))
|
||||
self._translation = TranslationService()
|
||||
settings = TranslationSettings()
|
||||
settings.from_dict({
|
||||
"Languages": [
|
||||
"de",
|
||||
"en"
|
||||
],
|
||||
"DefaultLanguage": "en"
|
||||
})
|
||||
settings.from_dict({"Languages": ["de", "en"], "DefaultLanguage": "en"})
|
||||
self._translation.load_by_settings(settings)
|
||||
self._translation.set_default_lang('de')
|
||||
self._translation.set_default_lang("de")
|
||||
self._translate = TranslatePipe(self._translation)
|
||||
|
||||
def cleanUp(self):
|
||||
pass
|
||||
|
||||
def test_service(self):
|
||||
self.assertEqual('Hallo Welt', self._translation.translate('main.text.hello_world'))
|
||||
self._translation.set_lang('en')
|
||||
self.assertEqual('Hello World', self._translation.translate('main.text.hello_world'))
|
||||
self.assertEqual("Hallo Welt", self._translation.translate("main.text.hello_world"))
|
||||
self._translation.set_lang("en")
|
||||
self.assertEqual("Hello World", self._translation.translate("main.text.hello_world"))
|
||||
with self.assertRaises(KeyError) as ctx:
|
||||
self._translation.translate('main.text.hallo_welt')
|
||||
self._translation.translate("main.text.hallo_welt")
|
||||
|
||||
self.assertTrue(type(ctx.exception) == KeyError)
|
||||
self.assertIn('Translation main.text.hallo_welt not found', str(ctx.exception))
|
||||
self.assertIn("Translation main.text.hallo_welt not found", str(ctx.exception))
|
||||
|
||||
with self.assertRaises(FileNotFoundError) as ctx:
|
||||
self._translation.load('DE')
|
||||
self._translation.load("DE")
|
||||
|
||||
self.assertTrue(type(ctx.exception) == FileNotFoundError)
|
||||
|
||||
with self.assertRaises(KeyError) as ctx:
|
||||
self._translation.set_lang('DE')
|
||||
self._translation.set_lang("DE")
|
||||
|
||||
self.assertTrue(type(ctx.exception) == KeyError)
|
||||
|
||||
with self.assertRaises(KeyError) as ctx:
|
||||
self._translation.set_default_lang('DE')
|
||||
self._translation.set_default_lang("DE")
|
||||
|
||||
self.assertTrue(type(ctx.exception) == KeyError)
|
||||
|
||||
def test_pipe(self):
|
||||
self.assertEqual('Hallo Welt', self._translate.transform('main.text.hello_world'))
|
||||
self._translation.set_lang('en')
|
||||
self.assertEqual('Hello World', self._translate.transform('main.text.hello_world'))
|
||||
self.assertEqual("Hallo Welt", self._translate.transform("main.text.hello_world"))
|
||||
self._translation.set_lang("en")
|
||||
self.assertEqual("Hello World", self._translate.transform("main.text.hello_world"))
|
||||
with self.assertRaises(KeyError) as ctx:
|
||||
self._translation.translate('main.text.hallo_welt')
|
||||
self._translation.translate("main.text.hallo_welt")
|
||||
|
||||
self.assertTrue(type(ctx.exception) == KeyError)
|
||||
self.assertIn('Translation main.text.hallo_welt not found', str(ctx.exception))
|
||||
self.assertIn("Translation main.text.hallo_welt not found", str(ctx.exception))
|
||||
|
@@ -6,7 +6,6 @@ from unittests_translation.translation_test_case import TranslationTestCase
|
||||
|
||||
|
||||
class TranslationTestSuite(unittest.TestSuite):
|
||||
|
||||
def __init__(self):
|
||||
unittest.TestSuite.__init__(self)
|
||||
|
||||
@@ -14,9 +13,7 @@ class TranslationTestSuite(unittest.TestSuite):
|
||||
self._result: Optional[TestResult] = None
|
||||
self._is_online = True
|
||||
|
||||
active_tests = [
|
||||
TranslationTestCase
|
||||
]
|
||||
active_tests = [TranslationTestCase]
|
||||
|
||||
for test in active_tests:
|
||||
self.addTests(loader.loadTestsFromTestCase(test))
|
||||
|
@@ -2,8 +2,8 @@
|
||||
"ProjectSettings": {
|
||||
"Name": "unittests_translation",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "12",
|
||||
"Major": "2023",
|
||||
"Minor": "2",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "",
|
||||
@@ -16,11 +16,11 @@
|
||||
"LicenseName": "",
|
||||
"LicenseDescription": "",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.0",
|
||||
"cpl-translation>=2022.12.0"
|
||||
"cpl-core>=2023.2.0",
|
||||
"cpl-translation>=2023.2.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.12.0"
|
||||
"cpl-cli>=2023.2.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
|
Reference in New Issue
Block a user