Added tests for generate command

This commit is contained in:
2022-05-26 14:47:36 +02:00
parent 46cceb0910
commit d937c4c0e6
10 changed files with 89 additions and 25 deletions

View File

@@ -1,9 +1,11 @@
import os
import shutil
import traceback
import unittest
from unittests_cli.add_test_case import AddTestCase
from unittests_cli.build_test_case import BuildTestCase
from unittests_cli.constants import PLAYGROUND
from unittests_cli.generate_test_case import GenerateTestCase
from unittests_cli.install_test_case import InstallTestCase
from unittests_cli.new_test_case import NewTestCase
@@ -21,8 +23,6 @@ class CLITestSuite(unittest.TestSuite):
def __init__(self):
unittest.TestSuite.__init__(self)
self._setup()
loader = unittest.TestLoader()
# nothing needed
self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
@@ -42,23 +42,26 @@ class CLITestSuite(unittest.TestSuite):
self.addTests(loader.loadTestsFromTestCase(AddTestCase))
self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
self._cleanup()
def _setup(self):
print(f'Setup {__name__}')
try:
playground = os.path.abspath(os.path.join(os.getcwd(), 'test_cli_playground'))
if os.path.exists(playground):
os.rmdir(playground)
if os.path.exists(PLAYGROUND):
shutil.rmtree(PLAYGROUND)
os.mkdir(playground)
os.chdir(playground)
os.mkdir(PLAYGROUND)
os.chdir(PLAYGROUND)
except Exception as e:
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
def _cleanup(self):
print(f'Cleanup {__name__}')
try:
playground = os.path.abspath(os.path.join(os.getcwd(), 'test_cli_playground'))
if os.path.exists(playground):
os.rmdir(playground)
if os.path.exists(PLAYGROUND):
shutil.rmtree(PLAYGROUND)
except Exception as e:
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')
def run(self, *args):
self._setup()
super().run(*args)
self._cleanup()

View File

@@ -0,0 +1,3 @@
import os
PLAYGROUND = os.path.abspath(os.path.join(os.getcwd(), '../generated/test_cli_playground'))

View File

@@ -1,10 +1,45 @@
import os.path
import unittest
from unittests_cli.constants import PLAYGROUND
from unittests_shared.cli_commands import CLICommands
class GenerateTestCase(unittest.TestCase):
def setUp(self):
pass
def test_equal(self):
pass
def _test_file(self, schematic: str, suffix: str):
CLICommands.generate(schematic, 'GeneratedFile')
file_path = os.path.abspath(os.path.join(PLAYGROUND, f'generated_file{suffix}.py'))
file_exists = os.path.exists(file_path)
self.assertTrue(file_exists)
os.remove(file_path)
def test_abc(self):
self._test_file('abc', '_abc')
def test_class(self):
self._test_file('class', '')
def test_enum(self):
self._test_file('enum', '_enum')
def test_pipe(self):
self._test_file('pipe', '_pipe')
def test_service(self):
self._test_file('service', '_service')
def test_settings(self):
self._test_file('settings', '_settings')
def test_test_case(self):
self._test_file('test_case', '_test_case')
def test_thread(self):
self._test_file('thread', '_thread')
def test_validator(self):
self._test_file('validator', '_validator')

View File

@@ -28,8 +28,8 @@
"ProjectType": "library",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "tests/unittest_cli.main",
"EntryPoint": "tests/unittest_cli",
"Main": "unittest_cli.main",
"EntryPoint": "unittest_cli",
"IncludePackageData": false,
"Included": [],
"Excluded": [