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
|
2022-05-26 22:21:16 +02:00
|
|
|
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-03 23:44:26 +02:00
|
|
|
from unittests_cli.remove_test_case import RemoveTestCase
|
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()
|
2022-05-26 22:21:16 +02:00
|
|
|
self._result: Optional[TestResult] = None
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
active_tests = [
|
|
|
|
# nothing needed
|
|
|
|
GenerateTestCase,
|
|
|
|
NewTestCase,
|
2022-05-26 13:59:46 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
# compare console output
|
|
|
|
# VersionTestCase,
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
# project needed
|
|
|
|
# compare two file states/directory content
|
|
|
|
BuildTestCase,
|
|
|
|
InstallTestCase,
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
# compare two file states/directory content
|
|
|
|
# PublishTestCase,
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
# check if application was executed properly
|
|
|
|
# RunTestCase,
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
# check if application was executed properly and file watcher is working
|
|
|
|
# StartTestCase,
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
UninstallTestCase,
|
|
|
|
# check in project settings if package is updated
|
|
|
|
# UpdateTestCase,
|
2022-06-21 09:24:56 +02:00
|
|
|
|
2022-06-23 21:49:44 +02:00
|
|
|
# workspace needed
|
|
|
|
AddTestCase,
|
|
|
|
RemoveTestCase
|
|
|
|
]
|
2022-05-26 13:59:46 +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:
|
2022-05-26 22:21:16 +02:00
|
|
|
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()
|
2022-05-26 22:21:16 +02:00
|
|
|
self._result = super().run(*args)
|
2022-05-26 14:47:36 +02:00
|
|
|
self._cleanup()
|