sh_cpl/unittests/unittests_cli/cli_test_suite.py

79 lines
2.5 KiB
Python
Raw Normal View History

2022-05-26 13:59:46 +02:00
import os
2022-05-26 14:47:36 +02:00
import shutil
2022-05-26 13:59:46 +02:00
import traceback
2022-05-26 13:49:31 +02:00
import unittest
from typing import Optional
from unittest import TestResult
2022-05-26 13:49:31 +02:00
2022-06-03 23:35:07 +02:00
from unittests_cli.add_test_case import AddTestCase
2022-06-23 21:49:44 +02:00
from unittests_cli.build_test_case import BuildTestCase
2022-05-26 15:29:49 +02:00
from unittests_cli.constants import PLAYGROUND_PATH
2022-05-26 13:49:31 +02:00
from unittests_cli.generate_test_case import GenerateTestCase
2022-06-21 08:56:26 +02:00
from unittests_cli.install_test_case import InstallTestCase
2022-05-26 13:49:31 +02:00
from unittests_cli.new_test_case import NewTestCase
2022-06-23 23:47:29 +02:00
from unittests_cli.publish_test_case import PublishTestCase
2022-06-03 23:44:26 +02:00
from unittests_cli.remove_test_case import RemoveTestCase
2022-06-26 00:15:05 +02:00
from unittests_cli.run_test_case import RunTestCase
2022-06-26 00:39:16 +02:00
from unittests_cli.start_test_case import StartTestCase
2022-06-21 09:24:56 +02:00
from unittests_cli.uninstall_test_case import UninstallTestCase
2022-06-23 21:49:44 +02:00
from unittests_cli.update_test_case import UpdateTestCase
2022-06-26 19:51:18 +02:00
from unittests_cli.version_test_case import VersionTestCase
2022-05-26 13:49:31 +02:00
class CLITestSuite(unittest.TestSuite):
def __init__(self):
unittest.TestSuite.__init__(self)
loader = unittest.TestLoader()
self._result: Optional[TestResult] = None
2022-06-26 01:07:10 +02:00
self._is_online = True
2022-06-21 09:24:56 +02:00
2022-06-23 21:49:44 +02:00
active_tests = [
2022-06-27 09:10:21 +02:00
# nothing needed
2022-06-26 19:51:18 +02:00
VersionTestCase,
2022-06-26 01:07:10 +02:00
NewTestCase,
GenerateTestCase,
2022-06-27 09:10:21 +02:00
# project needed
2022-06-26 01:07:10 +02:00
BuildTestCase,
PublishTestCase,
RunTestCase,
2022-06-26 00:39:16 +02:00
StartTestCase,
2022-06-23 21:49:44 +02:00
# workspace needed
2022-06-26 01:07:10 +02:00
AddTestCase,
RemoveTestCase
2022-06-23 21:49:44 +02:00
]
2022-05-26 13:59:46 +02:00
2022-06-26 00:15:05 +02:00
if self._is_online:
active_tests.append(InstallTestCase)
active_tests.append(UninstallTestCase)
2022-06-27 09:10:21 +02:00
active_tests.append(UpdateTestCase)
2022-06-26 00:15:05 +02:00
2022-06-23 21:49:44 +02:00
for test in active_tests:
self.addTests(loader.loadTestsFromTestCase(test))
2022-05-26 13:59:46 +02:00
def _setup(self):
try:
2022-05-26 15:29:49 +02:00
if os.path.exists(PLAYGROUND_PATH):
2022-05-26 21:42:43 +02:00
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
2022-05-26 13:59:46 +02:00
2022-05-26 15:49:52 +02:00
os.makedirs(PLAYGROUND_PATH)
2022-05-26 15:29:49 +02:00
os.chdir(PLAYGROUND_PATH)
2022-05-26 13:59:46 +02:00
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
2022-05-26 15:29:49 +02:00
if os.path.exists(PLAYGROUND_PATH):
2022-05-26 21:42:43 +02:00
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
2022-05-26 13:59:46 +02:00
except Exception as e:
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')
2022-05-26 14:47:36 +02:00
def run(self, *args):
self._setup()
self._result = super().run(*args)
# self._cleanup()