Exemple #1
0
    def test_basic_singleton(self):
        """Very basic schema and data with one node."""

        schema = {
            ('root', str): {
                ('sample node', str, 'sample'): ('node', str, r'[a-z]*')
            }
        }
        data = {'root': {'sample': 'node'}}

        expected_schema = {
            ('root', 'root'): [('sample node', 'node')]
        }
        expected_data = {
            ('root', 'root'): [('sample', ('node', str, '[a-z]*'))]
        }

        assert dict(lws.validate_schema(schema, data)) == expected_schema
        assert dict(lws.validate_data(schema, data)) == expected_data
Exemple #2
0
    def test_basic_singleton_key_error(self):
        """Very basic schema and data with one key error."""

        schema = {
            ('root', str): {
                ('sample node', str, 'sample'): ('node', str, r'[a-z]*')
            }
        }
        data = {'root': {'not sample': 'node'}}

        ERRORS = lws.return_errors()
        expected_schema = {
            ('root', 'root'): [('sample node', ERRORS['key'])]
        }
        expected_data = {
            ('root', 'root'): [('not sample', ERRORS['key'])]
        }

        assert dict(lws.validate_schema(schema, data)) == expected_schema
        assert dict(lws.validate_data(schema, data)) == expected_data