2022.6 #88

Merged
edraft merged 158 commits from 2022.6 into master 2022-06-29 17:50:07 +02:00
2 changed files with 38 additions and 6 deletions
Showing only changes of commit ff5f9b833d - Show all commits

View File

@ -1,3 +1,4 @@
import json
import os import os
import shutil import shutil
import unittest import unittest
@ -50,6 +51,33 @@ class NewTestCase(unittest.TestCase):
self.assertTrue(os.path.join(project_path, f'{name}.json')) self.assertTrue(os.path.join(project_path, f'{name}.json'))
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../'))) os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
def _test_sub_directory_project(self, project_type: str, directory: str, name: str, workspace_name: str, *args):
os.chdir(os.path.abspath(os.path.join(os.getcwd(), workspace_name)))
CLICommands.new(project_type, f'{directory}/{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, f'src/{directory}', String.convert_to_snake_case(name)))
self.assertTrue(os.path.exists(project_path))
project_file = os.path.join(project_path, f'{name}.json')
self.assertTrue(project_file)
project_json = {}
with open(project_file, 'r', encoding='utf-8') as cfg:
# load json
project_json = json.load(cfg)
cfg.close()
project_settings = project_json['ProjectSettings']
build_settings = project_json['BuildSettings']
self.assertEqual(project_settings['Name'], name)
self.assertEqual(build_settings['ProjectType'], 'library')
self.assertEqual(build_settings['OutputPath'], '../../dist')
self.assertEqual(build_settings['Main'], f'{String.convert_to_snake_case(name)}.main')
self.assertEqual(build_settings['EntryPoint'], name)
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
def test_console(self): def test_console(self):
self._test_project('console', 'test-console', '--ab', '--s') self._test_project('console', 'test-console', '--ab', '--s')
@ -71,6 +99,9 @@ class NewTestCase(unittest.TestCase):
def test_sub_library(self): def test_sub_library(self):
self._test_sub_project('library', 'test-sub-library', 'test-console', '--ab', '--s', '--sp') self._test_sub_project('library', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
def test_sub_directory_library(self):
self._test_sub_directory_project('library', 'directory', 'test-sub-library', 'test-console', '--ab', '--s', '--sp')
def test_unittest(self): def test_unittest(self):
self._test_project('unittest', 'test-unittest', '--ab') self._test_project('unittest', 'test-unittest', '--ab')

View File

@ -7,9 +7,10 @@ from unittests_cli.constants import CLI_PATH
class CLICommands: class CLICommands:
@staticmethod @staticmethod
def _run(cmd: str, *args): def _run(cmd: str, *args, output=False):
env_vars = os.environ env_vars = os.environ
env_vars['CPL_IS_UNITTEST'] = 'YES' env_vars['CPL_IS_UNITTEST'] = 'NO' if output else 'YES'
command = ['python', CLI_PATH, cmd] command = ['python', CLI_PATH, cmd]
for arg in args: for arg in args:
command.append(arg) command.append(arg)
@ -17,9 +18,9 @@ class CLICommands:
subprocess.run(command, env=env_vars) subprocess.run(command, env=env_vars)
@classmethod @classmethod
def generate(cls, schematic: str, name: str): def generate(cls, schematic: str, name: str, output=False):
cls._run('generate', schematic, name) cls._run('generate', schematic, name, output=output)
@classmethod @classmethod
def new(cls, project_type: str, name: str, *args): def new(cls, project_type: str, name: str, *args, output=False):
cls._run('new', project_type, name, *args) cls._run('new', project_type, name, *args, output=output)