Skip to content

Commit

Permalink
Fix styling errors in PRESUBMIT_test.py
Browse files Browse the repository at this point in the history
Most errors found by flake8 are fixed. The exceptions are:
- E111: indentation is not a multiple of four
- E121: continuation line under-indented for hanging indent
- E501: line too long (> 79 characters)

Bug: None
Change-Id: I6d85b3b170d5e0682e30c564e9dbaf185bb55168
Reviewed-on: https://chromium-review.googlesource.com/1152125
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578814}
  • Loading branch information
wychen authored and Commit Bot committed Jul 27, 2018
1 parent c1a2895 commit 54086c2
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
# found in the LICENSE file.

import os.path
import re
import subprocess
import unittest

import PRESUBMIT
from PRESUBMIT_test_mocks import MockChange, MockFile, MockAffectedFile
from PRESUBMIT_test_mocks import MockFile, MockAffectedFile
from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi


_TEST_DATA_DIR = 'base/test/data/presubmit'


class VersionControlConflictsTest(unittest.TestCase):
def testTypicalConflict(self):
lines = ['<<<<<<< HEAD',
Expand All @@ -38,6 +39,7 @@ def testIgnoresReadmes(self):
MockInputApi(), MockFile('some/polymer/README.md', lines))
self.assertEqual(0, len(errors))


class UmaHistogramChangeMatchedOrNotTest(unittest.TestCase):
def testTypicalCorrectlyMatchedChange(self):
diff_cc = ['UMA_HISTOGRAM_BOOL("Bla.Foo.Dummy", true)']
Expand Down Expand Up @@ -131,8 +133,8 @@ def testNameMatch(self):
# "Dummy\", true); // The \"correct"
diff_cc = ['UMA_HISTOGRAM_BOOL("Dummy", true); // The "correct" histogram']
diff_java = [
'RecordHistogram.recordBooleanHistogram("Dummy", true);'
+ ' // The "correct" histogram']
'RecordHistogram.recordBooleanHistogram("Dummy", true);' +
' // The "correct" histogram']
diff_xml = ['<histogram name="Dummy"> </histogram>']
mock_input_api = MockInputApi()
mock_input_api.files = [
Expand Down Expand Up @@ -177,6 +179,7 @@ def testMultiLine(self):
self.assertTrue('foo.cc' in warnings[0].items[0])
self.assertTrue('foo2.cc' in warnings[0].items[1])


class BadExtensionsTest(unittest.TestCase):
def testBadRejFile(self):
mock_input_api = MockInputApi()
Expand Down Expand Up @@ -225,7 +228,7 @@ def testSingletonInArbitraryHeader(self):
diff_bad_h = ['Foo* foo = base::Singleton<Foo>::get();']
mock_input_api = MockInputApi()
mock_input_api.files = [MockAffectedFile('base/memory/singleton.h',
diff_singleton_h),
diff_singleton_h),
MockAffectedFile('foo.h', diff_foo_h),
MockAffectedFile('foo2.h', diff_foo2_h),
MockAffectedFile('bad.h', diff_bad_h)]
Expand Down Expand Up @@ -274,14 +277,14 @@ def testInvalidIfDefinedMacroNames(self):
' # ifdef TARGET_IPHONE_SIMULATOR',
'# if defined(VALID) || defined(TARGET_IPHONE_SIMULATOR)',
'# else // defined(TARGET_IPHONE_SIMULATOR)',
'#endif // defined(TARGET_IPHONE_SIMULATOR)',]
'#endif // defined(TARGET_IPHONE_SIMULATOR)']
errors = PRESUBMIT._CheckForInvalidIfDefinedMacrosInFile(
MockInputApi(), MockFile('some/path/source.mm', lines))
self.assertEqual(len(lines), len(errors))

def testValidIfDefinedMacroNames(self):
lines = ['#if defined(FOO)',
'#ifdef BAR',]
'#ifdef BAR']
errors = PRESUBMIT._CheckForInvalidIfDefinedMacrosInFile(
MockInputApi(), MockFile('some/path/source.cc', lines))
self.assertEqual(0, len(errors))
Expand Down Expand Up @@ -391,7 +394,7 @@ def testFailure(self):
('invalid_json_4.json',
['{ "a": "b" "c": "d" }'],
'Expecting , delimiter:'),
]
]

input_api.files = [MockFile(filename, contents)
for (filename, contents, _) in test_data]
Expand Down Expand Up @@ -547,7 +550,7 @@ def testFailure(self):
' };',
'};'],
'Interface missing name.'),
]
]

input_api.files = [MockFile(filename, contents)
for (filename, contents, _) in test_data]
Expand Down Expand Up @@ -671,7 +674,6 @@ def testUserMetricsActionInActions(self):
self.assertEqual(
[], PRESUBMIT._CheckUserActionUpdate(input_api, MockOutputApi()))


def testUserMetricsActionNotAddedToActions(self):
input_api = MockInputApi()
file_with_user_action = 'file_with_user_action.cc'
Expand Down Expand Up @@ -824,6 +826,7 @@ def mock_check_output(cmd, shell=False, env=None):
self.assertTrue('File is stale' in str(results[0]))
self.assertTrue('File is stale' in str(results[1]))


class IncludeGuardTest(unittest.TestCase):
def testIncludeGuardChecks(self):
mock_input_api = MockInputApi()
Expand Down Expand Up @@ -950,40 +953,41 @@ def testIncludeGuardChecks(self):
self.assertEqual(expected_fail_count, len(msgs),
'Expected %d items, found %d: %s'
% (expected_fail_count, len(msgs), msgs))
self.assertEqual(msgs[0].items, [ 'content/browser/thing/bar.h' ])
self.assertEqual(msgs[0].items, ['content/browser/thing/bar.h'])
self.assertEqual(msgs[0].message,
'Include guard CONTENT_BROWSER_THING_BAR_H_ '
'not covering the whole file')

self.assertEqual(msgs[1].items, [ 'content/browser/test1.h' ])
self.assertEqual(msgs[1].items, ['content/browser/test1.h'])
self.assertEqual(msgs[1].message,
'Missing include guard CONTENT_BROWSER_TEST1_H_')

self.assertEqual(msgs[2].items, [ 'content/browser/test2.h:3' ])
self.assertEqual(msgs[2].items, ['content/browser/test2.h:3'])
self.assertEqual(msgs[2].message,
'Missing "#define CONTENT_BROWSER_TEST2_H_" for '
'include guard')

self.assertEqual(msgs[3].items, [ 'content/browser/spleling.h:1' ])
self.assertEqual(msgs[3].items, ['content/browser/spleling.h:1'])
self.assertEqual(msgs[3].message,
'Header using the wrong include guard name '
'CONTENT_BROWSER_SPLLEING_H_')

self.assertEqual(msgs[4].items, [ 'content/NotInBlink.h:1' ])
self.assertEqual(msgs[4].items, ['content/NotInBlink.h:1'])
self.assertEqual(msgs[4].message,
'Header using the wrong include guard name '
'NotInBlink_h')

self.assertEqual(msgs[5].items, [ 'third_party/blink/InBlink.h:1' ])
self.assertEqual(msgs[5].items, ['third_party/blink/InBlink.h:1'])
self.assertEqual(msgs[5].message,
'Header using the wrong include guard name '
'InBlink_h')

self.assertEqual(msgs[6].items, [ 'third_party/blink/AlsoInBlink.h:1' ])
self.assertEqual(msgs[6].items, ['third_party/blink/AlsoInBlink.h:1'])
self.assertEqual(msgs[6].message,
'Header using the wrong include guard name '
'WrongInBlink_h')


class AndroidDeprecatedTestAnnotationTest(unittest.TestCase):
def testCheckAndroidTestAnnotationUsage(self):
mock_input_api = MockInputApi()
Expand Down Expand Up @@ -1029,6 +1033,7 @@ def testCheckAndroidTestAnnotationUsage(self):
self.assertTrue('UsedDeprecatedSmokeAnnotation.java:1' in msgs[0].items,
'UsedDeprecatedSmokeAnnotation not found in errors')


class AndroidDeprecatedJUnitFrameworkTest(unittest.TestCase):
def testCheckAndroidTestJUnitFramework(self):
mock_input_api = MockInputApi()
Expand Down Expand Up @@ -1063,6 +1068,7 @@ def testCheckAndroidTestJUnitFramework(self):
in msgs[0].items,
'UsedDeprecatedJUnitAssert not found in errors')


class AndroidJUnitBaseClassTest(unittest.TestCase):
def testCheckAndroidTestJUnitBaseClass(self):
mock_input_api = MockInputApi()
Expand All @@ -1080,7 +1086,7 @@ def testCheckAndroidTestJUnitBaseClass(self):
MockAffectedFile('HistoricallyIncorrectTest.java', [
'public class Test extends BaseCaseA {',
'}',
], old_contents=[
], old_contents=[
'public class Test extends BaseCaseB {',
'}',
]),
Expand Down Expand Up @@ -1119,6 +1125,7 @@ def testCheckAndroidTestJUnitBaseClass(self):
self.assertTrue('IncorrectMultiLineTest.java:2' in msgs[0].items,
'IncorrectMultiLineTest not found in errors')


