cpl query Enumerable quatsch #129 #130

Merged
edraft merged 6 commits from #129 into 2022.12 2022-12-01 23:43:01 +01:00
19 changed files with 103 additions and 153 deletions
Showing only changes of commit 2840628443 - Show all commits

View File

View File

@ -0,0 +1,35 @@
import os
import shutil
import traceback
import unittest
from unittests_cli.constants import PLAYGROUND_PATH
class CommandTestCase(unittest.TestCase):
def __init__(self, method_name: str):
unittest.TestCase.__init__(self, method_name)
@classmethod
def setUpClass(cls):
try:
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH)
except Exception as e:
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
def setUp(self):
os.chdir(PLAYGROUND_PATH)
@classmethod
def tearDownClass(cls):
try:
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()}')

View File

@ -1,18 +1,16 @@
import json import json
import os import os
import shutil
import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class AddTestCase(unittest.TestCase): class AddTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'add-test-project' self._source = 'add-test-project'
self._target = 'add-test-library' self._target = 'add-test-library'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
@ -26,22 +24,12 @@ class AddTestCase(unittest.TestCase):
return project_json return project_json
def setUp(self): def setUp(self):
if not os.path.exists(PLAYGROUND_PATH):
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH) os.chdir(PLAYGROUND_PATH)
# create projects # 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)) os.chdir(os.path.join(os.getcwd(), self._source))
CLICommands.new('console', self._target, '--ab', '--s') CLICommands.new('console', self._target, '--ab', '--s')
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 test_add(self): def test_add(self):
CLICommands.add(self._source, self._target) CLICommands.add(self._source, self._target)
settings = self._get_project_settings() settings = self._get_project_settings()

View File

@ -2,18 +2,17 @@ import filecmp
import json import json
import os import os
import shutil import shutil
import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class BuildTestCase(unittest.TestCase): class BuildTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'build-test-source' self._source = 'build-test-source'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
@ -39,13 +38,6 @@ class BuildTestCase(unittest.TestCase):
CLICommands.new('console', self._source, '--ab', '--s') CLICommands.new('console', self._source, '--ab', '--s')
os.chdir(os.path.join(os.getcwd(), self._source)) os.chdir(os.path.join(os.getcwd(), self._source))
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 _are_dir_trees_equal(self, dir1, dir2): def _are_dir_trees_equal(self, dir1, dir2):
""" """
found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi

View File

@ -76,3 +76,8 @@ class CLITestSuite(unittest.TestSuite):
self._setup() self._setup()
self._result = super().run(*args) self._result = super().run(*args)
self._cleanup() self._cleanup()
if __name__ == "__main__":
runner = unittest.TextTestRunner()
runner.run(CLITestSuite())

View File

@ -6,4 +6,4 @@ if not os.getcwd().endswith('unittests'):
PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}test_cli_playground')) 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')) 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'../../src/cpl_cli/main.py')) CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), f'{base}../src/cpl_cli/main.py'))

View File

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

View File

@ -1,17 +1,18 @@
import os.path import os.path
import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class GenerateTestCase(unittest.TestCase): class GenerateTestCase(CommandTestCase):
_project = 'test-console' _project = 'test-console'
_t_path = 'test' _t_path = 'test'
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
CommandTestCase.setUpClass()
CLICommands.new('console', cls._project, '--ab', '--s', '--venv') CLICommands.new('console', cls._project, '--ab', '--s', '--venv')
def setUp(self): def setUp(self):

View File

@ -6,14 +6,15 @@ import sys
import unittest import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class InstallTestCase(unittest.TestCase): class InstallTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'install-test-source' self._source = 'install-test-source'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
@ -39,13 +40,6 @@ class InstallTestCase(unittest.TestCase):
CLICommands.new('console', self._source, '--ab', '--s') CLICommands.new('console', self._source, '--ab', '--s')
os.chdir(os.path.join(os.getcwd(), self._source)) os.chdir(os.path.join(os.getcwd(), self._source))
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: def _get_installed_packages(self) -> dict:
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
return dict([tuple(r.decode().split('==')) for r in reqs.split()]) return dict([tuple(r.decode().split('==')) for r in reqs.split()])

