def test_show_constraints_full(self): load_constraints = mock.Mock() load_constraints.return_value = { "plain": [{ "options": { "id": "plain_id" } }], "with_resource_sets": [fixture_constraint()], } format_options = mock.Mock() format_options.return_value = "plain constraint listing" self.assertEqual( [ "caption", " plain constraint listing", " Resource Sets:", " " + fixture_constraint_console(), ], command.show( "caption", load_constraints, format_options, InputModifiers({"--full": ""}), ), )
def test_get_non_existing(self): opt = "not_existing_option" with self.assertRaises(AssertionError) as cm: InputModifiers({}).get(opt) self.assertEqual( f"Non existing default value for '{opt}'", str(cm.exception) )
def test_dependencies_main_defined_with_deps(self): InputModifiers({ "a": 1, "b": 2, "c": 3, "d": 4 }).ensure_dependency_satisfied("a", ["b", "c"])
def test_incompatible_one(self): with self.assertRaises(CmdLineInputError) as cm: InputModifiers({ "a": 1, "b": 2, "c": 3 }).ensure_not_incompatible("a", ["b", "y"]) self.assertEqual(str(cm.exception), "'a' cannot be used with 'b'")
def test_dependencies_missing_multiple(self): with self.assertRaises(CmdLineInputError) as cm: InputModifiers( {"a": 1, "b": 2, "c": 3} ).ensure_dependency_satisfied("x", ["c", "b", "d"]) self.assertEqual( str(cm.exception), "'b', 'c' cannot be used without 'x'" )
def test_mutually_exclusive_more_specified(self): with self.assertRaises(CmdLineInputError) as cm: InputModifiers({ "a": 1, "b": 2, "c": 3 }).ensure_not_mutually_exclusive("c", "a") self.assertEqual(str(cm.exception), "Only one of 'a', 'c' can be used")
def test_show_only_caption_when_no_constraint_loaded(self): self.assertEqual(["caption"], command.show("caption", load_constraints=lambda: { "plain": [], "with_resource_sets": [] }, format_options=lambda: None, modifiers=InputModifiers({})))
def _dict_to_modifiers(options): def _convert_val(val): if val is True: return "" return val return InputModifiers({ f"--{opt}": _convert_val(val) for opt, val in options.items() if val is not False })
def test_call_lib_with_ticket_name(self): lib = mock.MagicMock() lib.booth = mock.MagicMock() lib.booth.config_ticket_add = mock.MagicMock() command.config_ticket_add( lib, arg_list=["TICKET_A", "timeout=10"], modifiers=InputModifiers({"--force": ""}) ) lib.booth.config_ticket_add.assert_called_once_with( "TICKET_A", {"timeout": "10"}, allow_unknown_options=True )
def test_call_lib_with_correct_args(self): lib = mock.MagicMock() lib.booth = mock.MagicMock() lib.booth.config_setup = mock.MagicMock() command.config_setup( lib, arg_list=[ "sites", "1.1.1.1", "2.2.2.2", "4.4.4.4", "arbitrators", "3.3.3.3" ], modifiers=InputModifiers({}), ) lib.booth.config_setup.assert_called_once_with( [ {"key": "site", "value": "1.1.1.1", "details": []}, {"key": "site", "value": "2.2.2.2", "details": []}, {"key": "site", "value": "4.4.4.4", "details": []}, {"key": "arbitrator", "value": "3.3.3.3", "details": []}, ], overwrite_existing=False )
def test_mutually_exclusive_one_specified(self): InputModifiers({ "a": 1, "b": 2 }).ensure_not_mutually_exclusive("a", "c")
def test_not_specified_default(self): self.assertFalse(InputModifiers({"a": "1"}).is_specified("--debug"))
def test_mutually_exclusive_not_specified(self): InputModifiers({ "a": 1, "b": 2, "c": 3 }).ensure_not_mutually_exclusive("x", "y")
def test_is_specified(self): self.assertTrue(InputModifiers({"a": "1"}).is_specified("a"))
def test_not_specified(self): self.assertFalse(InputModifiers({"a": "1"}).is_specified("b"))
def test_explicit_default(self): val = "something" self.assertEqual(val, InputModifiers({}).get("--force", default=val))
def test_explicit_default_not_used(self): opt = "--force" self.assertTrue(InputModifiers({opt: ""}).get(opt, default=False))
def test_get_existing_with_default(self): self.assertEqual(1, InputModifiers({"a": 1}).get("a", default=2))
def test_wait_default(self): self.assertFalse(InputModifiers({}).get("--wait"))
def test_multiple_get_existing(self): self.assertEqual(2, InputModifiers(dict(c=3, a=1, b=2)).get("b"))
def test_incompatible_incompatible_not_defined(self): InputModifiers({ "a": 1, "b": 2, "c": 3 }).ensure_not_incompatible("a", ["z", "y"])
def test_bool_options_defaults(self): for opt in self.bool_opts: with self.subTest(opt=opt): self.assertFalse(InputModifiers({}).get(opt), opt)
def test_bool_options(self): for opt in self.bool_opts: with self.subTest(opt=opt): self.assertTrue(InputModifiers({opt: ""}).get(opt), opt)
def test_debug_implicit(self): InputModifiers({"--debug": ""}).ensure_only_supported()
def test_default(self): self.assertEqual(2, InputModifiers({"a": 1}).get("b", default=2))
def test_multiple_get_existing_with_default(self): self.assertEqual( 2, InputModifiers(dict(c=3, a=1, b=2)).get("b", default=1))
def test_incompatible_checked_not_defined(self): InputModifiers({ "a": 1, "b": 2, "c": 3 }).ensure_not_incompatible("x", ["a", "c"])
def test_val_options_defaults(self): for opt in self.val_opts: with self.subTest(opt=opt): self.assertIsNone(InputModifiers({}).get(opt), opt)
def test_val_options(self): val = "something" for opt in self.val_opts: with self.subTest(opt=opt): self.assertEqual(val, InputModifiers({opt: val}).get(opt), opt)
def test_wait(self): opt = "--wait" val = "something" self.assertEqual(val, InputModifiers({opt: val}).get(opt))