#157 #165

Merged
edraft merged 14 commits from #157 into 2023.4 2023-04-11 11:48:49 +02:00
2 changed files with 77 additions and 0 deletions
Showing only changes of commit 792429d19d - Show all commits

View File

@ -0,0 +1,75 @@
import sys
import unittest
from unittest.mock import Mock, MagicMock
from cpl_core.configuration import Configuration, ArgumentTypeEnum
from cpl_core.dependency_injection import ServiceCollection
class ConsoleArgumentsTestCase(unittest.TestCase):
def setUp(self):
self._config = Configuration()
self._config.create_console_argument(ArgumentTypeEnum.Flag, "", "flag", [])
self._config.create_console_argument(ArgumentTypeEnum.Variable, "", "var", [], "=")
self._config.create_console_argument(ArgumentTypeEnum.Executable, "", "exec", [], Mock).add_console_argument(
ArgumentTypeEnum.Flag, "--", "dev", ["d", "D"]
).add_console_argument(ArgumentTypeEnum.Flag, "--", "virtual", ["v", "V"]).add_console_argument(
ArgumentTypeEnum.Variable, "", "var1", [], "="
)
self._config.for_each_argument(
lambda a: a.add_console_argument(ArgumentTypeEnum.Flag, "--", "help", ["h", "H"])
)
self._sc = ServiceCollection(self._config)
self._mocked_exec = Mock()
self._mocked_exec.run = MagicMock()
self._sc.add_transient(self._mocked_exec)
def test_flag(self):
sys.argv.append("flag")
self._config.parse_console_arguments(self._sc.build_service_provider())
self.assertIn("flag", self._config.additional_arguments)
def test_var(self):
sys.argv.append("var=1")
sys.argv.append("var2=1")
self._config.parse_console_arguments(self._sc.build_service_provider())
self.assertEqual("1", self._config.get_configuration("var"))
self.assertIsNone(self._config.get_configuration("var1"))
def test_exec(self):
sys.argv.append("exec")
self._config.parse_console_arguments(self._sc.build_service_provider())
self._mocked_exec.run.assert_called()
def test_exec_with_one_flag(self):
sys.argv.append("exec")
sys.argv.append("--dev")
self._config.parse_console_arguments(self._sc.build_service_provider())
self._mocked_exec.run.assert_called()
self.assertIn("dev", self._config.additional_arguments)
def test_exec_with_one_flag_alias(self):
sys.argv.append("exec")
sys.argv.append("--d")
self._config.parse_console_arguments(self._sc.build_service_provider())
self._mocked_exec.run.assert_called()
self.assertIn("dev", self._config.additional_arguments)
def test_exec_with_two_flags(self):
sys.argv.append("exec")
sys.argv.append("--dev")
sys.argv.append("--virtual")
self._config.parse_console_arguments(self._sc.build_service_provider())
self._mocked_exec.run.assert_called()
self.assertIn("dev", self._config.additional_arguments)
self.assertIn("virtual", self._config.additional_arguments)

View File

@ -1,5 +1,6 @@
import unittest import unittest
from unittests_core.configuration.console_arguments_test_case import ConsoleArgumentsTestCase
from unittests_core.configuration.configuration_test_case import ConfigurationTestCase from unittests_core.configuration.configuration_test_case import ConfigurationTestCase
from unittests_core.configuration.environment_test_case import EnvironmentTestCase from unittests_core.configuration.environment_test_case import EnvironmentTestCase
from unittests_core.pipes.bool_pipe_test_case import BoolPipeTestCase from unittests_core.pipes.bool_pipe_test_case import BoolPipeTestCase
@ -18,6 +19,7 @@ class CoreTestSuite(unittest.TestSuite):
tests = [ tests = [
# config # config
ConfigurationTestCase, ConfigurationTestCase,
ConsoleArgumentsTestCase,
EnvironmentTestCase, EnvironmentTestCase,
# pipes # pipes
BoolPipeTestCase, BoolPipeTestCase,