2022.12 #133

Merged
edraft merged 85 commits from 2022.12 into master 2022-12-25 11:58:35 +01:00
3 changed files with 71 additions and 11 deletions
Showing only changes of commit d0877a4ea6 - Show all commits

View File

@ -13,6 +13,7 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.console.console import Console
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
from cpl_core.utils import String
class RunService(CommandABC):
@ -87,7 +88,16 @@ class RunService(CommandABC):
def _build(self):
if self._is_dev:
return
self._env.set_working_directory(self._src_dir)
self._publisher.build()
self._src_dir = os.path.abspath(os.path.join(
self._src_dir,
self._build_settings.output_path,
self._project_settings.name,
'build',
String.convert_to_snake_case(self._project_settings.name)
))
def execute(self, args: list[str]):
"""

View File

@ -15,10 +15,10 @@ class RunTestCase(CommandTestCase):
CommandTestCase.__init__(self, method_name)
self._source = 'run-test'
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
self._appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
self._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
self._test_code = f"""
import json
import os
settings = dict()
with open('appsettings.json', 'r', encoding='utf-8') as cfg:
# load json
@ -26,14 +26,19 @@ class RunTestCase(CommandTestCase):
cfg.close()
settings['RunTest']['WasStarted'] = 'True'
settings['RunTest']['Path'] = os.path.dirname(os.path.realpath(__file__))
with open('appsettings.json', 'w', encoding='utf-8') as project_file:
project_file.write(json.dumps(settings, indent=2))
project_file.close()
"""
def _get_appsettings(self):
with open(os.path.join(os.getcwd(), self._appsettings), 'r', encoding='utf-8') as cfg:
def _get_appsettings(self, is_dev=False):
appsettings = f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json'
if is_dev:
appsettings = f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'
with open(os.path.join(os.getcwd(), appsettings), 'r', encoding='utf-8') as cfg:
# load json
project_json = json.load(cfg)
cfg.close()
@ -41,7 +46,7 @@ class RunTestCase(CommandTestCase):
return project_json
def _save_appsettings(self, settings: dict):
with open(os.path.join(os.getcwd(), self._appsettings), 'w', encoding='utf-8') as project_file:
with open(os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}/appsettings.json'), 'w', encoding='utf-8') as project_file:
project_file.write(json.dumps(settings, indent=2))
project_file.close()
@ -57,7 +62,7 @@ class RunTestCase(CommandTestCase):
file.close()
def test_run(self):
CLICommands.run(is_dev=True, output=True)
CLICommands.run()
settings = self._get_appsettings()
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
@ -66,10 +71,17 @@ class RunTestCase(CommandTestCase):
'True',
settings['RunTest']['WasStarted']
)
self.assertNotEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
self.assertEqual(
os.path.join(os.getcwd(), f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
def test_run_by_project(self):
os.chdir(os.path.join(os.getcwd()))
CLICommands.run(self._source, is_dev=True)
CLICommands.run(self._source)
settings = self._get_appsettings()
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
@ -78,3 +90,41 @@ class RunTestCase(CommandTestCase):
'True',
settings['RunTest']['WasStarted']
)
self.assertNotEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
self.assertEqual(
os.path.join(os.getcwd(), f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
def test_run_dev(self):
CLICommands.run(is_dev=True)
settings = self._get_appsettings(is_dev=True)
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
self.assertIn('WasStarted', settings['RunTest'])
self.assertEqual(
'True',
settings['RunTest']['WasStarted']
)
self.assertEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)
def test_run_dev_by_project(self):
CLICommands.run(self._source, is_dev=True)
settings = self._get_appsettings(is_dev=True)
self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings)
self.assertIn('WasStarted', settings['RunTest'])
self.assertEqual(
'True',
settings['RunTest']['WasStarted']
)
self.assertEqual(
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
settings['RunTest']['Path']
)

View File

@ -66,14 +66,14 @@ class CLICommands:
@classmethod
def run(cls, project: str = None, is_dev=False, output=False):
dev = ''
args = []
if is_dev:
dev = '--dev'
args.append('--dev')
if project is None:
cls._run('run', dev, output=output)
cls._run('run', *args, output=output)
return
cls._run('run', project, dev, output=output)
cls._run('run', project, *args, output=output)
@classmethod
def start(cls, output=False):