sh_cpl/unittests/unittests_cli/abc/command_test_case.py

41 lines
1.1 KiB
Python
Raw Normal View History

2022-12-01 23:23:48 +01:00
import os
import shutil
import traceback
import unittest
from unittests_cli.constants import PLAYGROUND_PATH
class CommandTestCase(unittest.TestCase):
2022-12-06 17:42:55 +01:00
_skip_tear_down = False
2023-04-10 15:10:39 +02:00
_cwd = os.getcwd()
2022-12-01 23:23:48 +01:00
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)))
2022-12-06 17:42:55 +01:00
if not os.path.exists(PLAYGROUND_PATH):
os.makedirs(PLAYGROUND_PATH)
2022-12-01 23:23:48 +01:00
os.chdir(PLAYGROUND_PATH)
except Exception as e:
2023-02-20 15:55:20 +01:00
print(f"Setup of {__name__} failed: {traceback.format_exc()}")
2022-12-01 23:23:48 +01:00
def setUp(self):
os.chdir(PLAYGROUND_PATH)
@classmethod
def tearDownClass(cls):
2022-12-06 17:42:55 +01:00
if cls._skip_tear_down:
return
2022-12-01 23:23:48 +01:00
try:
2023-04-10 15:10:39 +02:00
os.chdir(cls._cwd)
2022-12-01 23:23:48 +01:00
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
except Exception as e:
2023-02-20 15:55:20 +01:00
print(f"Cleanup of {__name__} failed: {traceback.format_exc()}")