Improved cpl n custom templating #139

This commit is contained in:
2022-12-06 17:42:55 +01:00
parent 5f10603fe5
commit e244535557
56 changed files with 329 additions and 2304 deletions

View File

@@ -7,6 +7,7 @@ from unittests_cli.constants import PLAYGROUND_PATH
class CommandTestCase(unittest.TestCase):
_skip_tear_down = False
def __init__(self, method_name: str):
unittest.TestCase.__init__(self, method_name)
@@ -18,7 +19,8 @@ class CommandTestCase(unittest.TestCase):
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))
os.makedirs(PLAYGROUND_PATH)
if not os.path.exists(PLAYGROUND_PATH):
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH)
except Exception as e:
print(f'Setup of {__name__} failed: {traceback.format_exc()}')
@@ -28,6 +30,8 @@ class CommandTestCase(unittest.TestCase):
@classmethod
def tearDownClass(cls):
if cls._skip_tear_down:
return
try:
if os.path.exists(PLAYGROUND_PATH):
shutil.rmtree(os.path.abspath(os.path.join(PLAYGROUND_PATH)))

View File

@@ -28,7 +28,7 @@ class AddTestCase(CommandTestCase):
# create projects
CLICommands.new('console', self._source, '--ab', '--s')
os.chdir(os.path.join(os.getcwd(), self._source))
CLICommands.new('console', self._target, '--ab', '--s')
CLICommands.new('library', self._target, '--ab', '--s')
def test_add(self):
CLICommands.add(self._source, self._target)

View File

@@ -1,5 +1,6 @@
import json
import os
import unittest
from cpl_core.utils import String
from unittests_cli.abc.command_test_case import CommandTestCase
@@ -32,8 +33,8 @@ class NewTestCase(CommandTestCase):
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, base, 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'))
self.assertTrue(os.path.join(project_path, f'main.py'))
self.assertTrue(os.path.exists(os.path.join(project_path, f'{name}.json')))
self.assertTrue(os.path.exists(os.path.join(project_path, f'main.py')))
if '--ab' in args:
self.assertTrue(os.path.isfile(os.path.join(project_path, f'application.py')))
@@ -110,23 +111,23 @@ class NewTestCase(CommandTestCase):
def test_console_without_anything(self):
self._test_project('console', 'test-console-without-anything', '--n')
def test_sub_console(self):
def test_console_sub(self):
self._test_sub_project('console', 'test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', test_venv=True)
def test_sub_console_with_other_base(self):
def test_console_sub_with_other_base(self):
self._test_sub_project('console', 'tools/test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', '--base', test_venv=True)
def test_library(self):
self._test_project('library', 'test-library', '--ab', '--s', '--sp')
def test_sub_library(self):
def test_library_sub(self):
self._test_sub_project('library', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
def test_sub_directory_library(self):
def test_library_sub_directory(self):
self._test_sub_directory_project('library', 'directory', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
def test_unittest(self):
self._test_project('unittest', 'test-unittest', '--ab')
def test_sub_unittest(self):
def test_unittest_sub(self):
self._test_sub_project('unittest', 'test-unittest', 'test-console', '--ab', '--s', '--sp')

View File

@@ -12,6 +12,7 @@ from unittests_shared.cli_commands import CLICommands
class PublishTestCase(CommandTestCase):
CommandTestCase._skip_tear_down = True
def __init__(self, method_name: str):
CommandTestCase.__init__(self, method_name)
@@ -26,6 +27,14 @@ class PublishTestCase(CommandTestCase):
return project_json
def _get_appsettings(self):
with open(os.path.join(os.getcwd(), os.path.dirname(self._project_file), 'appsettings.json'), 'r', encoding='utf-8') as cfg:
# load json
project_json = json.load(cfg)
cfg.close()
return project_json
def _save_project_settings(self, settings: dict):
with open(os.path.join(os.getcwd(), self._project_file), 'w', encoding='utf-8') as project_file:
project_file.write(json.dumps(settings, indent=2))
@@ -34,7 +43,7 @@ class PublishTestCase(CommandTestCase):
def setUp(self):
if not os.path.exists(PLAYGROUND_PATH):
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH)
# create projects
CLICommands.new('console', self._source, '--ab', '--s')
@@ -86,4 +95,8 @@ class PublishTestCase(CommandTestCase):
with open(f'{full_dist_path}/{self._source}.json', 'w') as file:
file.write(json.dumps(self._get_project_settings(), indent=2))
file.close()
with open(f'{full_dist_path}/appsettings.json', 'w') as file:
file.write(json.dumps(self._get_appsettings(), indent=2))
file.close()
self.assertTrue(self._are_dir_trees_equal(f'./src/{String.convert_to_snake_case(self._source)}', full_dist_path))