2022.6.17 - Unittests #84

Merged
edraft merged 51 commits from 2022.6.17 into 2022.6 2022-06-27 10:03:55 +02:00
5 changed files with 52 additions and 21 deletions
Showing only changes of commit ce0ad4013f - Show all commits

View File

@ -25,27 +25,27 @@ class CLITestSuite(unittest.TestSuite):
loader = unittest.TestLoader()
# nothing needed
self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
# self.addTests(loader.loadTestsFromTestCase(GenerateTestCase))
self.addTests(loader.loadTestsFromTestCase(NewTestCase))
self.addTests(loader.loadTestsFromTestCase(VersionTestCase))
# self.addTests(loader.loadTestsFromTestCase(VersionTestCase))
# project needed
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))
# 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))
# workspace needed
self.addTests(loader.loadTestsFromTestCase(AddTestCase))
self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
# self.addTests(loader.loadTestsFromTestCase(AddTestCase))
# self.addTests(loader.loadTestsFromTestCase(RemoveTestCase))
def _setup(self):
try:
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, '../')))
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH)
@ -55,7 +55,7 @@ class CLITestSuite(unittest.TestSuite):
def _cleanup(self):
try:
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH, '../')))
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
except Exception as e:
print(f'Cleanup of {__name__} failed: {traceback.format_exc()}')

View File

@ -1,4 +1,4 @@
import os
PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), '../generated/test_cli_playground'))
PLAYGROUND_PATH = os.path.abspath(os.path.join(os.getcwd(), '../test_cli_playground'))
CLI_PATH = os.path.abspath(os.path.join(os.getcwd(), '../../src/cpl_cli/main.py'))

View File

@ -15,28 +15,37 @@ class GenerateTestCase(unittest.TestCase):
os.remove(file_path)
def test_abc(self):
print(f'{__name__} generate abc')
self._test_file('abc', '_abc')
def test_class(self):
print(f'{__name__} generate class')
self._test_file('class', '')
def test_enum(self):
print(f'{__name__} generate enum')
self._test_file('enum', '_enum')
def test_pipe(self):
print(f'{__name__} generate pipe')
self._test_file('pipe', '_pipe')
def test_service(self):
print(f'{__name__} generate service')
self._test_file('service', '_service')
def test_settings(self):
print(f'{__name__} generate settings')
self._test_file('settings', '_settings')
def test_test_case(self):
print(f'{__name__} generate test_case')
self._test_file('test_case', '_test_case')
def test_thread(self):
print(f'{__name__} generate thread')
self._test_file('thread', '_thread')
def test_validator(self):
print(f'{__name__} generate validator')
self._test_file('validator', '_validator')

View File

@ -1,10 +1,32 @@
import os
import shutil
import unittest
from cpl_core.utils import String
from unittests_cli.constants import PLAYGROUND_PATH
from unittests_shared.cli_commands import CLICommands
class NewTestCase(unittest.TestCase):
def setUp(self):
pass
def test_equal(self):
pass
def _test_project(self, project_type: str, name: str, *args):
CLICommands.new(project_type, name, *args)
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, String.convert_to_snake_case(name)))
self.assertTrue(os.path.exists(project_path))
shutil.rmtree(project_path)
def test_console(self):
print(f'{__name__} new console')
self._test_project('console', 'test-console', '--ab', '--s', '--sp')
def test_library(self):
print(f'{__name__} new library')
self._test_project('library', 'test-library', '--ab', '--s', '--sp')
def test_unittest(self):
print(f'{__name__} new unittests')
self._test_project('unittest', 'test-unittest', '--ab', '--s', '--sp')

View File

@ -9,7 +9,7 @@ class CLICommands:
@staticmethod
def _run(cmd: str, *args):
env_vars = os.environ
env_vars['CPL_IS_UNITTEST'] = 'YES'
# env_vars['CPL_IS_UNITTEST'] = 'YES'
command = ['python', CLI_PATH, cmd]
for arg in args:
command.append(arg)
@ -17,9 +17,9 @@ class CLICommands:
subprocess.run(command, env=env_vars)
@classmethod
def generate(cls, *args):
cls._run('generate', *args)
def generate(cls, schematic: str, name: str):
cls._run('generate', schematic, name)
@classmethod
def new(cls, *args):
cls._run('new', *args)
def new(cls, project_type: str, name: str, *args):
cls._run('new', project_type, name, *args)