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-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
|
|
|
|
from unittests_cli.new_test_case import NewTestCase
|
|
|
|
|
|
|
|
|
|
|
|
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-05-26 13:59:46 +02:00
|
|
|
# nothing needed
|
2022-05-26 22:21:16 +02:00
|
|
|
self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
|
2022-05-26 13:49:31 +02:00
|
|
|
self.addTests(loader.loadTestsFromTestCase(NewTestCase))
|
2022-05-26 21:42:43 +02:00
|
|
|
# self.addTests(loader.loadTestsFromTestCase(VersionTestCase))
|
2022-05-26 13:59:46 +02:00
|
|
|
|
|
|
|
# project needed
|
2022-05-26 21:42:43 +02:00
|
|
|
# self.addTests(loader.loadTestsFromTestCase(BuildTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(InstallTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(PublishTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(RunTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(StartTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(UninstallTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(UpdateTestCase))
|
2022-05-26 13:59:46 +02:00
|
|
|
|
|
|
|
# workspace needed
|
2022-05-26 21:42:43 +02:00
|
|
|
# self.addTests(loader.loadTestsFromTestCase(AddTestCase))
|
|
|
|
# self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
|
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()
|