2022.12 #133
@ -13,6 +13,7 @@ from cpl_core.configuration import ConfigurationABC
|
|||||||
from cpl_core.console.console import Console
|
from cpl_core.console.console import Console
|
||||||
from cpl_core.dependency_injection import ServiceProviderABC
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||||
|
from cpl_core.utils import String
|
||||||
|
|
||||||
|
|
||||||
class RunService(CommandABC):
|
class RunService(CommandABC):
|
||||||
@ -87,7 +88,16 @@ class RunService(CommandABC):
|
|||||||
def _build(self):
|
def _build(self):
|
||||||
if self._is_dev:
|
if self._is_dev:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self._env.set_working_directory(self._src_dir)
|
||||||
self._publisher.build()
|
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]):
|
def execute(self, args: list[str]):
|
||||||
"""
|
"""
|
||||||
|
@ -15,10 +15,10 @@ class RunTestCase(CommandTestCase):
|
|||||||
CommandTestCase.__init__(self, method_name)
|
CommandTestCase.__init__(self, method_name)
|
||||||
self._source = 'run-test'
|
self._source = 'run-test'
|
||||||
self._project_file = f'src/{String.convert_to_snake_case(self._source)}/{self._source}.json'
|
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._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
|
||||||
self._test_code = f"""
|
self._test_code = f"""
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
settings = dict()
|
settings = dict()
|
||||||
with open('appsettings.json', 'r', encoding='utf-8') as cfg:
|
with open('appsettings.json', 'r', encoding='utf-8') as cfg:
|
||||||
# load json
|
# load json
|
||||||
@ -26,14 +26,19 @@ class RunTestCase(CommandTestCase):
|
|||||||
cfg.close()
|
cfg.close()
|
||||||
|
|
||||||
settings['RunTest']['WasStarted'] = 'True'
|
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:
|
with open('appsettings.json', 'w', encoding='utf-8') as project_file:
|
||||||
project_file.write(json.dumps(settings, indent=2))
|
project_file.write(json.dumps(settings, indent=2))
|
||||||
project_file.close()
|
project_file.close()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_appsettings(self):
|
def _get_appsettings(self, is_dev=False):
|
||||||
with open(os.path.join(os.getcwd(), self._appsettings), 'r', encoding='utf-8') as cfg:
|
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
|
# load json
|
||||||
project_json = json.load(cfg)
|
project_json = json.load(cfg)
|
||||||
cfg.close()
|
cfg.close()
|
||||||
@ -41,7 +46,7 @@ class RunTestCase(CommandTestCase):
|
|||||||
return project_json
|
return project_json
|
||||||
|
|
||||||
def _save_appsettings(self, settings: dict):
|
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.write(json.dumps(settings, indent=2))
|
||||||
project_file.close()
|
project_file.close()
|
||||||
|
|
||||||
@ -57,7 +62,7 @@ class RunTestCase(CommandTestCase):
|
|||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
CLICommands.run(is_dev=True, output=True)
|
CLICommands.run()
|
||||||
settings = self._get_appsettings()
|
settings = self._get_appsettings()
|
||||||
self.assertNotEqual(settings, {})
|
self.assertNotEqual(settings, {})
|
||||||
self.assertIn('RunTest', settings)
|
self.assertIn('RunTest', settings)
|
||||||
@ -66,10 +71,17 @@ class RunTestCase(CommandTestCase):
|
|||||||
'True',
|
'True',
|
||||||
settings['RunTest']['WasStarted']
|
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):
|
def test_run_by_project(self):
|
||||||
os.chdir(os.path.join(os.getcwd()))
|
CLICommands.run(self._source)
|
||||||
CLICommands.run(self._source, is_dev=True)
|
|
||||||
settings = self._get_appsettings()
|
settings = self._get_appsettings()
|
||||||
self.assertNotEqual(settings, {})
|
self.assertNotEqual(settings, {})
|
||||||
self.assertIn('RunTest', settings)
|
self.assertIn('RunTest', settings)
|
||||||
@ -78,3 +90,41 @@ class RunTestCase(CommandTestCase):
|
|||||||
'True',
|
'True',
|
||||||
settings['RunTest']['WasStarted']
|
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']
|
||||||
|
)
|
||||||
|
@ -66,14 +66,14 @@ class CLICommands:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls, project: str = None, is_dev=False, output=False):
|
def run(cls, project: str = None, is_dev=False, output=False):
|
||||||
dev = ''
|
args = []
|
||||||
if is_dev:
|
if is_dev:
|
||||||
dev = '--dev'
|
args.append('--dev')
|
||||||
|
|
||||||
if project is None:
|
if project is None:
|
||||||
cls._run('run', dev, output=output)
|
cls._run('run', *args, output=output)
|
||||||
return
|
return
|
||||||
cls._run('run', project, dev, output=output)
|
cls._run('run', project, *args, output=output)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def start(cls, output=False):
|
def start(cls, output=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user