2022-05-26 21:42:43 +02:00
|
|
|
import os
|
|
|
|
import shutil
|
2022-05-26 13:49:31 +02:00
|
|
|
import unittest
|
|
|
|
|
2022-05-26 21:42:43 +02:00
|
|
|
from cpl_core.utils import String
|
|
|
|
|
|
|
|
from unittests_cli.constants import PLAYGROUND_PATH
|
|
|
|
from unittests_shared.cli_commands import CLICommands
|
|
|
|
|
2022-05-26 13:49:31 +02:00
|
|
|
|
|
|
|
class NewTestCase(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
2022-05-26 22:21:16 +02:00
|
|
|
os.chdir(os.path.abspath(PLAYGROUND_PATH))
|
2022-05-26 13:49:31 +02:00
|
|
|
|
2022-05-26 21:42:43 +02:00
|
|
|
def _test_project(self, project_type: str, name: str, *args):
|
|
|
|
CLICommands.new(project_type, name, *args)
|
2022-05-26 22:21:16 +02:00
|
|
|
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name))
|
|
|
|
self.assertTrue(os.path.exists(workspace_path))
|
|
|
|
|
|
|
|
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name, 'src', String.convert_to_snake_case(name)))
|
|
|
|
self.assertTrue(os.path.exists(project_path))
|
|
|
|
self.assertTrue(os.path.join(project_path, f'{name}.json'))
|
2022-05-26 22:24:19 +02:00
|
|
|
self.assertTrue(os.path.join(project_path, f'main.py'))
|
2022-05-26 23:01:50 +02:00
|
|
|
|
|
|
|
if '--ab' in args:
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(project_path, f'application.py')))
|
|
|
|
else:
|
|
|
|
self.assertFalse(os.path.isfile(os.path.join(project_path, f'application.py')))
|
|
|
|
|
|
|
|
if '--sp' in args:
|
|
|
|
self.assertTrue(os.path.isfile(os.path.join(project_path, f'startup.py')))
|
|
|
|
else:
|
|
|
|
self.assertFalse(os.path.isfile(os.path.join(project_path, f'startup.py')))
|
|
|
|
|
2022-05-26 22:24:19 +02:00
|
|
|
if project_type == 'unittest':
|
2022-05-26 23:01:50 +02:00
|
|
|
self.assertTrue(os.path.isfile(os.path.join(project_path, f'test_case.py')))
|
|
|
|
else:
|
|
|
|
self.assertFalse(os.path.isfile(os.path.join(project_path, f'test_case.py')))
|
2022-05-26 22:21:16 +02:00
|
|
|
|
|
|
|
def _test_sub_project(self, project_type: str, name: str, workspace_name: str, *args):
|
|
|
|
os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name)))
|
|
|
|
CLICommands.new(project_type, name, *args)
|
|
|
|
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name))
|
|
|
|
self.assertTrue(os.path.exists(workspace_path))
|
|
|
|
|
|
|
|
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, 'src', String.convert_to_snake_case(name)))
|
2022-05-26 21:42:43 +02:00
|
|
|
self.assertTrue(os.path.exists(project_path))
|
2022-05-26 22:21:16 +02:00
|
|
|
self.assertTrue(os.path.join(project_path, f'{name}.json'))
|
|
|
|
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
|
2022-05-26 21:42:43 +02:00
|
|
|
|
|
|
|
def test_console(self):
|
|
|
|
self._test_project('console', 'test-console', '--ab', '--s', '--sp')
|
|
|
|
|
2022-05-26 23:01:50 +02:00
|
|
|
def test_console_without_sp(self):
|
|
|
|
self._test_project('console', 'test-console-without-sp', '--ab', '--s')
|
|
|
|
|
|
|
|
def test_console_without_s(self):
|
|
|
|
self._test_project('console', 'test-console-without-s', '--ab')
|
|
|
|
|
|
|
|
def test_console_without_ab(self):
|
|
|
|
self._test_project('console', 'test-console-without-ab', '--sp')
|
|
|
|
|
2022-05-26 22:21:16 +02:00
|
|
|
def test_sub_console(self):
|
|
|
|
self._test_sub_project('console', 'test-sub-console', 'test-console', '--ab', '--s', '--sp')
|
|
|
|
|
2022-05-26 21:42:43 +02:00
|
|
|
def test_library(self):
|
|
|
|
self._test_project('library', 'test-library', '--ab', '--s', '--sp')
|
|
|
|
|
2022-05-26 22:21:16 +02:00
|
|
|
def test_sub_library(self):
|
|
|
|
self._test_sub_project('library', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
|
|
|
|
|
2022-05-26 21:42:43 +02:00
|
|
|
def test_unittest(self):
|
2022-05-26 23:01:50 +02:00
|
|
|
self._test_project('unittest', 'test-unittest', '--ab')
|
2022-05-26 22:21:16 +02:00
|
|
|
|
|
|
|
def test_sub_unittest(self):
|
|
|
|
self._test_sub_project('unittest', 'test-unittest', 'test-console', '--ab', '--s', '--sp')
|