2022.6.17 - Unittests #84
@ -1,3 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
@ -50,6 +51,33 @@ class NewTestCase(unittest.TestCase):
|
||||
self.assertTrue(os.path.join(project_path, f'{name}.json'))
|
||||
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):
|
||||
self._test_project('console', 'test-console', '--ab', '--s')
|
||||
|
||||
@ -71,6 +99,9 @@ class NewTestCase(unittest.TestCase):
|
||||
def test_sub_library(self):
|
||||
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):
|
||||
self._test_project('unittest', 'test-unittest', '--ab')
|
||||
|
||||
|
@ -7,9 +7,10 @@ from unittests_cli.constants import CLI_PATH
|
||||
class CLICommands:
|
||||
|
||||
@staticmethod
|
||||
def _run(cmd: str, *args):
|
||||
def _run(cmd: str, *args, output=False):
|
||||
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]
|
||||
for arg in args:
|
||||
command.append(arg)
|
||||
@ -17,9 +18,9 @@ class CLICommands:
|
||||
subprocess.run(command, env=env_vars)
|
||||
|
||||
@classmethod
|
||||
def generate(cls, schematic: str, name: str):
|
||||
cls._run('generate', schematic, name)
|
||||
def generate(cls, schematic: str, name: str, output=False):
|
||||
cls._run('generate', schematic, name, output=output)
|
||||
|
||||
@classmethod
|
||||
def new(cls, project_type: str, name: str, *args):
|
||||
cls._run('new', project_type, name, *args)
|
||||
def new(cls, project_type: str, name: str, *args, output=False):
|
||||
cls._run('new', project_type, name, *args, output=output)
|
||||
|
Loading…
Reference in New Issue
Block a user