Commit 6820d712 authored by Igor Makarov's avatar Igor Makarov Committed by Commit Bot

Reformat python code in third_party/blink/tools/blinkpy/bindings for PEP8

- added .style.yapf file
- reformat *.py files

Bug: 1051750
Change-Id: Id52422ad244199d802c3c66afe480646e1672d37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127112Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758450}
parent ee6ab987
...@@ -11,24 +11,27 @@ from blink_idl_parser import parse_file, BlinkIDLParser ...@@ -11,24 +11,27 @@ from blink_idl_parser import parse_file, BlinkIDLParser
testdata_path = os.path.join( testdata_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'testdata') os.path.dirname(os.path.realpath(__file__)), 'testdata')
_FILE = os.path.join(testdata_path, 'test_filepath.txt') _FILE = os.path.join(testdata_path, 'test_filepath.txt')
_KEY_SET = set(['Operations', 'Name', 'FilePath', 'Inherit', 'Consts', 'ExtAttributes', 'Attributes']) _KEY_SET = set([
'Operations', 'Name', 'FilePath', 'Inherit', 'Consts', 'ExtAttributes',
'Attributes'
])
_PARTIAL = { _PARTIAL = {
'Node': { 'Node': {
'Operations': [], 'Operations': [],
'Name': 'Node', 'Name':
'FilePath': 'Source/core/timing/WorkerGlobalScopePerformance.idl', 'Node',
'FilePath':
'Source/core/timing/WorkerGlobalScopePerformance.idl',
'Inherit': [], 'Inherit': [],
'Consts': [], 'Consts': [],
'ExtAttributes': [], 'ExtAttributes': [],
'Attributes': [ 'Attributes': [{
{ 'Static': False,
'Static': False, 'Readonly': True,
'Readonly': True, 'Type': 'WorkerPerformance',
'Type': 'WorkerPerformance', 'Name': 'performance',
'Name': 'performance', 'ExtAttributes': []
'ExtAttributes': [] }]
}
]
} }
} }
...@@ -36,23 +39,26 @@ _PARTIAL = { ...@@ -36,23 +39,26 @@ _PARTIAL = {
class TestFunctions(unittest.TestCase): class TestFunctions(unittest.TestCase):
def setUp(self): def setUp(self):
parser = BlinkIDLParser() parser = BlinkIDLParser()
path = os.path.join( path = os.path.join(testdata_path,
testdata_path, utilities.read_file_to_list(_FILE)[0]) utilities.read_file_to_list(_FILE)[0])
definitions = parse_file(parser, path) definitions = parse_file(parser, path)
self.definition = definitions.GetChildren()[0] self.definition = definitions.GetChildren()[0]
def test_get_definitions(self): def test_get_definitions(self):
pathfile = utilities.read_file_to_list(_FILE) pathfile = utilities.read_file_to_list(_FILE)
pathfile = [os.path.join(testdata_path, filename) pathfile = [
for filename in pathfile] os.path.join(testdata_path, filename) for filename in pathfile
]
for actual in collect_idls_into_json.get_definitions(pathfile): for actual in collect_idls_into_json.get_definitions(pathfile):
self.assertEqual(actual.GetName(), self.definition.GetName()) self.assertEqual(actual.GetName(), self.definition.GetName())
def test_is_partial(self): def test_is_partial(self):
if self.definition.GetClass() == 'Interface' and self.definition.GetProperty('Partial'): if (self.definition.GetClass() == 'Interface'
and self.definition.GetProperty('Partial')):
self.assertTrue(collect_idls_into_json.is_partial(self.definition)) self.assertTrue(collect_idls_into_json.is_partial(self.definition))
else: else:
self.assertFalse(collect_idls_into_json.is_partial(self.definition)) self.assertFalse(
collect_idls_into_json.is_partial(self.definition))
def test_get_filepaths(self): def test_get_filepaths(self):
filepath = collect_idls_into_json.get_filepath(self.definition) filepath = collect_idls_into_json.get_filepath(self.definition)
...@@ -60,53 +66,85 @@ class TestFunctions(unittest.TestCase): ...@@ -60,53 +66,85 @@ class TestFunctions(unittest.TestCase):
def test_const_node_to_dict(self): def test_const_node_to_dict(self):
const_member = set(['Name', 'Type', 'Value', 'ExtAttributes']) const_member = set(['Name', 'Type', 'Value', 'ExtAttributes'])
for const in collect_idls_into_json.get_const_node_list(self.definition): for const in collect_idls_into_json.get_const_node_list(
self.definition):
if const: if const:
self.assertEqual(const.GetClass(), 'Const') self.assertEqual(const.GetClass(), 'Const')
self.assertEqual(collect_idls_into_json.get_const_type(const), 'unsigned short') self.assertEqual(
self.assertEqual(collect_idls_into_json.get_const_value(const), '1') collect_idls_into_json.get_const_type(const),
self.assertTrue(const_member.issuperset(collect_idls_into_json.const_node_to_dict(const).keys())) 'unsigned short')
self.assertEqual(
collect_idls_into_json.get_const_value(const), '1')
self.assertTrue(
const_member.issuperset(
collect_idls_into_json.const_node_to_dict(const).
keys()))
else: else:
self.assertEqual(const, None) self.assertEqual(const, None)
def test_attribute_node_to_dict(self): def test_attribute_node_to_dict(self):
attribute_member = set(['Name', 'Type', 'ExtAttributes', 'Readonly', 'Static']) attribute_member = set(
for attribute in collect_idls_into_json.get_attribute_node_list(self.definition): ['Name', 'Type', 'ExtAttributes', 'Readonly', 'Static'])
for attribute in collect_idls_into_json.get_attribute_node_list(
self.definition):
if attribute: if attribute:
self.assertEqual(attribute.GetClass(), 'Attribute') self.assertEqual(attribute.GetClass(), 'Attribute')
self.assertEqual(attribute.GetName(), 'parentNode') self.assertEqual(attribute.GetName(), 'parentNode')
self.assertEqual(collect_idls_into_json.get_attribute_type(attribute), 'Node') self.assertEqual(
self.assertTrue(attribute_member.issuperset(collect_idls_into_json.attribute_node_to_dict(attribute).keys())) collect_idls_into_json.get_attribute_type(attribute),
'Node')
self.assertTrue(
attribute_member.issuperset(
collect_idls_into_json.attribute_node_to_dict(
attribute).keys()))
else: else:
self.assertEqual(attribute, None) self.assertEqual(attribute, None)
def test_operation_node_to_dict(self): def test_operation_node_to_dict(self):
operate_member = set(['Static', 'ExtAttributes', 'Type', 'Name', 'Arguments']) operate_member = set(
['Static', 'ExtAttributes', 'Type', 'Name', 'Arguments'])
argument_member = set(['Name', 'Type']) argument_member = set(['Name', 'Type'])
for operation in collect_idls_into_json.get_operation_node_list(self.definition): for operation in collect_idls_into_json.get_operation_node_list(
self.definition):
if operation: if operation:
self.assertEqual(operation.GetClass(), 'Operation') self.assertEqual(operation.GetClass(), 'Operation')
self.assertEqual(operation.GetName(), 'appendChild') self.assertEqual(operation.GetName(), 'appendChild')
self.assertEqual(collect_idls_into_json.get_operation_type(operation), 'Node') self.assertEqual(
self.assertTrue(operate_member.issuperset(collect_idls_into_json.operation_node_to_dict(operation).keys())) collect_idls_into_json.get_operation_type(operation),
for argument in collect_idls_into_json.get_argument_node_list(operation): 'Node')
self.assertTrue(
operate_member.issuperset(
collect_idls_into_json.operation_node_to_dict(
operation).keys()))
for argument in collect_idls_into_json.get_argument_node_list(
operation):
if argument: if argument:
self.assertEqual(argument.GetClass(), 'Argument') self.assertEqual(argument.GetClass(), 'Argument')
self.assertEqual(argument.GetName(), 'newChild') self.assertEqual(argument.GetName(), 'newChild')
self.assertEqual(collect_idls_into_json.get_argument_type(argument), 'Node') self.assertEqual(
self.assertTrue(argument_member.issuperset(collect_idls_into_json.argument_node_to_dict(argument).keys())) collect_idls_into_json.get_argument_type(argument),
'Node')
self.assertTrue(
argument_member.issuperset(
collect_idls_into_json.argument_node_to_dict(
argument).keys()))
else: else:
self.assertEqual(argument, None) self.assertEqual(argument, None)
else: else:
self.assertEqual(operation, None) self.assertEqual(operation, None)
def test_extattribute_node_to_dict(self): def test_extattribute_node_to_dict(self):
for extattr in collect_idls_into_json.get_extattribute_node_list(self.definition): for extattr in collect_idls_into_json.get_extattribute_node_list(
self.definition):
if extattr: if extattr:
self.assertEqual(extattr.GetClass(), 'ExtAttribute') self.assertEqual(extattr.GetClass(), 'ExtAttribute')
self.assertEqual(extattr.GetName(), 'CustomToV8') self.assertEqual(extattr.GetName(), 'CustomToV8')
self.assertEqual(collect_idls_into_json.extattr_node_to_dict(extattr).keys(), ['Name']) self.assertEqual(
self.assertEqual(collect_idls_into_json.extattr_node_to_dict(extattr).values(), ['CustomToV8']) collect_idls_into_json.extattr_node_to_dict(extattr).
keys(), ['Name'])
self.assertEqual(
collect_idls_into_json.extattr_node_to_dict(extattr).
values(), ['CustomToV8'])
else: else:
self.assertEqual(extattr, None) self.assertEqual(extattr, None)
...@@ -119,12 +157,17 @@ class TestFunctions(unittest.TestCase): ...@@ -119,12 +157,17 @@ class TestFunctions(unittest.TestCase):
self.assertEqual(inherit, []) self.assertEqual(inherit, [])
def test_interface_node_to_dict(self): def test_interface_node_to_dict(self):
self.assertTrue(_KEY_SET.issuperset(collect_idls_into_json.interface_node_to_dict(self.definition))) self.assertTrue(
_KEY_SET.issuperset(
collect_idls_into_json.interface_node_to_dict(
self.definition)))
def test_merge_partial_dicts(self): def test_merge_partial_dicts(self):
key_name = self.definition.GetName() key_name = self.definition.GetName()
merged = collect_idls_into_json.merge_partial_dicts( merged = collect_idls_into_json.merge_partial_dicts({
{key_name: collect_idls_into_json.interface_node_to_dict(self.definition)}, _PARTIAL)[key_name]['Partial_FilePaths'] key_name:
collect_idls_into_json.interface_node_to_dict(self.definition)
}, _PARTIAL)[key_name]['Partial_FilePaths']
expected = [ expected = [
'Source/core/timing/WorkerGlobalScopePerformance.idl', 'Source/core/timing/WorkerGlobalScopePerformance.idl',
'Source/core/timing/WorkerGlobalScopePerformance.idl', 'Source/core/timing/WorkerGlobalScopePerformance.idl',
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# Copyright 2015 The Chromium Authors. All rights reserved. # Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""generate_idl_diff.py is a script that generates a diff of two given IDL files. """generate_idl_diff.py is a script that generates a diff of two given IDL files.
Usage: generate_idl_diff.py old_file.json new_file.json diff_file.json Usage: generate_idl_diff.py old_file.json new_file.json diff_file.json
old_file.json: An input json file including idl data of old Chrome version old_file.json: An input json file including idl data of old Chrome version
...@@ -55,8 +54,9 @@ and 'Operations'. Each item in them are called a "member". ...@@ -55,8 +54,9 @@ and 'Operations'. Each item in them are called a "member".
} }
""" """
EXTATTRIBUTES_AND_MEMBER_TYPES = [
EXTATTRIBUTES_AND_MEMBER_TYPES = ['ExtAttributes', 'Consts', 'Attributes', 'Operations'] 'ExtAttributes', 'Consts', 'Attributes', 'Operations'
]
DIFF_INSENSITIVE_FIELDS = ['Name'] DIFF_INSENSITIVE_FIELDS = ['Name']
DIFF_TAG = 'diff_tag' DIFF_TAG = 'diff_tag'
DIFF_TAG_ADDED = 'added' DIFF_TAG_ADDED = 'added'
...@@ -139,7 +139,8 @@ def interfaces_diff(old_interfaces, new_interfaces): ...@@ -139,7 +139,8 @@ def interfaces_diff(old_interfaces, new_interfaces):
annotated = {} annotated = {}
for interface_name, interface in new_interfaces.items(): for interface_name, interface in new_interfaces.items():
if interface_name in old_interfaces: if interface_name in old_interfaces:
annotated_interface, is_changed = members_diff(old_interfaces[interface_name], interface) annotated_interface, is_changed = members_diff(
old_interfaces[interface_name], interface)
if is_changed: if is_changed:
annotated[interface_name] = annotated_interface annotated[interface_name] = annotated_interface
del old_interfaces[interface_name] del old_interfaces[interface_name]
...@@ -166,9 +167,8 @@ def write_diff(diff, filepath): ...@@ -166,9 +167,8 @@ def write_diff(diff, filepath):
def main(argv): def main(argv):
if len(argv) != 3: if len(argv) != 3:
sys.stdout.write( sys.stdout.write('Usage: make_diff.py <old_file.json> <new_file.json> '
'Usage: make_diff.py <old_file.json> <new_file.json> ' '<diff_file.json>\n')
'<diff_file.json>\n')
exit(1) exit(1)
old_json_file = argv[0] old_json_file = argv[0]
new_json_file = argv[1] new_json_file = argv[1]
......
...@@ -11,7 +11,6 @@ from blinkpy.bindings.generate_idl_diff import DIFF_TAG ...@@ -11,7 +11,6 @@ from blinkpy.bindings.generate_idl_diff import DIFF_TAG
from blinkpy.bindings.generate_idl_diff import DIFF_TAG_DELETED from blinkpy.bindings.generate_idl_diff import DIFF_TAG_DELETED
from blinkpy.bindings.generate_idl_diff import DIFF_TAG_ADDED from blinkpy.bindings.generate_idl_diff import DIFF_TAG_ADDED
testdata_path = os.path.join( testdata_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'testdata') os.path.dirname(os.path.realpath(__file__)), 'testdata')
old_data_path = os.path.join(testdata_path, 'old_blink_idls.json') old_data_path = os.path.join(testdata_path, 'old_blink_idls.json')
...@@ -19,7 +18,6 @@ new_data_path = os.path.join(testdata_path, 'new_blink_idls.json') ...@@ -19,7 +18,6 @@ new_data_path = os.path.join(testdata_path, 'new_blink_idls.json')
class TestGenerateIDLDiff(unittest.TestCase): class TestGenerateIDLDiff(unittest.TestCase):
def setUp(self): def setUp(self):
old = generate_idl_diff.load_json_file(old_data_path) old = generate_idl_diff.load_json_file(old_data_path)
new = generate_idl_diff.load_json_file(new_data_path) new = generate_idl_diff.load_json_file(new_data_path)
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# Copyright 2015 The Chromium Authors. All rights reserved. # Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Print a diff generated by generate_idl_diff.py. """Print a diff generated by generate_idl_diff.py.
Before printing, sort the diff in the alphabetical order or the order of Before printing, sort the diff in the alphabetical order or the order of
diffing tags. diffing tags.
...@@ -24,7 +23,6 @@ from blinkpy.bindings.generate_idl_diff import DIFF_TAG ...@@ -24,7 +23,6 @@ from blinkpy.bindings.generate_idl_diff import DIFF_TAG
from blinkpy.bindings.generate_idl_diff import DIFF_TAG_ADDED from blinkpy.bindings.generate_idl_diff import DIFF_TAG_ADDED
from blinkpy.bindings.generate_idl_diff import DIFF_TAG_DELETED from blinkpy.bindings.generate_idl_diff import DIFF_TAG_DELETED
# pylint: disable=W0105 # pylint: disable=W0105
"""Refer to the explanation of generate_idl_diff.py's input files. """Refer to the explanation of generate_idl_diff.py's input files.
The deffference between the input structure of generate_idl_diff.py and The deffference between the input structure of generate_idl_diff.py and
...@@ -238,8 +236,8 @@ def sort_members_in_alphabetical_order(interface): ...@@ -238,8 +236,8 @@ def sort_members_in_alphabetical_order(interface):
""" """
sorted_interface = OrderedDict() sorted_interface = OrderedDict()
for member_type in EXTATTRIBUTES_AND_MEMBER_TYPES: for member_type in EXTATTRIBUTES_AND_MEMBER_TYPES:
sorted_members = sorted(interface[member_type], sorted_members = sorted(
key=lambda member: member['Name']) interface[member_type], key=lambda member: member['Name'])
sorted_interface[member_type] = sorted_members sorted_interface[member_type] = sorted_members
return sorted_interface return sorted_interface
...@@ -323,6 +321,7 @@ def print_extattributes_in_member(extattributes, out): ...@@ -323,6 +321,7 @@ def print_extattributes_in_member(extattributes, out):
Args: Args:
A list of "ExtAttributes" in the "member" object A list of "ExtAttributes" in the "member" object
""" """
def callback(extattribute): def callback(extattribute):
out.write(extattribute['Name']) out.write(extattribute['Name'])
...@@ -350,6 +349,7 @@ def print_arguments(arguments, out): ...@@ -350,6 +349,7 @@ def print_arguments(arguments, out):
"""Print arguments in a "members" object named "Operations". """Print arguments in a "members" object named "Operations".
Args: A list of "Arguments" Args: A list of "Arguments"
""" """
def callback(argument): def callback(argument):
out.write(argument['Name']) out.write(argument['Name'])
...@@ -407,7 +407,8 @@ def print_diff(diff, out): ...@@ -407,7 +407,8 @@ def print_diff(diff, out):
def print_usage(): def print_usage():
"""Show usage.""" """Show usage."""
sys.stdout.write('Usage: print_diff.py <diff_file.json> <"TAG"|"ALPHABET">\n') sys.stdout.write(
'Usage: print_diff.py <diff_file.json> <"TAG"|"ALPHABET">\n')
def main(argv): def main(argv):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment