Improved tests #129

This commit is contained in:
2022-12-01 23:23:48 +01:00
parent f0f79e7e3b
commit 2840628443
19 changed files with 103 additions and 153 deletions

View File

@@ -6,14 +6,15 @@ import sys
import unittest
from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands
class UpdateTestCase(unittest.TestCase):
class UpdateTestCase(CommandTestCase):
def __init__(self, methodName: str):
unittest.TestCase.__init__(self, methodName)
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'
@@ -26,6 +27,15 @@ class UpdateTestCase(unittest.TestCase):
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')
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:
# load json
@@ -39,22 +49,6 @@ class UpdateTestCase(unittest.TestCase):
project_file.write(json.dumps(settings, indent=2))
project_file.close()
def setUp(self):
CLICommands.uninstall(self._old_package)
CLICommands.uninstall(self._new_package)
os.chdir(os.path.abspath(PLAYGROUND_PATH))
# create projects
CLICommands.new('console', self._source, '--ab', '--s')
os.chdir(os.path.join(os.getcwd(), self._source))
CLICommands.install(self._old_package)
def cleanUp(self):
# remove projects
if not os.path.exists(os.path.abspath(os.path.join(PLAYGROUND_PATH, self._source))):
return
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, 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()])
@@ -85,5 +79,3 @@ class UpdateTestCase(unittest.TestCase):
packages = self._get_installed_packages()
self.assertIn(self._new_package_name, packages)
self.assertEqual(self._new_version, packages[self._new_package_name])