View File

@ -1,19 +1,16 @@
import json import json
import os import os
import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class NewTestCase(unittest.TestCase): class NewTestCase(CommandTestCase):
def setUp(self): def __init__(self, method_name: str):
if not os.path.exists(PLAYGROUND_PATH): CommandTestCase.__init__(self, method_name)
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH)
def _test_project(self, project_type: str, name: str, *args, test_venv=False, without_ws=False): def _test_project(self, project_type: str, name: str, *args, test_venv=False, without_ws=False):
CLICommands.new(project_type, name, *args) CLICommands.new(project_type, name, *args)
@ -73,7 +70,6 @@ class NewTestCase(unittest.TestCase):
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.exists(project_path))
self.assertTrue(os.path.join(project_path, f'{name}.json')) self.assertTrue(os.path.join(project_path, f'{name}.json'))
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
def _test_sub_directory_project(self, project_type: str, directory: str, name: str, workspace_name: str, *args): 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))) os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name)))
@ -99,8 +95,6 @@ class NewTestCase(unittest.TestCase):
self.assertEqual(build_settings['Main'], f'{String.convert_to_snake_case(name)}.main') self.assertEqual(build_settings['Main'], f'{String.convert_to_snake_case(name)}.main')
self.assertEqual(build_settings['EntryPoint'], name) self.assertEqual(build_settings['EntryPoint'], name)
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
def test_console(self): 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)

View File

@ -5,15 +5,16 @@ import shutil
import unittest import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class PublishTestCase(unittest.TestCase): class PublishTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'publish-test-source' self._source = 'publish-test-source'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
@ -39,13 +40,6 @@ class PublishTestCase(unittest.TestCase):
CLICommands.new('console', self._source, '--ab', '--s') CLICommands.new('console', self._source, '--ab', '--s')
os.chdir(os.path.join(os.getcwd(), self._source)) os.chdir(os.path.join(os.getcwd(), self._source))
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 _are_dir_trees_equal(self, dir1, dir2): def _are_dir_trees_equal(self, dir1, dir2):
""" """
found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi found at https://stackoverflow.com/questions/4187564/recursively-compare-two-directories-to-ensure-they-have-the-same-files-and-subdi

View File

@ -3,14 +3,15 @@ import os
import unittest import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class RemoveTestCase(unittest.TestCase): class RemoveTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'add-test-project' self._source = 'add-test-project'
self._target = 'add-test-library' self._target = 'add-test-library'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'

View File

@ -1,22 +1,18 @@
import json import json
import os import os
import shutil import shutil
import subprocess
import sys
import unittest import unittest
import pkg_resources
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class RunTestCase(unittest.TestCase): class RunTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'run-test' self._source = 'run-test'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' 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._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
@ -63,13 +59,6 @@ class RunTestCase(unittest.TestCase):
file.write(f'\t\t{self._test_code}') file.write(f'\t\t{self._test_code}')
file.close() file.close()
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 test_run(self): def test_run(self):
CLICommands.run() CLICommands.run()
settings = self._get_appsettings() settings = self._get_appsettings()

View File

@ -5,15 +5,16 @@ import time
import unittest import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_cli.threads.start_test_thread import StartTestThread from unittests_cli.threads.start_test_thread import StartTestThread
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class StartTestCase(unittest.TestCase): class StartTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'start-test' self._source = 'start-test'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' 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._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
@ -63,13 +64,6 @@ class StartTestCase(unittest.TestCase):
file.write(f'\t\t{self._test_code}') file.write(f'\t\t{self._test_code}')
file.close() file.close()
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 test_start(self): def test_start(self):
thread = StartTestThread() thread = StartTestThread()
thread.start() thread.start()

View File

