コード例 #1
0
 def test_get_mandatory_key_returns_key(self):
     # Should be able to handle an explicit None value
     expected_mock = mock.NonCallableMock()
     in_dict = {"is": {"there": None}, "mock": expected_mock}
     instance = TomlParserImplBase(in_dict)
     self.assertIsNone(instance.get_mandatory_val(["is", "there"]))
     self.assertEqual(expected_mock, instance.get_mandatory_val(["mock"]))
コード例 #2
0
    def test_get_mandatory_key_throws(self):
        in_dict = {"here": None}
        with self.assertRaisesRegex(MissingMandatoryParam, "this.not_there.foo"):
            TomlParserImplBase(in_dict).get_mandatory_val(["this", "not_there", "foo"])

        try:
            TomlParserImplBase(in_dict).get_mandatory_val(["not_there"])
        except KeyError:
            # Should be catchable with KeyError too, though assert raises
            # does not allow us to do isinstance so rely on thrown exception causing failure
            pass
コード例 #3
0
    def test_get_val_with_existing_dict(self):
        expected = mock.NonCallableMock()
        input_dict = {"there": None}
        injected_dict = {"there": expected}

        ret = TomlParserImplBase(input_dict).get_val("there", injected_dict)
        self.assertEqual(expected, ret, "Using internal dict instead of injected")
コード例 #4
0
    def test_returns_default_none(self):
        input_dict = {"foo": 1}
        expected = mock.NonCallableMock()

        self.assertEqual(
            expected,
            TomlParserImplBase(input_dict).get_val("bar", default=expected))
コード例 #5
0
 def test_get_val_returns_none_for_missing(self):
     input_dict = {"foo": 1}
     self.assertIsNone(TomlParserImplBase(input_dict).get_val("bar"))
コード例 #6
0
 def test_get_val_with_list(self):
     expected = mock.NonCallableMock()
     input_dict = {"is": {"there": expected}}
     self.assertEqual(expected, TomlParserImplBase(input_dict).get_val(["is", "there"]))
コード例 #7
0
 def test_get_mandatory_key_with_mixed_types(self):
     # Should be able to handle an explicit None value
     expected_mock = mock.NonCallableMock()
     in_dict = {"1": {"2": expected_mock}}
     instance = TomlParserImplBase(in_dict)
     self.assertEqual(expected_mock, instance.get_mandatory_val(["1", 2]))