Updated docs
This commit is contained in:
@@ -10,12 +10,11 @@ from unittests_shared.cli_commands import CLICommands
|
||||
|
||||
|
||||
class RunTestCase(CommandTestCase):
|
||||
|
||||
def __init__(self, method_name: str):
|
||||
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._application = f'src/{String.convert_to_snake_case(self._source)}/application.py'
|
||||
self._source = "run-test"
|
||||
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
||||
self._application = f"src/{String.convert_to_snake_case(self._source)}/application.py"
|
||||
self._test_code = f"""
|
||||
import json
|
||||
import os
|
||||
@@ -34,11 +33,11 @@ class RunTestCase(CommandTestCase):
|
||||
"""
|
||||
|
||||
def _get_appsettings(self, is_dev=False):
|
||||
appsettings = f'dist/{self._source}/build/{String.convert_to_snake_case(self._source)}/appsettings.json'
|
||||
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'
|
||||
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:
|
||||
with open(os.path.join(os.getcwd(), appsettings), "r", encoding="utf-8") as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
@@ -46,85 +45,73 @@ class RunTestCase(CommandTestCase):
|
||||
return project_json
|
||||
|
||||
def _save_appsettings(self, settings: dict):
|
||||
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:
|
||||
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()
|
||||
|
||||
def setUp(self):
|
||||
os.chdir(PLAYGROUND_PATH)
|
||||
# create projects
|
||||
CLICommands.new('console', self._source, '--ab', '--s')
|
||||
CLICommands.new("console", self._source, "--ab", "--s")
|
||||
os.chdir(os.path.join(os.getcwd(), self._source))
|
||||
settings = {'RunTest': {'WasStarted': 'False'}}
|
||||
settings = {"RunTest": {"WasStarted": "False"}}
|
||||
self._save_appsettings(settings)
|
||||
with open(os.path.join(os.getcwd(), self._application), 'a', encoding='utf-8') as file:
|
||||
file.write(f'\t\t{self._test_code}')
|
||||
with open(os.path.join(os.getcwd(), self._application), "a", encoding="utf-8") as file:
|
||||
file.write(f"\t\t{self._test_code}")
|
||||
file.close()
|
||||
|
||||
def test_run(self):
|
||||
CLICommands.run()
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertNotEqual(
|
||||
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
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']
|
||||
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):
|
||||
CLICommands.run(self._source)
|
||||
settings = self._get_appsettings()
|
||||
self.assertNotEqual(settings, {})
|
||||
self.assertIn('RunTest', settings)
|
||||
self.assertIn('WasStarted', settings['RunTest'])
|
||||
self.assertEqual(
|
||||
'True',
|
||||
settings['RunTest']['WasStarted']
|
||||
)
|
||||
self.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
self.assertNotEqual(
|
||||
os.path.join(os.getcwd(), f'src/{String.convert_to_snake_case(self._source)}'),
|
||||
settings['RunTest']['Path']
|
||||
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']
|
||||
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.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
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']
|
||||
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.assertIn("RunTest", settings)
|
||||
self.assertIn("WasStarted", settings["RunTest"])
|
||||
self.assertEqual("True", settings["RunTest"]["WasStarted"])
|
||||
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']
|
||||
os.path.join(os.getcwd(), f"src/{String.convert_to_snake_case(self._source)}"), settings["RunTest"]["Path"]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user