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
2 changed files with 24 additions and 21 deletions
Showing only changes of commit e5dd890931 - Show all commits

View File

@ -44,6 +44,7 @@ class NewService(CommandABC):
self._project_json = {} self._project_json = {}
self._name: str = '' self._name: str = ''
self._rel_path: str = ''
self._schematic: ProjectTypeEnum = ProjectTypeEnum.console self._schematic: ProjectTypeEnum = ProjectTypeEnum.console
self._use_nothing: bool = False self._use_nothing: bool = False
self._use_application_api: bool = False self._use_application_api: bool = False
@ -83,9 +84,10 @@ class NewService(CommandABC):
for name in schematics: for name in schematics:
Console.write(f'\n\t{name} ') Console.write(f'\n\t{name} ')
def _create_project_settings(self, name: str): def _create_project_settings(self):
self._rel_path = os.path.dirname(self._name)
self._project_dict = { self._project_dict = {
ProjectSettingsNameEnum.name.value: name, ProjectSettingsNameEnum.name.value: os.path.basename(self._name),
ProjectSettingsNameEnum.version.value: { ProjectSettingsNameEnum.version.value: {
VersionSettingsNameEnum.major.value: '0', VersionSettingsNameEnum.major.value: '0',
VersionSettingsNameEnum.minor.value: '0', VersionSettingsNameEnum.minor.value: '0',
@ -113,15 +115,11 @@ class NewService(CommandABC):
self._project.from_dict(self._project_dict) self._project.from_dict(self._project_dict)
def _create_build_settings(self): def _create_build_settings(self):
main = f'{String.convert_to_snake_case(self._project.name)}.main'
if self._schematic == ProjectTypeEnum.library.value:
main = f'{String.convert_to_snake_case(self._project.name)}.main'
self._build_dict = { self._build_dict = {
BuildSettingsNameEnum.project_type.value: self._schematic, BuildSettingsNameEnum.project_type.value: self._schematic,
BuildSettingsNameEnum.source_path.value: '', BuildSettingsNameEnum.source_path.value: '',
BuildSettingsNameEnum.output_path.value: '../../dist', BuildSettingsNameEnum.output_path.value: '../../dist',
BuildSettingsNameEnum.main.value: main, BuildSettingsNameEnum.main.value: f'{String.convert_to_snake_case(self._project.name)}.main',
BuildSettingsNameEnum.entry_point.value: self._project.name, BuildSettingsNameEnum.entry_point.value: self._project.name,
BuildSettingsNameEnum.include_package_data.value: False, BuildSettingsNameEnum.include_package_data.value: False,
BuildSettingsNameEnum.included.value: [], BuildSettingsNameEnum.included.value: [],
@ -151,15 +149,12 @@ class NewService(CommandABC):
:return: :return:
""" """
if self._workspace is None: if self._workspace is None:
project_path = os.path.join(self._env.working_directory, self._project.name) project_path = os.path.join(self._env.working_directory, self._rel_path, self._project.name)
else: else:
project_path = os.path.join( project_path = os.path.join(self._env.working_directory, 'src', self._rel_path, String.convert_to_snake_case(self._project.name))
self._env.working_directory,
'src',
String.convert_to_snake_case(self._project.name)
)
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0: if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
Console.write_line(project_path)
Console.error('Project path is not empty\n') Console.error('Project path is not empty\n')
return None return None
@ -195,7 +190,7 @@ class NewService(CommandABC):
:param args: :param args:
:return: :return:
""" """
self._create_project_settings(self._name) self._create_project_settings()
self._create_build_settings() self._create_build_settings()
self._create_project_json() self._create_project_json()
path = self._get_project_path() path = self._get_project_path()
@ -203,6 +198,9 @@ class NewService(CommandABC):
return return
self._get_project_information() self._get_project_information()
project_name = self._project.name
if self._rel_path != '':
project_name = f'{self._rel_path}/{project_name}'
try: try:
ConsoleBuilder.build( ConsoleBuilder.build(
path, path,
@ -210,7 +208,7 @@ class NewService(CommandABC):
self._use_startup, self._use_startup,
self._use_service_providing, self._use_service_providing,
self._use_async, self._use_async,
self._project.name, project_name,
self._project_json, self._project_json,
self._workspace self._workspace
) )
@ -223,7 +221,7 @@ class NewService(CommandABC):
:param args: :param args:
:return: :return:
""" """
self._create_project_settings(self._name) self._create_project_settings()
self._create_build_settings() self._create_build_settings()
self._create_project_json() self._create_project_json()
path = self._get_project_path() path = self._get_project_path()
@ -231,12 +229,15 @@ class NewService(CommandABC):
return return
self._get_project_information(is_unittest=True) self._get_project_information(is_unittest=True)
project_name = self._project.name
if self._rel_path != '':
project_name = f'{self._rel_path}/{project_name}'
try: try:
UnittestBuilder.build( UnittestBuilder.build(
path, path,
self._use_application_api, self._use_application_api,
self._use_async, self._use_async,
self._project.name, project_name,
self._project_json, self._project_json,
self._workspace self._workspace
) )
@ -249,7 +250,7 @@ class NewService(CommandABC):
:param args: :param args:
:return: :return:
""" """
self._create_project_settings(self._name) self._create_project_settings()
self._create_build_settings() self._create_build_settings()
self._create_project_json() self._create_project_json()
path = self._get_project_path() path = self._get_project_path()
@ -257,6 +258,9 @@ class NewService(CommandABC):
return return
self._get_project_information() self._get_project_information()
project_name = self._project.name
if self._rel_path != '':
project_name = f'{self._rel_path}/{project_name}'
try: try:
LibraryBuilder.build( LibraryBuilder.build(
path, path,
@ -264,7 +268,7 @@ class NewService(CommandABC):
self._use_startup, self._use_startup,
self._use_service_providing, self._use_service_providing,
self._use_async, self._use_async,
self._project.name, project_name,
self._project_json, self._project_json,
self._workspace self._workspace
) )

View File

@ -60,8 +60,7 @@ class NewTestCase(unittest.TestCase):
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, f'src/{directory}', String.convert_to_snake_case(name))) project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, f'src/{directory}', String.convert_to_snake_case(name)))
self.assertTrue(os.path.exists(project_path)) self.assertTrue(os.path.exists(project_path))
project_file = os.path.join(project_path, f'{name}.json') project_file = os.path.join(project_path, f'{name}.json')
self.assertTrue(project_file) self.assertTrue(os.path.exists(project_file))
project_json = {}
with open(project_file, 'r', encoding='utf-8') as cfg: with open(project_file, 'r', encoding='utf-8') as cfg:
# load json # load json
project_json = json.load(cfg) project_json = json.load(cfg)