1# Copyright 2017 The LibYuv Project Authors. All rights reserved. 2# 3# Use of this source code is governed by a BSD-style license 4# that can be found in the LICENSE file in the root of the source 5# tree. An additional intellectual property rights grant can be found 6# in the file PATENTS. All contributing project authors may 7# be found in the AUTHORS file in the root of the source tree. 8 9import os 10 11 12def _RunPythonTests(input_api, output_api): 13 def join(*args): 14 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args) 15 16 test_directories = [ 17 root for root, _, files in os.walk(join('tools_libyuv')) 18 if any(f.endswith('_test.py') for f in files) 19 ] 20 21 tests = [] 22 for directory in test_directories: 23 tests.extend( 24 input_api.canned_checks.GetUnitTestsInDirectory( 25 input_api, 26 output_api, 27 directory, 28 whitelist=[r'.+_test\.py$'])) 29 return input_api.RunTests(tests, parallel=True) 30 31 32def _CommonChecks(input_api, output_api): 33 """Checks common to both upload and commit.""" 34 results = [] 35 results.extend(input_api.canned_checks.RunPylint(input_api, output_api, 36 black_list=(r'^base[\\\/].*\.py$', 37 r'^build[\\\/].*\.py$', 38 r'^buildtools[\\\/].*\.py$', 39 r'^ios[\\\/].*\.py$', 40 r'^out.*[\\\/].*\.py$', 41 r'^testing[\\\/].*\.py$', 42 r'^third_party[\\\/].*\.py$', 43 r'^tools[\\\/].*\.py$', 44 # TODO(kjellander): should arguably be checked. 45 r'^tools_libyuv[\\\/]valgrind[\\\/].*\.py$', 46 r'^xcodebuild.*[\\\/].*\.py$',), 47 disabled_warnings=['F0401', # Failed to import x 48 'E0611', # No package y in x 49 'W0232', # Class has no __init__ method 50 ], 51 pylintrc='pylintrc')) 52 results.extend(_RunPythonTests(input_api, output_api)) 53 return results 54 55 56def CheckChangeOnUpload(input_api, output_api): 57 results = [] 58 results.extend(_CommonChecks(input_api, output_api)) 59 results.extend( 60 input_api.canned_checks.CheckGNFormatted(input_api, output_api)) 61 return results 62 63 64def CheckChangeOnCommit(input_api, output_api): 65 results = [] 66 results.extend(_CommonChecks(input_api, output_api)) 67 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) 68 results.extend(input_api.canned_checks.CheckChangeWasUploaded( 69 input_api, output_api)) 70 results.extend(input_api.canned_checks.CheckChangeHasDescription( 71 input_api, output_api)) 72 return results 73