Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / tools / json_schema_compiler / json_schema_test.py
blobedbb06e5aa17338acc2f1f774a29962d9a0d3ab6
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import json_schema
7 import unittest
9 class JsonSchemaUnittest(unittest.TestCase):
10 def testNocompile(self):
11 compiled = [
13 "namespace": "compile",
14 "description": "The compile API.",
15 "functions": [],
16 "types": {}
20 "namespace": "functions",
21 "description": "The functions API.",
22 "functions": [
24 "id": "two"
27 "id": "four"
31 "types": {
32 "one": { "key": "value" }
37 "namespace": "types",
38 "description": "The types API.",
39 "functions": [
40 { "id": "one" }
42 "types": {
43 "two": {
44 "key": "value"
46 "four": {
47 "key": "value"
53 "namespace": "nested",
54 "description": "The nested API.",
55 "properties": {
56 "sync": {
57 "functions": [
59 "id": "two"
62 "id": "four"
65 "types": {
66 "two": {
67 "key": "value"
69 "four": {
70 "key": "value"
78 schema = json_schema.CachedLoad('test/json_schema_test.json')
79 self.assertEquals(compiled, json_schema.DeleteNodes(schema, 'nocompile'))
81 def should_delete(value):
82 return isinstance(value, dict) and not value.get('valid', True)
83 expected = [
84 {'one': {'test': 'test'}},
85 {'valid': True},
88 given = [
89 {'one': {'test': 'test'}, 'two': {'valid': False}},
90 {'valid': True},
91 {},
92 {'valid': False}
94 self.assertEquals(
95 expected, json_schema.DeleteNodes(given, matcher=should_delete))
98 if __name__ == '__main__':
99 unittest.main()