2022-06-03 23:44:26 +02:00
|
|
|
import json
|
|
|
|
import os
|
2022-05-26 13:49:31 +02:00
|
|
|
import unittest
|
|
|
|
|
2022-06-03 23:44:26 +02:00
|
|
|
from cpl_core.utils import String
|
2022-12-01 23:23:48 +01:00
|
|
|
from unittests_cli.abc.command_test_case import CommandTestCase
|
2022-06-03 23:44:26 +02:00
|
|
|
from unittests_cli.constants import PLAYGROUND_PATH
|
|
|
|
from unittests_shared.cli_commands import CLICommands
|
|
|
|
|
2022-05-26 13:49:31 +02:00
|
|
|
|
2022-12-01 23:23:48 +01:00
|
|
|
class RemoveTestCase(CommandTestCase):
|
|
|
|
def __init__(self, method_name: str):
|
|
|
|
CommandTestCase.__init__(self, method_name)
|
2023-02-20 15:55:20 +01:00
|
|
|
self._source = "add-test-project"
|
|
|
|
self._target = "add-test-library"
|
|
|
|
self._project_file = f"src/{String.convert_to_snake_case(self._source)}/{self._source}.json"
|
2022-06-03 23:44:26 +02:00
|
|
|
|
2022-06-03 23:46:03 +02:00
|
|
|
def _get_project_settings(self):
|
2023-02-20 15:55:20 +01:00
|
|
|
with open(os.path.join(os.getcwd(), self._project_file), "r", encoding="utf-8") as cfg:
|
2022-06-03 23:46:03 +02:00
|
|
|
# load json
|
|
|
|
project_json = json.load(cfg)
|
|
|
|
cfg.close()
|
|
|
|
|
|
|
|
return project_json
|
|
|
|
|
2022-05-26 13:49:31 +02:00
|
|
|
def setUp(self):
|
2022-12-01 17:00:17 +01:00
|
|
|
if not os.path.exists(PLAYGROUND_PATH):
|
|
|
|
os.makedirs(PLAYGROUND_PATH)
|
2023-02-20 15:55:20 +01:00
|
|
|
|
2022-12-01 17:00:17 +01:00
|
|
|
os.chdir(PLAYGROUND_PATH)
|
2022-06-03 23:44:26 +02:00
|
|
|
# create projects
|
2023-02-20 15:55:20 +01:00
|
|
|
CLICommands.new("console", self._source, "--ab", "--s")
|
2022-06-03 23:44:26 +02:00
|
|
|
os.chdir(os.path.join(os.getcwd(), self._source))
|
2023-02-20 15:55:20 +01:00
|
|
|
CLICommands.new("console", self._target, "--ab", "--s")
|
2022-06-04 00:36:31 +02:00
|
|
|
CLICommands.add(self._source, self._target)
|
2022-05-26 13:49:31 +02:00
|
|
|
|
2022-06-03 23:44:26 +02:00
|
|
|
def test_remove(self):
|
|
|
|
CLICommands.remove(self._target)
|
2023-02-20 15:55:20 +01:00
|
|
|
path = os.path.abspath(os.path.join(os.getcwd(), f"../{String.convert_to_snake_case(self._target)}"))
|
2022-06-03 23:44:26 +02:00
|
|
|
self.assertTrue(os.path.exists(os.getcwd()))
|
|
|
|
self.assertTrue(os.path.exists(os.path.join(os.getcwd(), self._project_file)))
|
|
|
|
self.assertFalse(os.path.exists(path))
|
2022-06-03 23:46:03 +02:00
|
|
|
settings = self._get_project_settings()
|
2023-02-20 15:55:20 +01:00
|
|
|
self.assertIn("ProjectSettings", settings)
|
|
|
|
self.assertIn("ProjectReferences", settings["BuildSettings"])
|
|
|
|
self.assertIn("BuildSettings", settings)
|
2022-06-03 23:46:03 +02:00
|
|
|
self.assertNotIn(
|
2023-02-20 15:55:20 +01:00
|
|
|
f"../{String.convert_to_snake_case(self._target)}/{self._target}.json",
|
|
|
|
settings["BuildSettings"]["ProjectReferences"],
|
2022-06-03 23:46:03 +02:00
|
|
|
)
|