Example #1
0
 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": ""}),
         ),
     )
Example #2
0
 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)
     )
Example #3
0
 def test_dependencies_main_defined_with_deps(self):
     InputModifiers({
         "a": 1,
         "b": 2,
         "c": 3,
         "d": 4
     }).ensure_dependency_satisfied("a", ["b", "c"])
Example #4
0
 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'")
Example #5
0
 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'"
     )
Example #6
0
 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")
Example #7
0
 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({})))
Example #8
0
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
    })
Example #9
0
 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
     )
Example #10
0
    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
        )
Example #11
0
 def test_mutually_exclusive_one_specified(self):
     InputModifiers({
         "a": 1,
         "b": 2
     }).ensure_not_mutually_exclusive("a", "c")
Example #12
0
 def test_not_specified_default(self):
     self.assertFalse(InputModifiers({"a": "1"}).is_specified("--debug"))
Example #13
0
 def test_mutually_exclusive_not_specified(self):
     InputModifiers({
         "a": 1,
         "b": 2,
         "c": 3
     }).ensure_not_mutually_exclusive("x", "y")
Example #14
0
 def test_is_specified(self):
     self.assertTrue(InputModifiers({"a": "1"}).is_specified("a"))
Example #15
0
 def test_not_specified(self):
     self.assertFalse(InputModifiers({"a": "1"}).is_specified("b"))
Example #16
0
 def test_explicit_default(self):
     val = "something"
     self.assertEqual(val, InputModifiers({}).get("--force", default=val))
Example #17
0
 def test_explicit_default_not_used(self):
     opt = "--force"
     self.assertTrue(InputModifiers({opt: ""}).get(opt, default=False))
Example #18
0
 def test_get_existing_with_default(self):
     self.assertEqual(1, InputModifiers({"a": 1}).get("a", default=2))
Example #19
0
 def test_wait_default(self):
     self.assertFalse(InputModifiers({}).get("--wait"))
Example #20
0
 def test_multiple_get_existing(self):
     self.assertEqual(2, InputModifiers(dict(c=3, a=1, b=2)).get("b"))
Example #21
0
 def test_incompatible_incompatible_not_defined(self):
     InputModifiers({
         "a": 1,
         "b": 2,
         "c": 3
     }).ensure_not_incompatible("a", ["z", "y"])
Example #22
0
 def test_bool_options_defaults(self):
     for opt in self.bool_opts:
         with self.subTest(opt=opt):
             self.assertFalse(InputModifiers({}).get(opt), opt)
Example #23
0
 def test_bool_options(self):
     for opt in self.bool_opts:
         with self.subTest(opt=opt):
             self.assertTrue(InputModifiers({opt: ""}).get(opt), opt)
Example #24
0
 def test_debug_implicit(self):
     InputModifiers({"--debug": ""}).ensure_only_supported()
Example #25
0
 def test_default(self):
     self.assertEqual(2, InputModifiers({"a": 1}).get("b", default=2))
Example #26
0
 def test_multiple_get_existing_with_default(self):
     self.assertEqual(
         2,
         InputModifiers(dict(c=3, a=1, b=2)).get("b", default=1))
Example #27
0
 def test_incompatible_checked_not_defined(self):
     InputModifiers({
         "a": 1,
         "b": 2,
         "c": 3
     }).ensure_not_incompatible("x", ["a", "c"])
Example #28
0
 def test_val_options_defaults(self):
     for opt in self.val_opts:
         with self.subTest(opt=opt):
             self.assertIsNone(InputModifiers({}).get(opt), opt)
Example #29
0
 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)
Example #30
0
 def test_wait(self):
     opt = "--wait"
     val = "something"
     self.assertEqual(val, InputModifiers({opt: val}).get(opt))