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
testdata_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'testdata')
_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 = {
'Node': {
'Operations': [],
'Name': 'Node',
'FilePath': 'Source/core/timing/WorkerGlobalScopePerformance.idl',
'Name':
'Node',
'FilePath':
'Source/core/timing/WorkerGlobalScopePerformance.idl',
'Inherit': [],
'Consts': [],
'ExtAttributes': [],
'Attributes': [
{
'Attributes': [{
'Static': False,
'Readonly': True,
'Type': 'WorkerPerformance',
'Name': 'performance',
'ExtAttributes': []
}
]
}]
}
}
......@@ -36,23 +39,26 @@ _PARTIAL = {
class TestFunctions(unittest.TestCase):
def setUp(self):
parser = BlinkIDLParser()
path = os.path.join(
testdata_path, utilities.read_file_to_list(_FILE)[0])
path = os.path.join(testdata_path,
utilities.read_file_to_list(_FILE)[0])
definitions = parse_file(parser, path)
self.definition = definitions.GetChildren()[0]
def test_get_definitions(self):
pathfile = utilities.read_file_to_list(_FILE)
pathfile = [os.path.join(testdata_path, filename)
for filename in pathfile]
pathfile = [
os.path.join(testdata_path, filename) for filename in pathfile
]
for actual in collect_idls_into_json.get_definitions(pathfile):
self.assertEqual(actual.GetName(), self.definition.GetName())
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))
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):
filepath = collect_idls_into_json.get_filepath(self.definition)
......@@ -60,53 +66,85 @@ class TestFunctions(unittest.TestCase):
def test_const_node_to_dict(self):
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:
self.assertEqual(const.GetClass(), 'Const')
self.assertEqual(collect_idls_into_json.get_const_type(const), '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()))
self.assertEqual(
collect_idls_into_json.get_const_type(const),
'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:
self.assertEqual(const, None)
def test_attribute_node_to_dict(self):
attribute_member = set(['Name', 'Type', 'ExtAttributes', 'Readonly', 'Static'])
for attribute in collect_idls_into_json.get_attribute_node_list(self.definition):
attribute_member = set(
['Name', 'Type', 'ExtAttributes', 'Readonly', 'Static'])
for attribute in collect_idls_into_json.get_attribute_node_list(
self.definition):
if attribute:
self.assertEqual(attribute.GetClass(), 'Attribute')
self.assertEqual(attribute.GetName(), 'parentNode')
self.assertEqual(collect_idls_into_json.get_attribute_type(attribute), 'Node')
self.assertTrue(attribute_member.issuperset(collect_idls_into_json.attribute_node_to_dict(attribute).keys()))
self.assertEqual(
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:
self.assertEqual(attribute, None)
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'])
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:
self.assertEqual(operation.GetClass(), 'Operation')
self.assertEqual(operation.GetName(), 'appendChild')
self.assertEqual(collect_idls_into_json.get_operation_type(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):
self.assertEqual(
collect_idls_into_json.get_operation_type(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:
self.assertEqual(argument.GetClass(), 'Argument')
self.assertEqual(argument.GetName(), 'newChild')
self.assertEqual(collect_idls_into_json.get_argument_type(argument), 'Node')
self.assertTrue(argument_member.issuperset(collect_idls_into_json.argument_node_to_dict(argument).keys()))
self.assertEqual(
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:
self.assertEqual(argument, None)
else:
self.assertEqual(operation, None)
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:
self.assertEqual(extattr.GetClass(), 'ExtAttribute')
self.assertEqual(extattr.GetName(), 'CustomToV8')
self.assertEqual(collect_idls_into_json.extattr_node_to_dict(extattr).keys(), ['Name'])
self.assertEqual(collect_idls_into_json.extattr_node_to_dict(extattr).values(), ['CustomToV8'])
self.assertEqual(
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:
self.assertEqual(extattr, None)
......@@ -119,12 +157,17 @@ class TestFunctions(unittest.TestCase):
self.assertEqual(inherit, [])
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):
key_name = self.definition.GetName()
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']
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']
expected = [
'Source/core/timing/WorkerGlobalScopePerformance.idl',
'Source/core/timing/WorkerGlobalScopePerformance.idl',
......
......@@ -2,7 +2,6 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""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
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".
}
"""
EXTATTRIBUTES_AND_MEMBER_TYPES = ['ExtAttributes', 'Consts', 'Attributes', 'Operations']
EXTATTRIBUTES_AND_MEMBER_TYPES = [
'ExtAttributes', 'Consts', 'Attributes', 'Operations'
]
DIFF_INSENSITIVE_FIELDS = ['Name']
DIFF_TAG = 'diff_tag'
DIFF_TAG_ADDED = 'added'
......@@ -139,7 +139,8 @@ def interfaces_diff(old_interfaces, new_interfaces):
annotated = {}
for interface_name, interface in new_interfaces.items():
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:
annotated[interface_name] = annotated_interface
del old_interfaces[interface_name]
......@@ -166,8 +167,7 @@ def write_diff(diff, filepath):
def main(argv):
if len(argv) != 3:
sys.stdout.write(
'Usage: make_diff.py <old_file.json> <new_file.json> '
sys.stdout.write('Usage: make_diff.py <old_file.json> <new_file.json> '
'<diff_file.json>\n')
exit(1)
old_json_file = argv[0]
......
......@@ -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_ADDED
testdata_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'testdata')
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')
class TestGenerateIDLDiff(unittest.TestCase):
def setUp(self):
old = generate_idl_diff.load_json_file(old_data_path)
new = generate_idl_diff.load_json_file(new_data_path)
......
......@@ -2,7 +2,6 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Print a diff generated by generate_idl_diff.py.
Before printing, sort the diff in the alphabetical order or the order of
diffing tags.
......@@ -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_DELETED
# pylint: disable=W0105
"""Refer to the explanation of generate_idl_diff.py's input files.
The deffference between the input structure of generate_idl_diff.py and
......@@ -238,8 +236,8 @@ def sort_members_in_alphabetical_order(interface):
"""
sorted_interface = OrderedDict()
for member_type in EXTATTRIBUTES_AND_MEMBER_TYPES:
sorted_members = sorted(interface[member_type],
key=lambda member: member['Name'])
sorted_members = sorted(
interface[member_type], key=lambda member: member['Name'])
sorted_interface[member_type] = sorted_members
return sorted_interface
......@@ -323,6 +321,7 @@ def print_extattributes_in_member(extattributes, out):
Args:
A list of "ExtAttributes" in the "member" object
"""
def callback(extattribute):
out.write(extattribute['Name'])
......@@ -350,6 +349,7 @@ def print_arguments(arguments, out):
"""Print arguments in a "members" object named "Operations".
Args: A list of "Arguments"
"""
def callback(argument):
out.write(argument['Name'])
......@@ -407,7 +407,8 @@ def print_diff(diff, out):
def print_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):
......
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