Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: bindings/scripts/test_collect_idls_into_json.py

Issue 2786203002: Roll 50: Copied IDLs, PYTHON scripts from WebKit removed deleted files in WebCore (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bindings/scripts/print_idl_diff.py ('k') | bindings/scripts/testdata/test_interface.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 import unittest
4 import collect_idls_into_json
5 import utilities
6
7 from blink_idl_parser import parse_file, BlinkIDLParser
8
9 _FILE = 'Source/bindings/scripts/testdata/test_filepath.txt'
10 _KEY_SET = set(['Operations', 'Name', 'FilePath', 'Inherit', 'Consts', 'ExtAttri butes', 'Attributes'])
11 _PARTIAL = {'Node': {'Operations': [], 'Name': 'Node', 'FilePath': 'Source/core/ timing/WorkerGlobalScopePerformance.idl', 'Inherit': [], 'Consts': [], 'ExtAttri butes': [], 'Attributes': [{'Static': False, 'Readonly': True, 'Type': 'WorkerPe rformance', 'Name': 'performance', 'ExtAttributes': []}]}}
12
13
14 class TestFunctions(unittest.TestCase):
15 def setUp(self):
16 parser = BlinkIDLParser()
17 path = utilities.read_file_to_list(_FILE)[0]
18 definitions = parse_file(parser, path)
19 self.definition = definitions.GetChildren()[0]
20
21 def test_get_definitions(self):
22 pathfile = utilities.read_file_to_list(_FILE)
23 for actual in collect_idls_into_json.get_definitions(pathfile):
24 self.assertEqual(actual.GetName(), self.definition.GetName())
25
26 def test_is_non_partial(self):
27 if self.definition.GetClass() == 'Interface' and not self.definition.Get Property('Partial'):
28 self.assertTrue(collect_idls_into_json.is_non_partial(self.definitio n))
29 else:
30 self.assertFalse(collect_idls_into_json.is_non_partial(self.definiti on))
31
32 def test_is_partial(self):
33 if self.definition.GetClass() == 'Interface' and self.definition.GetProp erty('Partial'):
34 self.assertTrue(collect_idls_into_json.is_partial(self.definition))
35 else:
36 self.assertFalse(collect_idls_into_json.is_partial(self.definition))
37
38 def test_get_filepaths(self):
39 filepath = collect_idls_into_json.get_filepath(self.definition)
40 self.assertTrue(filepath.startswith('Source'))
41 self.assertTrue(filepath.endswith('.idl'))
42
43 def test_const_node_to_dict(self):
44 const_member = set(['Name', 'Type', 'Value', 'ExtAttributes'])
45 for const in collect_idls_into_json.get_const_node_list(self.definition) :
46 if const:
47 self.assertEqual(const.GetClass(), 'Const')
48 self.assertEqual(collect_idls_into_json.get_const_type(const), ' unsigned short')
49 self.assertEqual(collect_idls_into_json.get_const_value(const), '1')
50 self.assertTrue(const_member.issuperset(collect_idls_into_json.c onst_node_to_dict(const).keys()))
51 else:
52 self.assertEqual(const, None)
53
54 def test_attribute_node_to_dict(self):
55 attribute_member = set(['Name', 'Type', 'ExtAttributes', 'Readonly', 'St atic'])
56 for attribute in collect_idls_into_json.get_attribute_node_list(self.def inition):
57 if attribute:
58 self.assertEqual(attribute.GetClass(), 'Attribute')
59 self.assertEqual(attribute.GetName(), 'parentNode')
60 self.assertEqual(collect_idls_into_json.get_attribute_type(attri bute), 'Node')
61 self.assertTrue(attribute_member.issuperset(collect_idls_into_js on.attribute_node_to_dict(attribute).keys()))
62 else:
63 self.assertEqual(attribute, None)
64
65 def test_operation_node_to_dict(self):
66 operate_member = set(['Static', 'ExtAttributes', 'Type', 'Name', 'Argume nts'])
67 argument_member = set(['Name', 'Type'])
68 for operation in collect_idls_into_json.get_operation_node_list(self.def inition):
69 if operation:
70 self.assertEqual(operation.GetClass(), 'Operation')
71 self.assertEqual(operation.GetName(), 'appendChild')
72 self.assertEqual(collect_idls_into_json.get_operation_type(opera tion), 'Node')
73 self.assertTrue(operate_member.issuperset(collect_idls_into_json .operation_node_to_dict(operation).keys()))
74 for argument in collect_idls_into_json.get_argument_node_list(op eration):
75 if argument:
76 self.assertEqual(argument.GetClass(), 'Argument')
77 self.assertEqual(argument.GetName(), 'newChild')
78 self.assertEqual(collect_idls_into_json.get_argument_typ e(argument), 'Node')
79 self.assertTrue(argument_member.issuperset(collect_idls_ into_json.argument_node_to_dict(argument).keys()))
80 else:
81 self.assertEqual(argument, None)
82 else:
83 self.assertEqual(operation, None)
84
85 def test_extattribute_node_to_dict(self):
86 for extattr in collect_idls_into_json.get_extattribute_node_list(self.de finition):
87 if extattr:
88 self.assertEqual(extattr.GetClass(), 'ExtAttribute')
89 self.assertEqual(extattr.GetName(), 'CustomToV8')
90 self.assertEqual(collect_idls_into_json.extattr_node_to_dict(ext attr).keys(), ['Name'])
91 self.assertEqual(collect_idls_into_json.extattr_node_to_dict(ext attr).values(), ['CustomToV8'])
92 else:
93 self.assertEqual(extattr, None)
94
95 def test_inherit_node_to_dict(self):
96 inherit = collect_idls_into_json.inherit_node_to_dict(self.definition)
97 if inherit:
98 self.assertEqual(inherit.keys(), ['Parent'])
99 self.assertEqual(inherit.values(), ['EventTarget'])
100 else:
101 self.assertEqual(inherit, [])
102
103 def test_interface_node_to_dict(self):
104 self.assertTrue(_KEY_SET.issuperset(collect_idls_into_json.interface_nod e_to_dict(self.definition)))
105
106 def test_merge_partial_dicts(self):
107 key_name = self.definition.GetName()
108 self.assertEqual(collect_idls_into_json.merge_partial_dicts({key_name: c ollect_idls_into_json.interface_node_to_dict(self.definition)}, _PARTIAL)[key_na me]['Partial_FilePaths'], ['Source/core/timing/WorkerGlobalScopePerformance.idl' ])
109
110
111 if __name__ == '__main__':
112 unittest.main()
OLDNEW
« no previous file with comments | « bindings/scripts/print_idl_diff.py ('k') | bindings/scripts/testdata/test_interface.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698