class LogUsageTest(unittest.TestCase):

def testCheckAndroidCrLogUsage(self):
Expand Down Expand Up @@ -1244,6 +1251,7 @@ def testCheckAndroidCrLogUsage(self):
self.assertTrue('HasDottedTag.java' in msgs[4].items)
self.assertTrue('HasOldTag.java' in msgs[4].items)


class GoogleAnswerUrlFormatTest(unittest.TestCase):

def testCatchAnswerUrlId(self):
Expand Down Expand Up @@ -1274,6 +1282,7 @@ def testAllowAnswerUrlParam(self):
input_api, MockOutputApi())
self.assertEqual(0, len(warnings))


class HardcodedGoogleHostsTest(unittest.TestCase):

def testWarnOnAssignedLiterals(self):
Expand Down Expand Up @@ -1316,7 +1325,7 @@ def testCheckHeadersOnlyOutsideThirdParty(self):
])
]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
MockOutputApi())
MockOutputApi())
self.assertEqual(0, len(warnings))

def testNoNestedDeclaration(self):
Expand All @@ -1330,7 +1339,7 @@ def testNoNestedDeclaration(self):
])
]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
MockOutputApi())
MockOutputApi())
self.assertEqual(0, len(warnings))

def testSubStrings(self):
Expand All @@ -1344,7 +1353,7 @@ def testSubStrings(self):
])
]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
MockOutputApi())
MockOutputApi())
self.assertEqual(2, len(warnings))

def testUselessForwardDeclaration(self):
Expand All @@ -1358,7 +1367,7 @@ def testUselessForwardDeclaration(self):
])
]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
MockOutputApi())
MockOutputApi())
self.assertEqual(2, len(warnings))

def testBlinkHeaders(self):
Expand All @@ -1374,7 +1383,7 @@ def testBlinkHeaders(self):
])
]
warnings = PRESUBMIT._CheckUselessForwardDeclarations(mock_input_api,
MockOutputApi())
MockOutputApi())
self.assertEqual(4, len(warnings))


Expand Down Expand Up @@ -1425,6 +1434,7 @@ def testConstLetWarningIos9Code(self):
mock_input_api, mock_output_api)
self.assertEqual(2, len(warnings))


class RelativeIncludesTest(unittest.TestCase):
def testThirdPartyNotWebKitIgnored(self):
mock_input_api = MockInputApi()
Expand Down Expand Up @@ -1547,7 +1557,7 @@ def testCheckCrbugLinksHaveHttps(self):

warnings = PRESUBMIT._CheckCrbugLinksHaveHttps(input_api, MockOutputApi())
self.assertEqual(1, len(warnings))
self.assertEqual(3, warnings[0].message.count('\n'));
self.assertEqual(3, warnings[0].message.count('\n'))


class BannedFunctionCheckTest(unittest.TestCase):
Expand Down Expand Up @@ -1611,11 +1621,11 @@ def testTruePositives(self):
mock_input_api.files = [
MockFile('dir/java/src/foo.java', ['FooForTesting();']),
MockFile('dir/java/src/bar.java', ['FooForTests(x);']),
MockFile('dir/java/src/baz.java', ['FooForTest(','y',');']),
MockFile('dir/java/src/baz.java', ['FooForTest(', 'y', ');']),
MockFile('dir/java/src/mult.java', [
'int x = SomethingLongHere()',
' * SomethingLongHereForTesting();'
]),
])
]

results = PRESUBMIT._CheckNoProductionCodeUsingTestOnlyFunctionsJava(
Expand All @@ -1634,8 +1644,8 @@ def testFalsePositives(self):
MockFile('dir/java/src/foo.java', ['FooForTests() {']),
MockFile('dir/java/src/bar.java', ['// FooForTest();']),
MockFile('dir/java/src/bar2.java', ['x = 1; // FooForTest();']),
MockFile('dir/javatests/src/baz.java', ['FooForTest(','y',');']),
MockFile('dir/junit/src/baz.java', ['FooForTest(','y',');']),
MockFile('dir/javatests/src/baz.java', ['FooForTest(', 'y', ');']),
MockFile('dir/junit/src/baz.java', ['FooForTest(', 'y', ');']),
MockFile('dir/junit/src/javadoc.java', [
'/** Use FooForTest(); to obtain foo in tests.'
' */'
Expand Down

0 comments on commit 54086c2

Please sign in to comment.