Commit 4fc8a212 authored by Fergal Daly's avatar Fergal Daly Committed by Commit Bot

Fix blink/PRESUBMIT_test

This test was using mock.py's assert_not_called method but that does
not exist in the version in third_party/pymock. The result is that the
assert call was mocked out, allowing the test to pass without actually
testing anything.

Fix is two-fold:
1 factor out the filtering code and test it directly
2 assert that .call_count is 0

Bug: 890657
Change-Id: Iffc6382ad0d9335a11c17f5ffe4d0c6ae6cbcf6c
Reviewed-on: https://chromium-review.googlesource.com/1253601
Commit-Queue: Fergal Daly <fergal@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595406}
parent 92605c16
......@@ -94,26 +94,34 @@ def _CommonChecks(input_api, output_api):
return results
def _CheckStyle(input_api, output_api):
style_checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'tools', 'check_blink_style.py')
args = [input_api.python_executable, style_checker_path, '--diff-files']
def _FilterPaths(input_api):
"""Returns input files with certain paths removed."""
files = []
for f in input_api.AffectedFiles():
file_path = f.LocalPath()
# Filter out changes in LayoutTests.
if 'web_tests' + input_api.os_path.sep in file_path and 'TestExpectations' not in file_path:
# Filter out changes in web_tests/.
if ('web_tests' + input_api.os_path.sep in file_path
and 'TestExpectations' not in file_path):
continue
if '/PRESUBMIT' in file_path:
continue
files.append(input_api.os_path.join('..', '..', file_path))
return files
def _CheckStyle(input_api, output_api):
files = _FilterPaths(input_api)
# Do not call check_blink_style.py with empty affected file list if all
# input_api.AffectedFiles got filtered.
if not files:
return []
style_checker_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
'tools', 'check_blink_style.py')
args = [input_api.python_executable, style_checker_path, '--diff-files']
args += files
results = []
results = []
try:
child = input_api.subprocess.Popen(args,
stderr=input_api.subprocess.PIPE)
......
......@@ -70,16 +70,35 @@ class PresubmitTest(unittest.TestCase):
diff_file_chromium2_h = ['another diff']
diff_file_layout_test_html = ['more diff']
mock_input_api = MockInputApi()
mock_input_api.files = [
MockAffectedFile('first_file_chromium.h', diff_file_chromium1_h),
MockAffectedFile('second_file_chromium.h', diff_file_chromium2_h),
MockAffectedFile('LayoutTests/some_tests.html', diff_file_layout_test_html)
]
mock_input_api.files = []
# Access to a protected member _CheckStyle
# pylint: disable=W0212
PRESUBMIT._CheckStyle(mock_input_api, MockOutputApi())
# pylint: disable=E1101
subprocess.Popen.assert_not_called()
self.assertEqual(0, subprocess.Popen.call_count)
def test_FilterPaths(self):
"""This verifies that _FilterPaths removes expected paths."""
diff_file_chromium1_h = ['some diff']
diff_web_tests_html = ['more diff']
diff_presubmit = ['morer diff']
diff_test_expectations = ['morest diff']
mock_input_api = MockInputApi()
mock_input_api.files = [
MockAffectedFile('file_chromium1.h', diff_file_chromium1_h),
MockAffectedFile('web_tests/some_tests.html', diff_web_tests_html),
MockAffectedFile('web_tests/TestExpectations', diff_test_expectations),
MockAffectedFile('blink/PRESUBMIT', diff_presubmit),
]
# Access to a protected member _FilterPaths
# pylint: disable=W0212
filtered = PRESUBMIT._FilterPaths(mock_input_api)
self.assertEqual(2, len(filtered))
self.assertEqual(
mock_input_api.os_path.join('..', '..', 'file_chromium1.h'),
filtered[0])
self.assertEqual(
mock_input_api.os_path.join('..', '..', 'web_tests/TestExpectations'),
filtered[1])
def testCheckPublicHeaderWithBlinkMojo(self):
"""This verifies that _CheckForWrongMojomIncludes detects -blink mojo
......
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