Added tests for generate command
This commit is contained in:
parent
46cceb0910
commit
d937c4c0e6
@ -1,5 +1,5 @@
|
|||||||
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
from unittest import TestSuite
|
|
||||||
|
|
||||||
from cpl_core.application import ApplicationABC
|
from cpl_core.application import ApplicationABC
|
||||||
from cpl_core.configuration import ConfigurationABC
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
"ProjectType": "unittest",
|
"ProjectType": "unittest",
|
||||||
"SourcePath": "",
|
"SourcePath": "",
|
||||||
"OutputPath": "../../dist",
|
"OutputPath": "../../dist",
|
||||||
"Main": "tests/unittest.main",
|
"Main": "unittest.main",
|
||||||
"EntryPoint": "tests/unittest",
|
"EntryPoint": "unittest",
|
||||||
"IncludePackageData": false,
|
"IncludePackageData": false,
|
||||||
"Included": [],
|
"Included": [],
|
||||||
"Excluded": [
|
"Excluded": [
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import traceback
|
import traceback
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from unittests_cli.add_test_case import AddTestCase
|
from unittests_cli.add_test_case import AddTestCase
|
||||||
from unittests_cli.build_test_case import BuildTestCase
|
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.generate_test_case import GenerateTestCase
|
||||||
from unittests_cli.install_test_case import InstallTestCase
|
from unittests_cli.install_test_case import InstallTestCase
|
||||||
from unittests_cli.new_test_case import NewTestCase
|
from unittests_cli.new_test_case import NewTestCase
|
||||||
@ -21,8 +23,6 @@ class CLITestSuite(unittest.TestSuite):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
unittest.TestSuite.__init__(self)
|
unittest.TestSuite.__init__(self)
|
||||||
|
|
||||||
self._setup()
|
|
||||||
|
|
||||||
loader = unittest.TestLoader()
|
loader = unittest.TestLoader()
|
||||||
# nothing needed
|
# nothing needed
|
||||||
self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
|
self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
|
||||||
@ -42,23 +42,26 @@ class CLITestSuite(unittest.TestSuite):
|
|||||||
self.addTests(loader.loadTestsFromTestCase(AddTestCase))
|
self.addTests(loader.loadTestsFromTestCase(AddTestCase))
|
||||||
self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
|
self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
|
||||||
|
|
||||||
self._cleanup()
|
|
||||||
|
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
|
print(f'Setup {__name__}')
|
||||||
try:
|
try:
|
||||||
playground = os.path.abspath(os.path.join(os.getcwd(), 'test_cli_playground'))
|
if os.path.exists(PLAYGROUND):
|
||||||
if os.path.exists(playground):
|
shutil.rmtree(PLAYGROUND)
|
||||||
os.rmdir(playground)
|
|
||||||
|
|
||||||
os.mkdir(playground)
|
os.mkdir(PLAYGROUND)
|
||||||
os.chdir(playground)
|
os.chdir(PLAYGROUND)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
|
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
|
||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self):
|
||||||
|
print(f'Cleanup {__name__}')
|
||||||
try:
|
try:
|
||||||
playground = os.path.abspath(os.path.join(os.getcwd(), 'test_cli_playground'))
|
if os.path.exists(PLAYGROUND):
|
||||||
if os.path.exists(playground):
|
shutil.rmtree(PLAYGROUND)
|
||||||
os.rmdir(playground)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')
|
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')
|
||||||
|
|
||||||
|
def run(self, *args):
|
||||||
|
self._setup()
|
||||||
|
super().run(*args)
|
||||||
|
self._cleanup()
|
||||||
|
3
src/tests/unittests_cli/constants.py
Normal file
3
src/tests/unittests_cli/constants.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
PLAYGROUND = os.path.abspath(os.path.join(os.getcwd(), '../generated/test_cli_playground'))
|
@ -1,10 +1,45 @@
|
|||||||
|
import os.path
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from unittests_cli.constants import PLAYGROUND
|
||||||
|
from unittests_shared.cli_commands import CLICommands
|
||||||
|
|
||||||
|
|
||||||
class GenerateTestCase(unittest.TestCase):
|
class GenerateTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_equal(self):
|
def _test_file(self, schematic: str, suffix: str):
|
||||||
pass
|
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')
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
"ProjectType": "library",
|
"ProjectType": "library",
|
||||||
"SourcePath": "",
|
"SourcePath": "",
|
||||||
"OutputPath": "../../dist",
|
"OutputPath": "../../dist",
|
||||||
"Main": "tests/unittest_cli.main",
|
"Main": "unittest_cli.main",
|
||||||
"EntryPoint": "tests/unittest_cli",
|
"EntryPoint": "unittest_cli",
|
||||||
"IncludePackageData": false,
|
"IncludePackageData": false,
|
||||||
"Included": [],
|
"Included": [],
|
||||||
"Excluded": [
|
"Excluded": [
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
"ProjectType": "library",
|
"ProjectType": "library",
|
||||||
"SourcePath": "",
|
"SourcePath": "",
|
||||||
"OutputPath": "../../dist",
|
"OutputPath": "../../dist",
|
||||||
"Main": "tests/unittest_core.main",
|
"Main": "unittest_core.main",
|
||||||
"EntryPoint": "tests/unittest_core",
|
"EntryPoint": "unittest_core",
|
||||||
"IncludePackageData": false,
|
"IncludePackageData": false,
|
||||||
"Included": [],
|
"Included": [],
|
||||||
"Excluded": [
|
"Excluded": [
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
"ProjectType": "library",
|
"ProjectType": "library",
|
||||||
"SourcePath": "",
|
"SourcePath": "",
|
||||||
"OutputPath": "../../dist",
|
"OutputPath": "../../dist",
|
||||||
"Main": "tests/unittest_query.main",
|
"Main": "unittest_query.main",
|
||||||
"EntryPoint": "tests/unittest_query",
|
"EntryPoint": "unittest_query",
|
||||||
"IncludePackageData": false,
|
"IncludePackageData": false,
|
||||||
"Included": [],
|
"Included": [],
|
||||||
"Excluded": [
|
"Excluded": [
|
||||||
|
23
src/tests/unittests_shared/cli_commands.py
Normal file
23
src/tests/unittests_shared/cli_commands.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
class CLICommands:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _run(cmd: str, *args):
|
||||||
|
env_vars = os.environ
|
||||||
|
command = ['python', os.path.abspath(os.path.join(os.getcwd(), '../../../cpl_cli/main.py')), cmd]
|
||||||
|
for arg in args:
|
||||||
|
command.append(arg)
|
||||||
|
|
||||||
|
print(f'Running {command}')
|
||||||
|
subprocess.run(command, env=env_vars)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def generate(cls, *args):
|
||||||
|
cls._run('generate', *args)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def new(cls, *args):
|
||||||
|
cls._run('new', *args)
|
@ -28,8 +28,8 @@
|
|||||||
"ProjectType": "library",
|
"ProjectType": "library",
|
||||||
"SourcePath": "",
|
"SourcePath": "",
|
||||||
"OutputPath": "../../dist",
|
"OutputPath": "../../dist",
|
||||||
"Main": "tests/unittest_shared.main",
|
"Main": "unittest_shared.main",
|
||||||
"EntryPoint": "tests/unittest_shared",
|
"EntryPoint": "unittest_shared",
|
||||||
"IncludePackageData": false,
|
"IncludePackageData": false,
|
||||||
"Included": [],
|
"Included": [],
|
||||||
"Excluded": [
|
"Excluded": [
|
||||||
|
Loading…
Reference in New Issue
Block a user