Пример #1
0
    def test_validate_negative_missing_keys(self):
        filepath = self.get_data_path('placements-missing.json')
        fmt = PlacementsFormat(filepath, mode='r')

        with self.assertRaisesRegex(ValidationError,
                                    'found.*placements.*tree'):
            fmt.validate()
Пример #2
0
    def test_placements_format_to_dict(self):
        transformer = self.get_transformer(PlacementsFormat, dict)

        fp = pathlib.Path(self.temp_dir.name) / pathlib.Path('placements.json')
        fp.write_text('{"foo": 1}')

        input_ = PlacementsFormat(str(fp), mode='r')
        with self.assertRaisesRegex(ValidationError, r'found \[\'foo\'\]'):
            # A bit of a cop-out, but this means we were able to parse the
            # JSON document.
            input_.validate(level='max')

        obs = transformer(input_)
        self.assertEqual(obs, {'foo': 1})
Пример #3
0
    def test_validate_negative_array(self):
        filepath = self.get_data_path('root-array.json')
        fmt = PlacementsFormat(filepath, mode='r')

        with self.assertRaisesRegex(ValidationError, 'JSON object'):
            fmt.validate()
Пример #4
0
    def test_validate_positive(self):
        filepath = self.get_data_path('placements.json')
        fmt = PlacementsFormat(filepath, mode='r')

        fmt.validate()
        self.assertTrue(True)