Updated docs

This commit is contained in:
2023-02-20 15:55:20 +01:00
parent 48d0daabf5
commit 9e28dce5ce
632 changed files with 10917 additions and 6775 deletions

View File

@@ -1 +1 @@
# imports:
# imports:

View File

@@ -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()}")

View File

@@ -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"],
)

View File

@@ -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)
)

View File

@@ -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()

View File

@@ -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"))

View File

@@ -2,7 +2,6 @@ from unittests_cli.abc.command_test_case import CommandTestCase
class CustomTestCase(CommandTestCase):
def setUp(self):
pass

View File

@@ -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)

View File

@@ -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])

View File

@@ -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")

View File

@@ -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)
)

View File

@@ -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"],
)

View File

@@ -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"]
)

View File

@@ -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"])

View File

@@ -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

View File

@@ -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)

View File

@@ -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": {},

View File

@@ -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])

View File

@@ -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)