sh_cpl/unittests/unittests_cli/cli_test_suite.py

80 lines
2.6 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-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 00:39:16 +02:00
self._is_online = False
2022-06-21 09:24:56 +02:00
2022-06-23 21:49:44 +02:00
active_tests = [
# nothing needed
2022-06-26 00:41:25 +02:00
GenerateTestCase,
NewTestCase,
2022-06-23 21:49:44 +02:00
# compare console output
# VersionTestCase,
# project needed
2022-06-26 00:41:25 +02:00
BuildTestCase,
PublishTestCase,
RunTestCase,
2022-06-26 00:39:16 +02:00
StartTestCase,
2022-06-23 21:49:44 +02:00
# check in project settings if package is updated
# UpdateTestCase,
# workspace needed
2022-06-26 00:41:25 +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-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)
2022-05-26 14:47:36 +02:00
self._cleanup()