@ -6,14 +6,15 @@ import sys
import unittest import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class UninstallTestCase(unittest.TestCase): class UninstallTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'uninstall-test-source' self._source = 'uninstall-test-source'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
self._version = '1.7.3' self._version = '1.7.3'
@ -31,19 +32,12 @@ class UninstallTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
if not os.path.exists(PLAYGROUND_PATH): if not os.path.exists(PLAYGROUND_PATH):
os.makedirs(PLAYGROUND_PATH) os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH) os.chdir(PLAYGROUND_PATH)
# create projects # 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)) os.chdir(os.path.join(os.getcwd(), self._source))
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: def _get_installed_packages(self) -> dict:
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
return dict([tuple(r.decode().split('==')) for r in reqs.split()]) return dict([tuple(r.decode().split('==')) for r in reqs.split()])

View File

@ -6,14 +6,15 @@ import sys
import unittest import unittest
from cpl_core.utils import String from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_cli.constants import PLAYGROUND_PATH from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class UpdateTestCase(unittest.TestCase): class UpdateTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._source = 'install-test-source' self._source = 'install-test-source'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json' 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_name = 'discord.py'
self._new_package = f'{self._new_package_name}=={self._new_version}' 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): 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 # load json
@ -39,22 +49,6 @@ class UpdateTestCase(unittest.TestCase):
project_file.write(json.dumps(settings, indent=2)) project_file.write(json.dumps(settings, indent=2))
project_file.close() 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: def _get_installed_packages(self) -> dict:
reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']) reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
return dict([tuple(r.decode().split('==')) for r in reqs.split()]) return dict([tuple(r.decode().split('==')) for r in reqs.split()])
@ -85,5 +79,3 @@ class UpdateTestCase(unittest.TestCase):
packages = self._get_installed_packages() packages = self._get_installed_packages()
self.assertIn(self._new_package_name, packages) self.assertIn(self._new_package_name, packages)
self.assertEqual(self._new_version, packages[self._new_package_name]) self.assertEqual(self._new_version, packages[self._new_package_name])

View File

@ -12,13 +12,14 @@ import cpl_cli
from cpl_core.console import ForegroundColorEnum from cpl_core.console import ForegroundColorEnum
from termcolor import colored from termcolor import colored
from unittests_cli.abc.command_test_case import CommandTestCase
from unittests_shared.cli_commands import CLICommands from unittests_shared.cli_commands import CLICommands
class VersionTestCase(unittest.TestCase): class VersionTestCase(CommandTestCase):
def __init__(self, methodName: str): def __init__(self, method_name: str):
unittest.TestCase.__init__(self, methodName) CommandTestCase.__init__(self, method_name)
self._block_banner = "" self._block_banner = ""
self._block_version = "" self._block_version = ""
self._block_package_header = "" self._block_package_header = ""

View File

@ -1,5 +1,6 @@
import os import os
import subprocess import subprocess
import sys
from unittests_cli.constants import CLI_PATH from unittests_cli.constants import CLI_PATH
@ -29,7 +30,8 @@ class CLICommands:
for arg in args: for arg in args:
command.append(arg) command.append(arg)
return subprocess.run(command, env=env_vars, check=True, capture_output=True, text=True).stdout with subprocess.Popen(command, stdout=subprocess.PIPE, universal_newlines=True) as process:
return process.stdout.read()
@classmethod @classmethod
def add(cls, source: str, target: str, output=False): def add(cls, source: str, target: str, output=False):

View File

@ -1,11 +1,7 @@
import os
import shutil
import traceback
import unittest import unittest
from typing import Optional from typing import Optional
from unittest import TestResult from unittest import TestResult
from unittests_cli.constants import PLAYGROUND_PATH
from unittests_translation.translation_test_case import TranslationTestCase from unittests_translation.translation_test_case import TranslationTestCase
@ -25,27 +21,5 @@ class TranslationTestSuite(unittest.TestSuite):
for test in active_tests: for test in active_tests:
self.addTests(loader.loadTestsFromTestCase(test)) self.addTests(loader.loadTestsFromTestCase(test))
def _setup(self):
try:
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH)
except Exception as e:
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
def _cleanup(self):
try:
if self._result is not None and (len(self._result.errors) > 0 or len(self._result.failures) > 0):
return
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()}')
def run(self, *args): def run(self, *args):
self._setup()
self._result = super().run(*args) self._result = super().run(*args)
self._cleanup()