1#!/usr/bin/env vpython3 2# Copyright 2020 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Runs all python3-compatible tests in devil.""" 7 8import os 9import sys 10import unittest 11 12_DEVIL_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) 13_SIX_PATH = os.path.join(_DEVIL_PATH, '..', 'third_party', 'six') 14 15sys.path.append(_DEVIL_PATH) 16sys.path.append(_SIX_PATH) 17# Import compatible tests here by full module path 18import devil.android.apk_helper_test 19import devil.android.app_ui_test 20import devil.android.battery_utils_test 21import devil.android.cpu_temperature_test 22import devil.android.decorators_test 23import devil.android.device_denylist_test 24import devil.android.device_errors_test 25import devil.android.device_utils_test 26import devil.android.fastboot_utils_test 27import devil.android.flag_changer_test 28import devil.android.logcat_monitor_test 29import devil.android.md5sum_test 30import devil.android.perf.perf_control_test 31import devil.android.perf.surface_stats_collector_test 32import devil.android.sdk.adb_wrapper_test 33import devil.android.sdk.shared_prefs_test 34import devil.android.tools.device_monitor_test 35import devil.android.tools.script_common_test 36import devil.android.tools.system_app_test 37import devil.devil_env_test 38import devil.utils.cmd_helper_test 39import devil.utils.decorators_test 40import devil.utils.find_usb_devices_test 41import devil.utils.geometry_test 42import devil.utils.lazy.weak_constant_test 43import devil.utils.lsusb_test 44import devil.utils.markdown_test 45import devil.utils.mock_calls_test 46import devil.utils.parallelizer_test 47import devil.utils.reraiser_thread_unittest 48import devil.utils.timeout_retry_unittest 49import devil.utils.zip_utils_test 50 51PY3_COMPATIBLE_TESTS = [ 52 # Add full test module path here 53 devil.android.apk_helper_test, 54 devil.android.app_ui_test, 55 devil.android.battery_utils_test, 56 devil.android.cpu_temperature_test, 57 devil.android.decorators_test, 58 devil.android.device_denylist_test, 59 devil.android.device_errors_test, 60 devil.android.device_utils_test, 61 devil.android.fastboot_utils_test, 62 devil.android.flag_changer_test, 63 devil.android.logcat_monitor_test, 64 devil.android.md5sum_test, 65 devil.android.perf.perf_control_test, 66 devil.android.perf.surface_stats_collector_test, 67 devil.android.sdk.adb_wrapper_test, 68 devil.android.sdk.shared_prefs_test, 69 devil.android.tools.device_monitor_test, 70 devil.android.tools.script_common_test, 71 devil.android.tools.system_app_test, 72 devil.devil_env_test, 73 devil.utils.cmd_helper_test, 74 devil.utils.decorators_test, 75 devil.utils.find_usb_devices_test, 76 devil.utils.geometry_test, 77 devil.utils.lazy.weak_constant_test, 78 devil.utils.lsusb_test, 79 devil.utils.markdown_test, 80 devil.utils.mock_calls_test, 81 devil.utils.parallelizer_test, 82 devil.utils.reraiser_thread_unittest, 83 devil.utils.timeout_retry_unittest, 84 devil.utils.zip_utils_test, 85] 86 87 88def main(): 89 # TODO(crbug.com/1007101): Use six.PY2 directly once we're using six via 90 # vpython. 91 if sys.version_info[0] == 2: 92 print('Somehow running under python2.') 93 return 1 94 95 # Tests mock out internal details of methods, and the ANDROID_SERIAL can 96 # change which internal methods are called. Since tests don't actually use 97 # devices, it should be fine to delete the variable. 98 if 'ANDROID_SERIAL' in os.environ: 99 del os.environ['ANDROID_SERIAL'] 100 101 # This does not use typ for now, as typ has vpython dependencies that haven't 102 # yet been updated for python3. 103 result = unittest.TextTestRunner().run(unittest.TestSuite( 104 unittest.defaultTestLoader.loadTestsFromModule(test_module) 105 for test_module in PY3_COMPATIBLE_TESTS 106 )) 107 108 return 0 if result.wasSuccessful() else 1 109 110 111 112if __name__ == '__main__': 113 sys.exit(main()) 114