diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 553aa8119..a900a017d 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -10,6 +10,8 @@ details on the presubmit API built into depot_tools. PRESUBMIT_VERSION = '2.0.0' +USE_PYTHON3 = True + import fnmatch import os import sys @@ -85,17 +87,16 @@ def CheckRecipes(input_api, output_api): return input_api.canned_checks.CheckJsonParses(input_api, output_api, file_filter=file_filter) -def CheckPythonVersion(input_api, output_api): - # The tests here are assuming this is not defined, so raise an error - # if it is. - if 'USE_PYTHON3' in globals(): - return [output_api.PresubmitError( - 'USE_PYTHON3 is defined; update the tests in //PRESUBMIT.py and ' - '//tests/PRESUBMIT.py.')] - if sys.version_info.major != 2: - return [output_api.PresubmitError( - 'Did not use Python2 for //PRESUBMIT.py by default.')] - return [] + +def CheckUsePython3(input_api, output_api): + results = [] + + if sys.version_info.major != 3: + results.append( + output_api.PresubmitError( + 'Did not use Python3 for //tests/PRESUBMIT.py.')) + + return results def CheckJsonFiles(input_api, output_api): @@ -104,9 +105,22 @@ def CheckJsonFiles(input_api, output_api): def CheckUnitTestsOnCommit(input_api, output_api): - # Do not run integration tests on upload since they are way too slow. + """ Do not run integration tests on upload since they are way too slow.""" + input_api.SetTimeout(TEST_TIMEOUT_S) + # We still support python2 presubmit tests, so we need to test them. We don't + # run py3 here as the code below will start those tests + tests = input_api.canned_checks.GetUnitTestsInDirectory( + input_api, + output_api, + 'tests', + files_to_check=[ + r'.*presubmit_unittest\.py$', + ], + run_on_python2=True, + run_on_python3=False) + # Run only selected tests on Windows. test_to_run_list = [r'.*test\.py$'] tests_to_skip_list = [] @@ -120,40 +134,13 @@ def CheckUnitTestsOnCommit(input_api, output_api): r'.*ninjalog_uploader_test\.py$', r'.*recipes_test\.py$', ]) - py2_only_tests = [ - 'recipes_test.py', - ] - - py3_only_tests = [ - 'autoninja_test.py', - 'ninjalog_uploader_test.py', - ] - - tests = input_api.canned_checks.GetUnitTestsInDirectory( - input_api, - output_api, - 'tests', - files_to_check=test_to_run_list, - files_to_skip=tests_to_skip_list + py2_only_tests + py3_only_tests, - run_on_python3=True) - - # TODO: once py3 compatbile, remove those tests - tests.extend( - input_api.canned_checks.GetUnitTestsInDirectory( - input_api, - output_api, - 'tests', - files_to_check=py2_only_tests, - files_to_skip=tests_to_skip_list, - run_on_python3=False)) - # TODO: use this for all tests when py2 support is dropped. tests.extend( input_api.canned_checks.GetUnitTestsInDirectory( input_api, output_api, 'tests', - files_to_check=py3_only_tests, + files_to_check=test_to_run_list, files_to_skip=tests_to_skip_list, run_on_python3=True, run_on_python2=False)) diff --git a/tests/PRESUBMIT.py b/tests/PRESUBMIT.py index 6dfefcf94..5c0a3bd4b 100644 --- a/tests/PRESUBMIT.py +++ b/tests/PRESUBMIT.py @@ -6,14 +6,22 @@ import sys PRESUBMIT_VERSION = '2.0.0' -USE_PYTHON3 = True +# This file can be removed once py2 presubmit is no longer supported. This is +# an integration test to ensure py2 presubmit still works. -def CheckUsePython3(input_api, output_api): - results = [] - - if sys.version_info.major != 3: - results.append(output_api.PresubmitError( - 'Did not use Python3 for //tests/PRESUBMIT.py.')) - - return results +def CheckPythonVersion(input_api, output_api): + # The tests here are assuming this is not defined, so raise an error + # if it is. + if 'USE_PYTHON3' in globals(): + return [ + output_api.PresubmitError( + 'USE_PYTHON3 is defined; update the tests in //PRESUBMIT.py and ' + '//tests/PRESUBMIT.py.') + ] + if sys.version_info.major != 2: + return [ + output_api.PresubmitError( + 'Did not use Python2 for //PRESUBMIT.py by default.') + ] + return [] diff --git a/tests/owners_client_test.py b/tests/owners_client_test.py old mode 100644 new mode 100755 index 7c026c3e1..364c37853 --- a/tests/owners_client_test.py +++ b/tests/owners_client_test.py @@ -1,3 +1,4 @@ +#!/usr/bin/env vpython3 # Copyright (c) 2020 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. @@ -91,12 +92,12 @@ class GerritClientTest(unittest.TestCase): } ] }).start() - self.assertEquals( + self.assertEqual( ['approver@example.com', 'reviewer@example.com', 'missing@example.com'], self.client.ListOwners(os.path.join('bar', 'everyone', 'foo.txt'))) # Result should be cached. - self.assertEquals( + self.assertEqual( ['approver@example.com', 'reviewer@example.com', 'missing@example.com'], self.client.ListOwners(os.path.join('bar', 'everyone', 'foo.txt'))) # Always use slashes as separators. @@ -130,12 +131,9 @@ class GerritClientTest(unittest.TestCase): }, ] ).start() - self.assertEquals( - ['foo@example.com', self.client.EVERYONE], - self.client.ListOwners('foo.txt')) - self.assertEquals( - ['bar@example.com'], - self.client.ListOwners('bar.txt')) + self.assertEqual(['foo@example.com', self.client.EVERYONE], + self.client.ListOwners('foo.txt')) + self.assertEqual(['bar@example.com'], self.client.ListOwners('bar.txt')) class TestClient(owners_client.OwnersClient): @@ -280,7 +278,7 @@ class OwnersClientTest(unittest.TestCase): 'bar/foo/': [bob, chris] } - self.assertEquals( + self.assertEqual( { 'bar/everyone/foo.txt': [alice, bob], 'bar/everyone/bar.txt': [bob],