def testNocompile(self):
        compiled = [{
            "namespace": "compile",
            "description": "The compile API.",
            "functions": [],
            "types": {}
        }, {
            "namespace": "functions",
            "description": "The functions API.",
            "functions": [{
                "id": "two"
            }, {
                "id": "four"
            }],
            "types": {
                "one": {
                    "key": "value"
                }
            }
        }, {
            "namespace": "types",
            "description": "The types API.",
            "functions": [{
                "id": "one"
            }],
            "types": {
                "two": {
                    "key": "value"
                },
                "four": {
                    "key": "value"
                }
            }
        }, {
            "namespace": "nested",
            "description": "The nested API.",
            "properties": {
                "sync": {
                    "functions": [{
                        "id": "two"
                    }, {
                        "id": "four"
                    }],
                    "types": {
                        "two": {
                            "key": "value"
                        },
                        "four": {
                            "key": "value"
                        }
                    }
                }
            }
        }]

        schema = json_schema.CachedLoad('test/json_schema_test.json')
        self.assertEquals(compiled,
                          json_schema.DeleteNodes(schema, 'nocompile'))
Exemplo n.º 2
0
    def testNocompile(self):
        compiled = [{
            "namespace": "compile",
            "description": "The compile API.",
            "functions": [],
            "types": {}
        }, {
            "namespace": "functions",
            "description": "The functions API.",
            "functions": [{
                "id": "two"
            }, {
                "id": "four"
            }],
            "types": {
                "one": {
                    "key": "value"
                }
            }
        }, {
            "namespace": "types",
            "description": "The types API.",
            "functions": [{
                "id": "one"
            }],
            "types": {
                "two": {
                    "key": "value"
                },
                "four": {
                    "key": "value"
                }
            }
        }, {
            "namespace": "nested",
            "description": "The nested API.",
            "properties": {
                "sync": {
                    "functions": [{
                        "id": "two"
                    }, {
                        "id": "four"
                    }],
                    "types": {
                        "two": {
                            "key": "value"
                        },
                        "four": {
                            "key": "value"
                        }
                    }
                }
            }
        }]

        schema = json_schema.CachedLoad('test/json_schema_test.json')
        self.assertEquals(compiled,
                          json_schema.DeleteNodes(schema, 'nocompile'))

        def should_delete(value):
            return isinstance(value, dict) and not value.get('valid', True)

        expected = [{'one': {'test': 'test'}}, {'valid': True}, {}]
        given = [{
            'one': {
                'test': 'test'
            },
            'two': {
                'valid': False
            }
        }, {
            'valid': True
        }, {}, {
            'valid': False
        }]
        self.assertEquals(
            expected, json_schema.DeleteNodes(given, matcher=should_delete))