Exemplo n.º 1
0
    def test_set_and_dict_paths_are_equiv(self):
        input_a = {"A": {"B": None}}
        input_b = {"A": {"B"}}

        output_a = TomlSchemaV1Validator._build_nested_keys(input_a)
        output_b = TomlSchemaV1Validator._build_nested_keys(input_b)
        self.assertEqual(output_a, output_b)
Exemplo n.º 2
0
    def test_wildcard_respected(self):
        valid_example = {
            "transmission": {
                "monitor": {
                    "FOO": {
                        "spectrum_number": None
                    }
                }
            }
        }
        invalid_example = {
            "transmission": {
                "monitor": {
                    "FOO": {
                        "NotRecognisedKey": None
                    }
                }
            }
        }

        obj = TomlSchemaV1Validator(valid_example)
        self.assertIsNone(obj.validate())

        with self.assertRaises(KeyError):
            TomlSchemaV1Validator(invalid_example).validate()
Exemplo n.º 3
0
    def test_path_building_can_handle_set(self):
        expected = ["A.Set", "A.SetB"]
        output = TomlSchemaV1Validator._build_nested_keys(
            {"A": {"Set", "SetB"}})

        # These can come in any order - so to avoid flaky tests we assert they are in
        self.assertTrue(expected[0] in output)
        self.assertTrue(expected[1] in output)
Exemplo n.º 4
0
    def __init__(self, dict_to_parse, file_information, schema_validator=None):
        self._validator = schema_validator if schema_validator else TomlSchemaV1Validator(
            dict_to_parse)
        self._validator.validate()

        self._implementation = None
        data_info = self.get_state_data(file_information)
        self._implementation = self._get_impl(dict_to_parse, data_info)
        self._implementation.parse_all()
Exemplo n.º 5
0
    def test_valid_key_accepted(self):
        expected_valid_examples = [{
            "instrument": {
                "name": mock.NonCallableMock()
            }
        }, {
            "instrument": {
                "configuration": {
                    "sample_offset": 1.0
                }
            }
        }]

        for i in expected_valid_examples:
            obj = TomlSchemaV1Validator(i)
            self.assertIsNone(obj.validate())
Exemplo n.º 6
0
    def test_paths_build_for_nested_dict(self):
        test_grid = [({
            "A": None
        }, ["A"]), ({
            "A": {
                "B": None
            }
        }, ["A.B"]), ({
            "A": {
                "B": None,
                "C": None
            }
        }, ["A.B", "A.C"])]

        for test_in, expected in test_grid:
            output = TomlSchemaV1Validator._build_nested_keys(test_in)
            self.assertEqual(expected, output)
Exemplo n.º 7
0
 def test_sub_key_checked(self):
     obj = TomlSchemaV1Validator({"instrument": "Foo"})
     with self.assertRaises(KeyError):
         obj.validate()
Exemplo n.º 8
0
 def test_all_unknown_keys_mentioned(self):
     obj = TomlSchemaV1Validator({"A": None, "B": None})
     with self.assertRaises(KeyError) as e:
         obj.validate()
         self.assertTrue("A" in e)
         self.assertTrue("B" in e)
Exemplo n.º 9
0
 def test_throws_if_unrecognised_top_level_key(self):
     for i in [{"NotRecognised": None}, {"Foo": {"Bar": None}}]:
         obj = TomlSchemaV1Validator(i)
         with self.assertRaises(KeyError):
             obj.validate()