1*c2e18aaaSAndroid Build Coastguard Worker#!/usr/bin/env python3 2*c2e18aaaSAndroid Build Coastguard Worker# 3*c2e18aaaSAndroid Build Coastguard Worker# Copyright 2018, The Android Open Source Project 4*c2e18aaaSAndroid Build Coastguard Worker# 5*c2e18aaaSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*c2e18aaaSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*c2e18aaaSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*c2e18aaaSAndroid Build Coastguard Worker# 9*c2e18aaaSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*c2e18aaaSAndroid Build Coastguard Worker# 11*c2e18aaaSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*c2e18aaaSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*c2e18aaaSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*c2e18aaaSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*c2e18aaaSAndroid Build Coastguard Worker# limitations under the License. 16*c2e18aaaSAndroid Build Coastguard Worker 17*c2e18aaaSAndroid Build Coastguard Worker"""Unittests for module_info.""" 18*c2e18aaaSAndroid Build Coastguard Worker 19*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=invalid-name 20*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=missing-function-docstring 21*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=too-many-lines 22*c2e18aaaSAndroid Build Coastguard Worker 23*c2e18aaaSAndroid Build Coastguard Workerimport os 24*c2e18aaaSAndroid Build Coastguard Workerfrom pathlib import Path 25*c2e18aaaSAndroid Build Coastguard Workerimport shutil 26*c2e18aaaSAndroid Build Coastguard Workerimport tempfile 27*c2e18aaaSAndroid Build Coastguard Workerimport unittest 28*c2e18aaaSAndroid Build Coastguard Workerfrom unittest import mock 29*c2e18aaaSAndroid Build Coastguard Workerfrom atest import constants 30*c2e18aaaSAndroid Build Coastguard Workerfrom atest import module_info 31*c2e18aaaSAndroid Build Coastguard Workerfrom atest import unittest_constants as uc 32*c2e18aaaSAndroid Build Coastguard Workerfrom atest import unittest_utils 33*c2e18aaaSAndroid Build Coastguard Workerfrom pyfakefs import fake_filesystem_unittest 34*c2e18aaaSAndroid Build Coastguard Worker 35*c2e18aaaSAndroid Build Coastguard WorkerJSON_FILE_PATH = os.path.join(uc.TEST_DATA_DIR, uc.JSON_FILE) 36*c2e18aaaSAndroid Build Coastguard WorkerCC_DEP_PATH = os.path.join(uc.TEST_DATA_DIR, uc.CC_DEP_FILE) 37*c2e18aaaSAndroid Build Coastguard WorkerJAVA_DEP_PATH = os.path.join(uc.TEST_DATA_DIR, uc.JAVA_DEP_FILE) 38*c2e18aaaSAndroid Build Coastguard WorkerEXPECTED_MOD_TARGET = 'tradefed' 39*c2e18aaaSAndroid Build Coastguard WorkerEXPECTED_MOD_TARGET_PATH = ['tf/core'] 40*c2e18aaaSAndroid Build Coastguard WorkerUNEXPECTED_MOD_TARGET = 'this_should_not_be_in_module-info.json' 41*c2e18aaaSAndroid Build Coastguard WorkerMOD_NO_PATH = 'module-no-path' 42*c2e18aaaSAndroid Build Coastguard WorkerPATH_TO_MULT_MODULES = 'shared/path/to/be/used' 43*c2e18aaaSAndroid Build Coastguard WorkerMULT_MOODULES_WITH_SHARED_PATH = ['module2', 'module1'] 44*c2e18aaaSAndroid Build Coastguard WorkerPATH_TO_MULT_MODULES_WITH_MULTI_ARCH = 'shared/path/to/be/used2' 45*c2e18aaaSAndroid Build Coastguard WorkerTESTABLE_MODULES_WITH_SHARED_PATH = [ 46*c2e18aaaSAndroid Build Coastguard Worker 'multiarch1', 47*c2e18aaaSAndroid Build Coastguard Worker 'multiarch2', 48*c2e18aaaSAndroid Build Coastguard Worker 'multiarch3', 49*c2e18aaaSAndroid Build Coastguard Worker 'multiarch3_32', 50*c2e18aaaSAndroid Build Coastguard Worker] 51*c2e18aaaSAndroid Build Coastguard Worker 52*c2e18aaaSAndroid Build Coastguard WorkerROBO_MOD_PATH = ['/shared/robo/path'] 53*c2e18aaaSAndroid Build Coastguard WorkerROBO_MODULE = 'FooTests' 54*c2e18aaaSAndroid Build Coastguard WorkerASSOCIATED_ROBO_MODULE = 'RunFooTests' 55*c2e18aaaSAndroid Build Coastguard WorkerROBO_MODULE_INFO = { 56*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: ROBO_MODULE, 57*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: ROBO_MOD_PATH, 58*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_CLASS: [constants.MODULE_CLASS_JAVA_LIBRARIES], 59*c2e18aaaSAndroid Build Coastguard Worker} 60*c2e18aaaSAndroid Build Coastguard WorkerASSOCIATED_ROBO_MODULE_INFO = { 61*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: ASSOCIATED_ROBO_MODULE, 62*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: ROBO_MOD_PATH, 63*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_CLASS: [constants.MODULE_CLASS_ROBOLECTRIC], 64*c2e18aaaSAndroid Build Coastguard Worker} 65*c2e18aaaSAndroid Build Coastguard WorkerMOD_PATH_INFO_DICT = { 66*c2e18aaaSAndroid Build Coastguard Worker ROBO_MOD_PATH[0]: [ASSOCIATED_ROBO_MODULE_INFO, ROBO_MODULE_INFO] 67*c2e18aaaSAndroid Build Coastguard Worker} 68*c2e18aaaSAndroid Build Coastguard WorkerMOD_NAME_INFO_DICT = { 69*c2e18aaaSAndroid Build Coastguard Worker ASSOCIATED_ROBO_MODULE: ASSOCIATED_ROBO_MODULE_INFO, 70*c2e18aaaSAndroid Build Coastguard Worker ROBO_MODULE: ROBO_MODULE_INFO, 71*c2e18aaaSAndroid Build Coastguard Worker} 72*c2e18aaaSAndroid Build Coastguard WorkerMOD_NAME1 = 'mod1' 73*c2e18aaaSAndroid Build Coastguard WorkerMOD_NAME2 = 'mod2' 74*c2e18aaaSAndroid Build Coastguard WorkerMOD_NAME3 = 'mod3' 75*c2e18aaaSAndroid Build Coastguard WorkerMOD_NAME4 = 'mod4' 76*c2e18aaaSAndroid Build Coastguard WorkerMOD_INFO_DICT = {} 77*c2e18aaaSAndroid Build Coastguard WorkerMODULE_INFO = { 78*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: 'random_name', 79*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: 'a/b/c/path', 80*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_CLASS: ['random_class'], 81*c2e18aaaSAndroid Build Coastguard Worker} 82*c2e18aaaSAndroid Build Coastguard WorkerNAME_TO_MODULE_INFO = {'random_name': MODULE_INFO} 83*c2e18aaaSAndroid Build Coastguard Worker 84*c2e18aaaSAndroid Build Coastguard WorkerMOBLY_MODULE = 'mobly-test' 85*c2e18aaaSAndroid Build Coastguard WorkerMOBLY_MODULE_NO_TAG = 'mobly-test-no-tag' 86*c2e18aaaSAndroid Build Coastguard Worker 87*c2e18aaaSAndroid Build Coastguard Worker# Mocking path allows str only, use os.path instead of Path. 88*c2e18aaaSAndroid Build Coastguard Workerwith tempfile.TemporaryDirectory() as temp_dir: 89*c2e18aaaSAndroid Build Coastguard Worker BUILD_TOP_DIR = temp_dir 90*c2e18aaaSAndroid Build Coastguard WorkerSOONG_OUT_DIR = os.path.join(BUILD_TOP_DIR, 'out/soong') 91*c2e18aaaSAndroid Build Coastguard WorkerPRODUCT_OUT_DIR = os.path.join(BUILD_TOP_DIR, 'out/target/product/vsoc_x86_64') 92*c2e18aaaSAndroid Build Coastguard WorkerHOST_OUT_DIR = os.path.join(BUILD_TOP_DIR, 'out/host/linux-x86') 93*c2e18aaaSAndroid Build Coastguard Worker 94*c2e18aaaSAndroid Build Coastguard Worker 95*c2e18aaaSAndroid Build Coastguard Worker# TODO: (b/263199608) Suppress too-many-public-methods after refactoring. 96*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=protected-access, too-many-public-methods 97*c2e18aaaSAndroid Build Coastguard Workerclass ModuleInfoUnittests(unittest.TestCase): 98*c2e18aaaSAndroid Build Coastguard Worker """Unit tests for module_info.py""" 99*c2e18aaaSAndroid Build Coastguard Worker 100*c2e18aaaSAndroid Build Coastguard Worker def setUp(self) -> None: 101*c2e18aaaSAndroid Build Coastguard Worker for path in [BUILD_TOP_DIR, PRODUCT_OUT_DIR, SOONG_OUT_DIR, HOST_OUT_DIR]: 102*c2e18aaaSAndroid Build Coastguard Worker if not Path(path).is_dir(): 103*c2e18aaaSAndroid Build Coastguard Worker Path(path).mkdir(parents=True) 104*c2e18aaaSAndroid Build Coastguard Worker shutil.copy2(JSON_FILE_PATH, PRODUCT_OUT_DIR) 105*c2e18aaaSAndroid Build Coastguard Worker self.json_file_path = Path(PRODUCT_OUT_DIR).joinpath(uc.JSON_FILE) 106*c2e18aaaSAndroid Build Coastguard Worker shutil.copy2(CC_DEP_PATH, SOONG_OUT_DIR) 107*c2e18aaaSAndroid Build Coastguard Worker self.cc_dep_path = Path(SOONG_OUT_DIR).joinpath(uc.CC_DEP_FILE) 108*c2e18aaaSAndroid Build Coastguard Worker shutil.copy2(JAVA_DEP_PATH, SOONG_OUT_DIR) 109*c2e18aaaSAndroid Build Coastguard Worker self.java_dep_path = Path(SOONG_OUT_DIR).joinpath(uc.JAVA_DEP_FILE) 110*c2e18aaaSAndroid Build Coastguard Worker self.merged_dep_path = Path(PRODUCT_OUT_DIR).joinpath(uc.MERGED_DEP_FILE) 111*c2e18aaaSAndroid Build Coastguard Worker 112*c2e18aaaSAndroid Build Coastguard Worker def tearDown(self) -> None: 113*c2e18aaaSAndroid Build Coastguard Worker if self.merged_dep_path.is_file(): 114*c2e18aaaSAndroid Build Coastguard Worker os.remove(self.merged_dep_path) 115*c2e18aaaSAndroid Build Coastguard Worker 116*c2e18aaaSAndroid Build Coastguard Worker def test_target_name_is_relative_to_build_top(self): 117*c2e18aaaSAndroid Build Coastguard Worker build_top = '/src/build_top' 118*c2e18aaaSAndroid Build Coastguard Worker product_out = '/src/build_top/pout' 119*c2e18aaaSAndroid Build Coastguard Worker env_mock = { 120*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: build_top, 121*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: product_out, 122*c2e18aaaSAndroid Build Coastguard Worker } 123*c2e18aaaSAndroid Build Coastguard Worker expected_target = os.path.relpath( 124*c2e18aaaSAndroid Build Coastguard Worker os.path.join(product_out, 'module-info.json'), build_top 125*c2e18aaaSAndroid Build Coastguard Worker ) 126*c2e18aaaSAndroid Build Coastguard Worker 127*c2e18aaaSAndroid Build Coastguard Worker with mock.patch.dict('os.environ', env_mock, clear=True): 128*c2e18aaaSAndroid Build Coastguard Worker actual_target = module_info.get_module_info_target() 129*c2e18aaaSAndroid Build Coastguard Worker 130*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(actual_target, expected_target) 131*c2e18aaaSAndroid Build Coastguard Worker 132*c2e18aaaSAndroid Build Coastguard Worker def test_target_name_is_in_absolute_path(self): 133*c2e18aaaSAndroid Build Coastguard Worker build_top = '/src/build_top' 134*c2e18aaaSAndroid Build Coastguard Worker product_out = '/somewhere/pout' 135*c2e18aaaSAndroid Build Coastguard Worker env_mock = { 136*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: build_top, 137*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: product_out, 138*c2e18aaaSAndroid Build Coastguard Worker } 139*c2e18aaaSAndroid Build Coastguard Worker expected_target = os.path.join(product_out, 'module-info.json') 140*c2e18aaaSAndroid Build Coastguard Worker 141*c2e18aaaSAndroid Build Coastguard Worker with mock.patch.dict('os.environ', env_mock, clear=True): 142*c2e18aaaSAndroid Build Coastguard Worker actual_target = module_info.get_module_info_target() 143*c2e18aaaSAndroid Build Coastguard Worker 144*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(actual_target, expected_target) 145*c2e18aaaSAndroid Build Coastguard Worker 146*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(module_info.Loader, 'load') 147*c2e18aaaSAndroid Build Coastguard Worker def test_get_path_to_module_info(self, mock_load_module): 148*c2e18aaaSAndroid Build Coastguard Worker """Test that we correctly create the path to module info dict.""" 149*c2e18aaaSAndroid Build Coastguard Worker mod_one = 'mod1' 150*c2e18aaaSAndroid Build Coastguard Worker mod_two = 'mod2' 151*c2e18aaaSAndroid Build Coastguard Worker mod_path_one = '/path/to/mod1' 152*c2e18aaaSAndroid Build Coastguard Worker mod_path_two = '/path/to/mod2' 153*c2e18aaaSAndroid Build Coastguard Worker mod_info_dict = { 154*c2e18aaaSAndroid Build Coastguard Worker mod_one: { 155*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: [mod_path_one], 156*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: mod_one, 157*c2e18aaaSAndroid Build Coastguard Worker }, 158*c2e18aaaSAndroid Build Coastguard Worker mod_two: { 159*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: [mod_path_two], 160*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: mod_two, 161*c2e18aaaSAndroid Build Coastguard Worker }, 162*c2e18aaaSAndroid Build Coastguard Worker } 163*c2e18aaaSAndroid Build Coastguard Worker mock_load_module.return_value = mod_info_dict 164*c2e18aaaSAndroid Build Coastguard Worker path_to_mod_info = { 165*c2e18aaaSAndroid Build Coastguard Worker mod_path_one: [{ 166*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: mod_one, 167*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: [mod_path_one], 168*c2e18aaaSAndroid Build Coastguard Worker }], 169*c2e18aaaSAndroid Build Coastguard Worker mod_path_two: [{ 170*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: mod_two, 171*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_PATH: [mod_path_two], 172*c2e18aaaSAndroid Build Coastguard Worker }], 173*c2e18aaaSAndroid Build Coastguard Worker } 174*c2e18aaaSAndroid Build Coastguard Worker self.assertDictEqual( 175*c2e18aaaSAndroid Build Coastguard Worker path_to_mod_info, module_info.get_path_to_module_info(mod_info_dict) 176*c2e18aaaSAndroid Build Coastguard Worker ) 177*c2e18aaaSAndroid Build Coastguard Worker 178*c2e18aaaSAndroid Build Coastguard Worker def test_is_module(self): 179*c2e18aaaSAndroid Build Coastguard Worker """Test that we get the module when it's properly loaded.""" 180*c2e18aaaSAndroid Build Coastguard Worker # Load up the test json file and check that module is in it 181*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 182*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_module(EXPECTED_MOD_TARGET)) 183*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_module(UNEXPECTED_MOD_TARGET)) 184*c2e18aaaSAndroid Build Coastguard Worker 185*c2e18aaaSAndroid Build Coastguard Worker def test_get_path(self): 186*c2e18aaaSAndroid Build Coastguard Worker """Test that we get the module path when it's properly loaded.""" 187*c2e18aaaSAndroid Build Coastguard Worker # Load up the test json file and check that module is in it 188*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 189*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 190*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_paths(EXPECTED_MOD_TARGET), EXPECTED_MOD_TARGET_PATH 191*c2e18aaaSAndroid Build Coastguard Worker ) 192*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(mod_info.get_paths(MOD_NO_PATH), []) 193*c2e18aaaSAndroid Build Coastguard Worker 194*c2e18aaaSAndroid Build Coastguard Worker def test_get_module_names(self): 195*c2e18aaaSAndroid Build Coastguard Worker """test that we get the module name properly.""" 196*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 197*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 198*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_module_names(EXPECTED_MOD_TARGET_PATH[0]), 199*c2e18aaaSAndroid Build Coastguard Worker [EXPECTED_MOD_TARGET], 200*c2e18aaaSAndroid Build Coastguard Worker ) 201*c2e18aaaSAndroid Build Coastguard Worker unittest_utils.assert_strict_equal( 202*c2e18aaaSAndroid Build Coastguard Worker self, 203*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_module_names(PATH_TO_MULT_MODULES), 204*c2e18aaaSAndroid Build Coastguard Worker MULT_MOODULES_WITH_SHARED_PATH, 205*c2e18aaaSAndroid Build Coastguard Worker ) 206*c2e18aaaSAndroid Build Coastguard Worker 207*c2e18aaaSAndroid Build Coastguard Worker def test_path_to_mod_info(self): 208*c2e18aaaSAndroid Build Coastguard Worker """test that we get the module name properly.""" 209*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 210*c2e18aaaSAndroid Build Coastguard Worker module_list = [] 211*c2e18aaaSAndroid Build Coastguard Worker for path_to_mod_info in mod_info.path_to_module_info[ 212*c2e18aaaSAndroid Build Coastguard Worker PATH_TO_MULT_MODULES_WITH_MULTI_ARCH 213*c2e18aaaSAndroid Build Coastguard Worker ]: 214*c2e18aaaSAndroid Build Coastguard Worker module_list.append(path_to_mod_info.get(constants.MODULE_NAME)) 215*c2e18aaaSAndroid Build Coastguard Worker module_list.sort() 216*c2e18aaaSAndroid Build Coastguard Worker TESTABLE_MODULES_WITH_SHARED_PATH.sort() 217*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(module_list, TESTABLE_MODULES_WITH_SHARED_PATH) 218*c2e18aaaSAndroid Build Coastguard Worker 219*c2e18aaaSAndroid Build Coastguard Worker def test_is_suite_in_compatibility_suites(self): 220*c2e18aaaSAndroid Build Coastguard Worker """Test is_suite_in_compatibility_suites.""" 221*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 222*c2e18aaaSAndroid Build Coastguard Worker info = {'compatibility_suites': []} 223*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_suite_in_compatibility_suites('cts', info)) 224*c2e18aaaSAndroid Build Coastguard Worker info2 = {'compatibility_suites': ['cts']} 225*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_suite_in_compatibility_suites('cts', info2)) 226*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_suite_in_compatibility_suites('vts10', info2)) 227*c2e18aaaSAndroid Build Coastguard Worker info3 = {'compatibility_suites': ['cts', 'vts10']} 228*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_suite_in_compatibility_suites('cts', info3)) 229*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_suite_in_compatibility_suites('vts10', info3)) 230*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_suite_in_compatibility_suites('ats', info3)) 231*c2e18aaaSAndroid Build Coastguard Worker 232*c2e18aaaSAndroid Build Coastguard Worker def test_get_testable_modules(self): 233*c2e18aaaSAndroid Build Coastguard Worker """Test get_testable_modules.""" 234*c2e18aaaSAndroid Build Coastguard Worker expected_testable_modules = {'Module1', 'Module2', 'Module3'} 235*c2e18aaaSAndroid Build Coastguard Worker expected_test_suite_modules = {'Module1', 'Module2'} 236*c2e18aaaSAndroid Build Coastguard Worker expected_null_suite_modules = {'Module3'} 237*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info( 238*c2e18aaaSAndroid Build Coastguard Worker modules=[ 239*c2e18aaaSAndroid Build Coastguard Worker test_module(name='Module1', compatibility_suites=['test-suite']), 240*c2e18aaaSAndroid Build Coastguard Worker test_module(name='Module2', compatibility_suites=['test-suite']), 241*c2e18aaaSAndroid Build Coastguard Worker test_module(name='Module3'), 242*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name='Dep1'), 243*c2e18aaaSAndroid Build Coastguard Worker ] 244*c2e18aaaSAndroid Build Coastguard Worker ) 245*c2e18aaaSAndroid Build Coastguard Worker 246*c2e18aaaSAndroid Build Coastguard Worker actual_all_testable_modules = mod_info.get_testable_modules() 247*c2e18aaaSAndroid Build Coastguard Worker actual_test_suite_modules = mod_info.get_testable_modules('test-suite') 248*c2e18aaaSAndroid Build Coastguard Worker actual_null_suite_modules = mod_info.get_testable_modules('null-suite') 249*c2e18aaaSAndroid Build Coastguard Worker 250*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(actual_all_testable_modules, expected_testable_modules) 251*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(actual_test_suite_modules, expected_test_suite_modules) 252*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(actual_null_suite_modules, expected_null_suite_modules) 253*c2e18aaaSAndroid Build Coastguard Worker 254*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 255*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 256*c2e18aaaSAndroid Build Coastguard Worker { 257*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: '/', 258*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 259*c2e18aaaSAndroid Build Coastguard Worker }, 260*c2e18aaaSAndroid Build Coastguard Worker ) 261*c2e18aaaSAndroid Build Coastguard Worker def test_is_mobly_test(self): 262*c2e18aaaSAndroid Build Coastguard Worker """Test is_mobly_test.""" 263*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 264*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue( 265*c2e18aaaSAndroid Build Coastguard Worker mod_info.is_mobly_module(mod_info.get_module_info(MOBLY_MODULE)) 266*c2e18aaaSAndroid Build Coastguard Worker ) 267*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse( 268*c2e18aaaSAndroid Build Coastguard Worker mod_info.is_mobly_module(mod_info.get_module_info(MOBLY_MODULE_NO_TAG)) 269*c2e18aaaSAndroid Build Coastguard Worker ) 270*c2e18aaaSAndroid Build Coastguard Worker 271*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 272*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 273*c2e18aaaSAndroid Build Coastguard Worker { 274*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: '/', 275*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 276*c2e18aaaSAndroid Build Coastguard Worker }, 277*c2e18aaaSAndroid Build Coastguard Worker ) 278*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(module_info.ModuleInfo, 'get_robolectric_type') 279*c2e18aaaSAndroid Build Coastguard Worker def test_is_robolectric_test(self, mock_type): 280*c2e18aaaSAndroid Build Coastguard Worker """Test is_robolectric_test.""" 281*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 282*c2e18aaaSAndroid Build Coastguard Worker mock_type.return_value = constants.ROBOTYPE_MODERN 283*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_robolectric_test(ROBO_MODULE)) 284*c2e18aaaSAndroid Build Coastguard Worker mock_type.return_value = constants.ROBOTYPE_LEGACY 285*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_robolectric_test(ROBO_MODULE)) 286*c2e18aaaSAndroid Build Coastguard Worker mock_type.return_value = 0 287*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_robolectric_test(ROBO_MODULE)) 288*c2e18aaaSAndroid Build Coastguard Worker 289*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(module_info.ModuleInfo, 'is_module') 290*c2e18aaaSAndroid Build Coastguard Worker def test_is_auto_gen_test_config(self, mock_is_module): 291*c2e18aaaSAndroid Build Coastguard Worker """Test is_auto_gen_test_config correctly detects the module.""" 292*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 293*c2e18aaaSAndroid Build Coastguard Worker mock_is_module.return_value = True 294*c2e18aaaSAndroid Build Coastguard Worker is_auto_test_config = {'auto_test_config': [True]} 295*c2e18aaaSAndroid Build Coastguard Worker is_not_auto_test_config = {'auto_test_config': [False]} 296*c2e18aaaSAndroid Build Coastguard Worker is_not_auto_test_config_again = {'auto_test_config': []} 297*c2e18aaaSAndroid Build Coastguard Worker MOD_INFO_DICT[MOD_NAME1] = is_auto_test_config 298*c2e18aaaSAndroid Build Coastguard Worker MOD_INFO_DICT[MOD_NAME2] = is_not_auto_test_config 299*c2e18aaaSAndroid Build Coastguard Worker MOD_INFO_DICT[MOD_NAME3] = is_not_auto_test_config_again 300*c2e18aaaSAndroid Build Coastguard Worker MOD_INFO_DICT[MOD_NAME4] = {} 301*c2e18aaaSAndroid Build Coastguard Worker mod_info.name_to_module_info = MOD_INFO_DICT 302*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_auto_gen_test_config(MOD_NAME1)) 303*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_auto_gen_test_config(MOD_NAME2)) 304*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_auto_gen_test_config(MOD_NAME3)) 305*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.is_auto_gen_test_config(MOD_NAME4)) 306*c2e18aaaSAndroid Build Coastguard Worker 307*c2e18aaaSAndroid Build Coastguard Worker def test_merge_build_system_infos(self): 308*c2e18aaaSAndroid Build Coastguard Worker """Test _merge_build_system_infos.""" 309*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 310*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 311*c2e18aaaSAndroid Build Coastguard Worker ) 312*c2e18aaaSAndroid Build Coastguard Worker mod_info_1 = { 313*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: 'module_1', 314*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_DEPENDENCIES: [], 315*c2e18aaaSAndroid Build Coastguard Worker } 316*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = {'module_1': mod_info_1} 317*c2e18aaaSAndroid Build Coastguard Worker expect_deps = ['test_dep_level_1_1', 'test_dep_level_1_2'] 318*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = loader._merge_build_system_infos( 319*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info, java_bp_info_path=self.java_dep_path 320*c2e18aaaSAndroid Build Coastguard Worker ) 321*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 322*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info['module_1'].get(constants.MODULE_DEPENDENCIES), 323*c2e18aaaSAndroid Build Coastguard Worker expect_deps, 324*c2e18aaaSAndroid Build Coastguard Worker ) 325*c2e18aaaSAndroid Build Coastguard Worker 326*c2e18aaaSAndroid Build Coastguard Worker def test_merge_build_system_infos_missing_keys(self): 327*c2e18aaaSAndroid Build Coastguard Worker """Test _merge_build_system_infos for keys missing from module-info.json.""" 328*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 329*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 330*c2e18aaaSAndroid Build Coastguard Worker ) 331*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = loader._merge_build_system_infos( 332*c2e18aaaSAndroid Build Coastguard Worker {}, java_bp_info_path=self.java_dep_path 333*c2e18aaaSAndroid Build Coastguard Worker ) 334*c2e18aaaSAndroid Build Coastguard Worker 335*c2e18aaaSAndroid Build Coastguard Worker expect_deps = ['test_dep_level_1_1'] 336*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 337*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info['not_in_module_info'].get( 338*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_DEPENDENCIES 339*c2e18aaaSAndroid Build Coastguard Worker ), 340*c2e18aaaSAndroid Build Coastguard Worker expect_deps, 341*c2e18aaaSAndroid Build Coastguard Worker ) 342*c2e18aaaSAndroid Build Coastguard Worker 343*c2e18aaaSAndroid Build Coastguard Worker def test_merge_dependency_with_ori_dependency(self): 344*c2e18aaaSAndroid Build Coastguard Worker """Test _merge_dependency.""" 345*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 346*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 347*c2e18aaaSAndroid Build Coastguard Worker ) 348*c2e18aaaSAndroid Build Coastguard Worker mod_info_1 = { 349*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: 'module_1', 350*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_DEPENDENCIES: ['ori_dep_1'], 351*c2e18aaaSAndroid Build Coastguard Worker } 352*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = {'module_1': mod_info_1} 353*c2e18aaaSAndroid Build Coastguard Worker expect_deps = ['ori_dep_1', 'test_dep_level_1_1', 'test_dep_level_1_2'] 354*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = loader._merge_build_system_infos( 355*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info, java_bp_info_path=self.java_dep_path 356*c2e18aaaSAndroid Build Coastguard Worker ) 357*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 358*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info['module_1'].get(constants.MODULE_DEPENDENCIES), 359*c2e18aaaSAndroid Build Coastguard Worker expect_deps, 360*c2e18aaaSAndroid Build Coastguard Worker ) 361*c2e18aaaSAndroid Build Coastguard Worker 362*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 363*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 364*c2e18aaaSAndroid Build Coastguard Worker { 365*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: uc.TEST_DATA_DIR, 366*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 367*c2e18aaaSAndroid Build Coastguard Worker }, 368*c2e18aaaSAndroid Build Coastguard Worker ) 369*c2e18aaaSAndroid Build Coastguard Worker def test_get_instrumentation_target_apps(self): 370*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 371*c2e18aaaSAndroid Build Coastguard Worker artifacts = { 372*c2e18aaaSAndroid Build Coastguard Worker 'AmSlam': { 373*c2e18aaaSAndroid Build Coastguard Worker os.path.join( 374*c2e18aaaSAndroid Build Coastguard Worker uc.TEST_DATA_DIR, 375*c2e18aaaSAndroid Build Coastguard Worker 'out/target/product/generic/data/app/AmSlam/AmSlam.apk', 376*c2e18aaaSAndroid Build Coastguard Worker ) 377*c2e18aaaSAndroid Build Coastguard Worker } 378*c2e18aaaSAndroid Build Coastguard Worker } 379*c2e18aaaSAndroid Build Coastguard Worker # 1. If Android.bp is available, use `manifest` to determine the actual 380*c2e18aaaSAndroid Build Coastguard Worker # manifest. 381*c2e18aaaSAndroid Build Coastguard Worker bp_context = """android_test { 382*c2e18aaaSAndroid Build Coastguard Worker name: "AmSlamTests", 383*c2e18aaaSAndroid Build Coastguard Worker manifest: 'AndroidManifest.xml', 384*c2e18aaaSAndroid Build Coastguard Worker instrumentation_for: "AmSlam" 385*c2e18aaaSAndroid Build Coastguard Worker }""" 386*c2e18aaaSAndroid Build Coastguard Worker bp_file = os.path.join(uc.TEST_DATA_DIR, 'foo/bar/AmSlam/test/Android.bp') 387*c2e18aaaSAndroid Build Coastguard Worker with open(bp_file, 'w', encoding='utf-8') as cache: 388*c2e18aaaSAndroid Build Coastguard Worker cache.write(bp_context) 389*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 390*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_instrumentation_target_apps('AmSlamTests'), artifacts 391*c2e18aaaSAndroid Build Coastguard Worker ) 392*c2e18aaaSAndroid Build Coastguard Worker os.remove(bp_file) 393*c2e18aaaSAndroid Build Coastguard Worker # 2. If Android.bp is unavailable, search `AndroidManifest.xml` 394*c2e18aaaSAndroid Build Coastguard Worker # arbitrarily. 395*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 396*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_instrumentation_target_apps('AmSlamTests'), artifacts 397*c2e18aaaSAndroid Build Coastguard Worker ) 398*c2e18aaaSAndroid Build Coastguard Worker 399*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 400*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 401*c2e18aaaSAndroid Build Coastguard Worker { 402*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: uc.TEST_DATA_DIR, 403*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 404*c2e18aaaSAndroid Build Coastguard Worker }, 405*c2e18aaaSAndroid Build Coastguard Worker ) 406*c2e18aaaSAndroid Build Coastguard Worker def test_get_target_module_by_pkg(self): 407*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 408*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 409*c2e18aaaSAndroid Build Coastguard Worker 'AmSlam', 410*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_target_module_by_pkg( 411*c2e18aaaSAndroid Build Coastguard Worker package='c0m.andr0id.settingS', 412*c2e18aaaSAndroid Build Coastguard Worker search_from=Path(uc.TEST_DATA_DIR).joinpath('foo/bar/AmSlam/test'), 413*c2e18aaaSAndroid Build Coastguard Worker ), 414*c2e18aaaSAndroid Build Coastguard Worker ) 415*c2e18aaaSAndroid Build Coastguard Worker 416*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 417*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 418*c2e18aaaSAndroid Build Coastguard Worker { 419*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: uc.TEST_DATA_DIR, 420*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 421*c2e18aaaSAndroid Build Coastguard Worker }, 422*c2e18aaaSAndroid Build Coastguard Worker ) 423*c2e18aaaSAndroid Build Coastguard Worker def test_get_artifact_map(self): 424*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 425*c2e18aaaSAndroid Build Coastguard Worker artifacts = { 426*c2e18aaaSAndroid Build Coastguard Worker 'AmSlam': { 427*c2e18aaaSAndroid Build Coastguard Worker os.path.join( 428*c2e18aaaSAndroid Build Coastguard Worker uc.TEST_DATA_DIR, 429*c2e18aaaSAndroid Build Coastguard Worker 'out/target/product/generic/data/app/AmSlam/AmSlam.apk', 430*c2e18aaaSAndroid Build Coastguard Worker ) 431*c2e18aaaSAndroid Build Coastguard Worker } 432*c2e18aaaSAndroid Build Coastguard Worker } 433*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(mod_info.get_artifact_map('AmSlam'), artifacts) 434*c2e18aaaSAndroid Build Coastguard Worker 435*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 436*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 437*c2e18aaaSAndroid Build Coastguard Worker { 438*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: uc.TEST_DATA_DIR, 439*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 440*c2e18aaaSAndroid Build Coastguard Worker }, 441*c2e18aaaSAndroid Build Coastguard Worker ) 442*c2e18aaaSAndroid Build Coastguard Worker def test_get_filepath_from_module(self): 443*c2e18aaaSAndroid Build Coastguard Worker """Test for get_filepath_from_module.""" 444*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 445*c2e18aaaSAndroid Build Coastguard Worker 446*c2e18aaaSAndroid Build Coastguard Worker expected_filepath = Path(uc.TEST_DATA_DIR).joinpath( 447*c2e18aaaSAndroid Build Coastguard Worker 'foo/bar/AmSlam', 'AndroidManifest.xml' 448*c2e18aaaSAndroid Build Coastguard Worker ) 449*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 450*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_filepath_from_module('AmSlam', 'AndroidManifest.xml'), 451*c2e18aaaSAndroid Build Coastguard Worker expected_filepath, 452*c2e18aaaSAndroid Build Coastguard Worker ) 453*c2e18aaaSAndroid Build Coastguard Worker 454*c2e18aaaSAndroid Build Coastguard Worker expected_filepath = Path(uc.TEST_DATA_DIR).joinpath( 455*c2e18aaaSAndroid Build Coastguard Worker 'foo/bar/AmSlam/test', 'AndroidManifest.xml' 456*c2e18aaaSAndroid Build Coastguard Worker ) 457*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 458*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_filepath_from_module('AmSlamTests', 'AndroidManifest.xml'), 459*c2e18aaaSAndroid Build Coastguard Worker expected_filepath, 460*c2e18aaaSAndroid Build Coastguard Worker ) 461*c2e18aaaSAndroid Build Coastguard Worker 462*c2e18aaaSAndroid Build Coastguard Worker def test_get_module_dependency(self): 463*c2e18aaaSAndroid Build Coastguard Worker """Test get_module_dependency.""" 464*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 465*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 466*c2e18aaaSAndroid Build Coastguard Worker ) 467*c2e18aaaSAndroid Build Coastguard Worker mod_info = loader.load() 468*c2e18aaaSAndroid Build Coastguard Worker expect_deps = { 469*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_1_1', 470*c2e18aaaSAndroid Build Coastguard Worker 'module_1', 471*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_1_2', 472*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_2_2', 473*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_2_1', 474*c2e18aaaSAndroid Build Coastguard Worker 'module_2', 475*c2e18aaaSAndroid Build Coastguard Worker } 476*c2e18aaaSAndroid Build Coastguard Worker loader._merge_build_system_infos( 477*c2e18aaaSAndroid Build Coastguard Worker loader.name_to_module_info, java_bp_info_path=self.java_dep_path 478*c2e18aaaSAndroid Build Coastguard Worker ) 479*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 480*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_module_dependency('dep_test_module'), expect_deps 481*c2e18aaaSAndroid Build Coastguard Worker ) 482*c2e18aaaSAndroid Build Coastguard Worker 483*c2e18aaaSAndroid Build Coastguard Worker def test_get_module_dependency_w_loop(self): 484*c2e18aaaSAndroid Build Coastguard Worker """Test get_module_dependency with problem dep file.""" 485*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 486*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 487*c2e18aaaSAndroid Build Coastguard Worker ) 488*c2e18aaaSAndroid Build Coastguard Worker mod_info = loader.load() 489*c2e18aaaSAndroid Build Coastguard Worker # Java dependency file with a endless loop define. 490*c2e18aaaSAndroid Build Coastguard Worker java_dep_file = os.path.join( 491*c2e18aaaSAndroid Build Coastguard Worker uc.TEST_DATA_DIR, 'module_bp_java_loop_deps.json' 492*c2e18aaaSAndroid Build Coastguard Worker ) 493*c2e18aaaSAndroid Build Coastguard Worker expect_deps = { 494*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_1_1', 495*c2e18aaaSAndroid Build Coastguard Worker 'module_1', 496*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_1_2', 497*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_2_2', 498*c2e18aaaSAndroid Build Coastguard Worker 'test_dep_level_2_1', 499*c2e18aaaSAndroid Build Coastguard Worker 'module_2', 500*c2e18aaaSAndroid Build Coastguard Worker } 501*c2e18aaaSAndroid Build Coastguard Worker loader._merge_build_system_infos( 502*c2e18aaaSAndroid Build Coastguard Worker loader.name_to_module_info, java_bp_info_path=java_dep_file 503*c2e18aaaSAndroid Build Coastguard Worker ) 504*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 505*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_module_dependency('dep_test_module'), expect_deps 506*c2e18aaaSAndroid Build Coastguard Worker ) 507*c2e18aaaSAndroid Build Coastguard Worker 508*c2e18aaaSAndroid Build Coastguard Worker def test_get_install_module_dependency(self): 509*c2e18aaaSAndroid Build Coastguard Worker """Test get_install_module_dependency.""" 510*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 511*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 512*c2e18aaaSAndroid Build Coastguard Worker ) 513*c2e18aaaSAndroid Build Coastguard Worker mod_info = loader.load() 514*c2e18aaaSAndroid Build Coastguard Worker expect_deps = {'module_1', 'test_dep_level_2_1'} 515*c2e18aaaSAndroid Build Coastguard Worker loader._merge_build_system_infos( 516*c2e18aaaSAndroid Build Coastguard Worker loader.name_to_module_info, java_bp_info_path=self.java_dep_path 517*c2e18aaaSAndroid Build Coastguard Worker ) 518*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 519*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_install_module_dependency('dep_test_module'), expect_deps 520*c2e18aaaSAndroid Build Coastguard Worker ) 521*c2e18aaaSAndroid Build Coastguard Worker 522*c2e18aaaSAndroid Build Coastguard Worker def test_cc_merge_build_system_infos(self): 523*c2e18aaaSAndroid Build Coastguard Worker """Test _merge_build_system_infos for cc.""" 524*c2e18aaaSAndroid Build Coastguard Worker loader = module_info.Loader( 525*c2e18aaaSAndroid Build Coastguard Worker module_file=JSON_FILE_PATH, need_merge_fn=lambda: True 526*c2e18aaaSAndroid Build Coastguard Worker ) 527*c2e18aaaSAndroid Build Coastguard Worker mod_info_1 = { 528*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: 'module_cc_1', 529*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_DEPENDENCIES: [], 530*c2e18aaaSAndroid Build Coastguard Worker } 531*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = {'module_cc_1': mod_info_1} 532*c2e18aaaSAndroid Build Coastguard Worker expect_deps = ['test_cc_dep_level_1_1', 'test_cc_dep_level_1_2'] 533*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info = loader._merge_build_system_infos( 534*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info, cc_bp_info_path=self.cc_dep_path 535*c2e18aaaSAndroid Build Coastguard Worker ) 536*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 537*c2e18aaaSAndroid Build Coastguard Worker name_to_mod_info['module_cc_1'].get(constants.MODULE_DEPENDENCIES), 538*c2e18aaaSAndroid Build Coastguard Worker expect_deps, 539*c2e18aaaSAndroid Build Coastguard Worker ) 540*c2e18aaaSAndroid Build Coastguard Worker 541*c2e18aaaSAndroid Build Coastguard Worker def test_is_unit_test(self): 542*c2e18aaaSAndroid Build Coastguard Worker """Test is_unit_test.""" 543*c2e18aaaSAndroid Build Coastguard Worker module_name = 'myModule' 544*c2e18aaaSAndroid Build Coastguard Worker maininfo_with_unittest = { 545*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: module_name, 546*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_IS_UNIT_TEST: 'true', 547*c2e18aaaSAndroid Build Coastguard Worker } 548*c2e18aaaSAndroid Build Coastguard Worker 549*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(module_info.ModuleInfo.is_unit_test(maininfo_with_unittest)) 550*c2e18aaaSAndroid Build Coastguard Worker 551*c2e18aaaSAndroid Build Coastguard Worker def test_is_host_unit_test(self): 552*c2e18aaaSAndroid Build Coastguard Worker """Test is_host_unit_test.""" 553*c2e18aaaSAndroid Build Coastguard Worker module_name = 'myModule' 554*c2e18aaaSAndroid Build Coastguard Worker maininfo_with_host_unittest = { 555*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: module_name, 556*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_IS_UNIT_TEST: 'true', 557*c2e18aaaSAndroid Build Coastguard Worker 'compatibility_suites': ['host-unit-tests'], 558*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_INSTALLED: uc.DEFAULT_INSTALL_PATH, 559*c2e18aaaSAndroid Build Coastguard Worker 'auto_test_config': ['true'], 560*c2e18aaaSAndroid Build Coastguard Worker } 561*c2e18aaaSAndroid Build Coastguard Worker 562*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 563*c2e18aaaSAndroid Build Coastguard Worker 564*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.is_host_unit_test(maininfo_with_host_unittest)) 565*c2e18aaaSAndroid Build Coastguard Worker 566*c2e18aaaSAndroid Build Coastguard Worker def test_is_device_driven_test(self): 567*c2e18aaaSAndroid Build Coastguard Worker module_name = 'myModule' 568*c2e18aaaSAndroid Build Coastguard Worker maininfo_with_device_driven_test = { 569*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: module_name, 570*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_TEST_CONFIG: [ 571*c2e18aaaSAndroid Build Coastguard Worker os.path.join(uc.TEST_CONFIG_DATA_DIR, 'a.xml.data') 572*c2e18aaaSAndroid Build Coastguard Worker ], 573*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_INSTALLED: uc.DEFAULT_INSTALL_PATH, 574*c2e18aaaSAndroid Build Coastguard Worker 'supported_variants': ['DEVICE'], 575*c2e18aaaSAndroid Build Coastguard Worker } 576*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 577*c2e18aaaSAndroid Build Coastguard Worker 578*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue( 579*c2e18aaaSAndroid Build Coastguard Worker mod_info.is_device_driven_test(maininfo_with_device_driven_test) 580*c2e18aaaSAndroid Build Coastguard Worker ) 581*c2e18aaaSAndroid Build Coastguard Worker 582*c2e18aaaSAndroid Build Coastguard Worker def test_not_device_driven_test_when_suite_is_robolectric_test(self): 583*c2e18aaaSAndroid Build Coastguard Worker module_name = 'myModule' 584*c2e18aaaSAndroid Build Coastguard Worker maininfo_with_device_driven_test = { 585*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: module_name, 586*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_TEST_CONFIG: [ 587*c2e18aaaSAndroid Build Coastguard Worker os.path.join(uc.TEST_CONFIG_DATA_DIR, 'a.xml.data') 588*c2e18aaaSAndroid Build Coastguard Worker ], 589*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_INSTALLED: uc.DEFAULT_INSTALL_PATH, 590*c2e18aaaSAndroid Build Coastguard Worker 'supported_variants': ['DEVICE'], 591*c2e18aaaSAndroid Build Coastguard Worker 'compatibility_suites': ['robolectric-tests'], 592*c2e18aaaSAndroid Build Coastguard Worker } 593*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 594*c2e18aaaSAndroid Build Coastguard Worker 595*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse( 596*c2e18aaaSAndroid Build Coastguard Worker mod_info.is_device_driven_test(maininfo_with_device_driven_test) 597*c2e18aaaSAndroid Build Coastguard Worker ) 598*c2e18aaaSAndroid Build Coastguard Worker 599*c2e18aaaSAndroid Build Coastguard Worker def test_is_host_driven_test(self): 600*c2e18aaaSAndroid Build Coastguard Worker """Test is_host_driven_test.""" 601*c2e18aaaSAndroid Build Coastguard Worker test_name = 'myModule' 602*c2e18aaaSAndroid Build Coastguard Worker expected_host_driven_info = { 603*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_NAME: test_name, 604*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_TEST_CONFIG: [ 605*c2e18aaaSAndroid Build Coastguard Worker os.path.join(uc.TEST_CONFIG_DATA_DIR, 'a.xml.data') 606*c2e18aaaSAndroid Build Coastguard Worker ], 607*c2e18aaaSAndroid Build Coastguard Worker constants.MODULE_INSTALLED: uc.DEFAULT_INSTALL_PATH, 608*c2e18aaaSAndroid Build Coastguard Worker 'supported_variants': ['HOST'], 609*c2e18aaaSAndroid Build Coastguard Worker } 610*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 611*c2e18aaaSAndroid Build Coastguard Worker module( 612*c2e18aaaSAndroid Build Coastguard Worker name=test_name, 613*c2e18aaaSAndroid Build Coastguard Worker test_config=[os.path.join(uc.TEST_CONFIG_DATA_DIR, 'a.xml.data')], 614*c2e18aaaSAndroid Build Coastguard Worker installed=uc.DEFAULT_INSTALL_PATH, 615*c2e18aaaSAndroid Build Coastguard Worker supported_variants=['HOST'], 616*c2e18aaaSAndroid Build Coastguard Worker ) 617*c2e18aaaSAndroid Build Coastguard Worker ]) 618*c2e18aaaSAndroid Build Coastguard Worker 619*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_host_driven_test(expected_host_driven_info) 620*c2e18aaaSAndroid Build Coastguard Worker 621*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 622*c2e18aaaSAndroid Build Coastguard Worker 623*c2e18aaaSAndroid Build Coastguard Worker # TODO: (b/264015241) Stop mocking build variables. 624*c2e18aaaSAndroid Build Coastguard Worker # TODO: (b/263199608) Re-write the test after refactoring module-info.py 625*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 626*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 627*c2e18aaaSAndroid Build Coastguard Worker { 628*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: uc.ATEST_PKG_DIR, 629*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 630*c2e18aaaSAndroid Build Coastguard Worker }, 631*c2e18aaaSAndroid Build Coastguard Worker ) 632*c2e18aaaSAndroid Build Coastguard Worker def test_has_mainline_modules(self): 633*c2e18aaaSAndroid Build Coastguard Worker """Test has_mainline_modules.""" 634*c2e18aaaSAndroid Build Coastguard Worker name1 = 'MainModule1' 635*c2e18aaaSAndroid Build Coastguard Worker mainline_module1 = ['foo2.apk', 'foo3.apk'] 636*c2e18aaaSAndroid Build Coastguard Worker name2 = 'MainModule2' 637*c2e18aaaSAndroid Build Coastguard Worker mainline_module2 = ['foo1.apex'] 638*c2e18aaaSAndroid Build Coastguard Worker name3 = 'MainModule3' 639*c2e18aaaSAndroid Build Coastguard Worker 640*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=JSON_FILE_PATH) 641*c2e18aaaSAndroid Build Coastguard Worker # found in 'test_mainlne_modules' attribute. 642*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.has_mainline_modules(name1, mainline_module1)) 643*c2e18aaaSAndroid Build Coastguard Worker # found in the value of 'mainline-param' in test_config. 644*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(mod_info.has_mainline_modules(name2, mainline_module2)) 645*c2e18aaaSAndroid Build Coastguard Worker # cannot be found in both 'test_mainline_modules' and 'test_config'. 646*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(mod_info.has_mainline_modules(name3, mainline_module2)) 647*c2e18aaaSAndroid Build Coastguard Worker 648*c2e18aaaSAndroid Build Coastguard Worker # TODO: (b/264015241) Stop mocking build variables. 649*c2e18aaaSAndroid Build Coastguard Worker # TODO: (b/263199608) Re-write the test after refactoring module-info.py 650*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 651*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', 652*c2e18aaaSAndroid Build Coastguard Worker { 653*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_BUILD_TOP: os.path.dirname(__file__), 654*c2e18aaaSAndroid Build Coastguard Worker constants.ANDROID_PRODUCT_OUT: PRODUCT_OUT_DIR, 655*c2e18aaaSAndroid Build Coastguard Worker }, 656*c2e18aaaSAndroid Build Coastguard Worker ) 657*c2e18aaaSAndroid Build Coastguard Worker def test_get_module_info_for_multi_lib_module(self): 658*c2e18aaaSAndroid Build Coastguard Worker my_module_name = 'MyMultiArchTestModule' 659*c2e18aaaSAndroid Build Coastguard Worker multi_arch_json = os.path.join( 660*c2e18aaaSAndroid Build Coastguard Worker uc.TEST_DATA_DIR, 'multi_arch_module-info.json' 661*c2e18aaaSAndroid Build Coastguard Worker ) 662*c2e18aaaSAndroid Build Coastguard Worker mod_info = module_info.load_from_file(module_file=multi_arch_json) 663*c2e18aaaSAndroid Build Coastguard Worker 664*c2e18aaaSAndroid Build Coastguard Worker self.assertIsNotNone(mod_info.get_module_info(my_module_name)) 665*c2e18aaaSAndroid Build Coastguard Worker 666*c2e18aaaSAndroid Build Coastguard Worker def test_get_modules_by_include_deps_w_testable_module_only_false(self): 667*c2e18aaaSAndroid Build Coastguard Worker module_1 = module( 668*c2e18aaaSAndroid Build Coastguard Worker name='module_1', 669*c2e18aaaSAndroid Build Coastguard Worker dependencies=['dep1', 'dep2'], 670*c2e18aaaSAndroid Build Coastguard Worker ) 671*c2e18aaaSAndroid Build Coastguard Worker module_2 = module(name='module_2', dependencies=['dep1', 'dep3']) 672*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([module_1, module_2]) 673*c2e18aaaSAndroid Build Coastguard Worker 674*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 675*c2e18aaaSAndroid Build Coastguard Worker {'module_1', 'module_2'}, 676*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_modules_by_include_deps( 677*c2e18aaaSAndroid Build Coastguard Worker {'dep1'}, testable_module_only=False 678*c2e18aaaSAndroid Build Coastguard Worker ), 679*c2e18aaaSAndroid Build Coastguard Worker ) 680*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 681*c2e18aaaSAndroid Build Coastguard Worker {'module_1'}, 682*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_modules_by_include_deps( 683*c2e18aaaSAndroid Build Coastguard Worker {'dep2'}, testable_module_only=False 684*c2e18aaaSAndroid Build Coastguard Worker ), 685*c2e18aaaSAndroid Build Coastguard Worker ) 686*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 687*c2e18aaaSAndroid Build Coastguard Worker {'module_2'}, 688*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_modules_by_include_deps( 689*c2e18aaaSAndroid Build Coastguard Worker {'dep3'}, testable_module_only=False 690*c2e18aaaSAndroid Build Coastguard Worker ), 691*c2e18aaaSAndroid Build Coastguard Worker ) 692*c2e18aaaSAndroid Build Coastguard Worker 693*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.object(module_info.ModuleInfo, 'get_testable_modules') 694*c2e18aaaSAndroid Build Coastguard Worker def test_get_modules_by_include_deps_w_testable_module_only_true( 695*c2e18aaaSAndroid Build Coastguard Worker self, _testable_modules 696*c2e18aaaSAndroid Build Coastguard Worker ): 697*c2e18aaaSAndroid Build Coastguard Worker module_1 = module( 698*c2e18aaaSAndroid Build Coastguard Worker name='module_1', 699*c2e18aaaSAndroid Build Coastguard Worker dependencies=['dep1', 'dep2'], 700*c2e18aaaSAndroid Build Coastguard Worker ) 701*c2e18aaaSAndroid Build Coastguard Worker module_2 = module(name='module_2', dependencies=['dep1', 'dep3']) 702*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([module_1, module_2]) 703*c2e18aaaSAndroid Build Coastguard Worker _testable_modules.return_value = [] 704*c2e18aaaSAndroid Build Coastguard Worker 705*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 706*c2e18aaaSAndroid Build Coastguard Worker set(), 707*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_modules_by_include_deps( 708*c2e18aaaSAndroid Build Coastguard Worker {'dep1'}, testable_module_only=True 709*c2e18aaaSAndroid Build Coastguard Worker ), 710*c2e18aaaSAndroid Build Coastguard Worker ) 711*c2e18aaaSAndroid Build Coastguard Worker 712*c2e18aaaSAndroid Build Coastguard Worker def test_get_modules_by_path_in_srcs_no_module_found(self): 713*c2e18aaaSAndroid Build Coastguard Worker module_1 = module( 714*c2e18aaaSAndroid Build Coastguard Worker name='module_1', 715*c2e18aaaSAndroid Build Coastguard Worker srcs=['path/src1', 'path/src2'], 716*c2e18aaaSAndroid Build Coastguard Worker ) 717*c2e18aaaSAndroid Build Coastguard Worker module_2 = module(name='module_2', srcs=['path/src2', 'path/src3']) 718*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([module_1, module_2]) 719*c2e18aaaSAndroid Build Coastguard Worker 720*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(set(), mod_info.get_modules_by_path_in_srcs('path/src4')) 721*c2e18aaaSAndroid Build Coastguard Worker 722*c2e18aaaSAndroid Build Coastguard Worker def test_get_modules_by_path_in_srcs_one_module_found(self): 723*c2e18aaaSAndroid Build Coastguard Worker module_1 = module( 724*c2e18aaaSAndroid Build Coastguard Worker name='module_1', 725*c2e18aaaSAndroid Build Coastguard Worker srcs=['path/src1', 'path/src2'], 726*c2e18aaaSAndroid Build Coastguard Worker ) 727*c2e18aaaSAndroid Build Coastguard Worker module_2 = module(name='module_2', srcs=['path/src2', 'path/src3']) 728*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([module_1, module_2]) 729*c2e18aaaSAndroid Build Coastguard Worker 730*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 731*c2e18aaaSAndroid Build Coastguard Worker {'module_1'}, mod_info.get_modules_by_path_in_srcs('path/src1') 732*c2e18aaaSAndroid Build Coastguard Worker ) 733*c2e18aaaSAndroid Build Coastguard Worker 734*c2e18aaaSAndroid Build Coastguard Worker def test_get_modules_by_path_in_srcs_multiple_module_found(self): 735*c2e18aaaSAndroid Build Coastguard Worker module_1 = module( 736*c2e18aaaSAndroid Build Coastguard Worker name='module_1', 737*c2e18aaaSAndroid Build Coastguard Worker srcs=['path/src1', 'path/src2'], 738*c2e18aaaSAndroid Build Coastguard Worker ) 739*c2e18aaaSAndroid Build Coastguard Worker module_2 = module(name='module_2', srcs=['path/src2', 'path/src3']) 740*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([module_1, module_2]) 741*c2e18aaaSAndroid Build Coastguard Worker 742*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 743*c2e18aaaSAndroid Build Coastguard Worker {'module_1', 'module_2'}, 744*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_modules_by_path_in_srcs('path/src2'), 745*c2e18aaaSAndroid Build Coastguard Worker ) 746*c2e18aaaSAndroid Build Coastguard Worker 747*c2e18aaaSAndroid Build Coastguard Worker def test_contains_same_mainline_modules(self): 748*c2e18aaaSAndroid Build Coastguard Worker mainline_modules = {'A.apex', 'B.apk'} 749*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue( 750*c2e18aaaSAndroid Build Coastguard Worker module_info.contains_same_mainline_modules( 751*c2e18aaaSAndroid Build Coastguard Worker mainline_modules, {'B.apk+A.apex'} 752*c2e18aaaSAndroid Build Coastguard Worker ) 753*c2e18aaaSAndroid Build Coastguard Worker ) 754*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse( 755*c2e18aaaSAndroid Build Coastguard Worker module_info.contains_same_mainline_modules( 756*c2e18aaaSAndroid Build Coastguard Worker mainline_modules, {'B.apk+C.apex'} 757*c2e18aaaSAndroid Build Coastguard Worker ) 758*c2e18aaaSAndroid Build Coastguard Worker ) 759*c2e18aaaSAndroid Build Coastguard Worker 760*c2e18aaaSAndroid Build Coastguard Worker def test_get_installed_paths_have_abs_path(self): 761*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info( 762*c2e18aaaSAndroid Build Coastguard Worker [module(name='my_module', installed=[Path('/a/b/c/d')])] 763*c2e18aaaSAndroid Build Coastguard Worker ) 764*c2e18aaaSAndroid Build Coastguard Worker 765*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 766*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_installed_paths('my_module'), [Path('/a/b/c/d')] 767*c2e18aaaSAndroid Build Coastguard Worker ) 768*c2e18aaaSAndroid Build Coastguard Worker 769*c2e18aaaSAndroid Build Coastguard Worker @mock.patch.dict( 770*c2e18aaaSAndroid Build Coastguard Worker 'os.environ', {constants.ANDROID_BUILD_TOP: '/mocked/build_top'} 771*c2e18aaaSAndroid Build Coastguard Worker ) 772*c2e18aaaSAndroid Build Coastguard Worker def test_get_installed_paths_have_relative_path(self): 773*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info( 774*c2e18aaaSAndroid Build Coastguard Worker [module(name='my_module', installed=['a/b/c/d'])] 775*c2e18aaaSAndroid Build Coastguard Worker ) 776*c2e18aaaSAndroid Build Coastguard Worker 777*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 778*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_installed_paths('my_module'), 779*c2e18aaaSAndroid Build Coastguard Worker [Path('/mocked/build_top/a/b/c/d')], 780*c2e18aaaSAndroid Build Coastguard Worker ) 781*c2e18aaaSAndroid Build Coastguard Worker 782*c2e18aaaSAndroid Build Coastguard Worker def test_get_code_under_test_module_name_is_not_found_in_module_info(self): 783*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 784*c2e18aaaSAndroid Build Coastguard Worker module( 785*c2e18aaaSAndroid Build Coastguard Worker name='my_module', 786*c2e18aaaSAndroid Build Coastguard Worker code_under_test='code_under_test_module', 787*c2e18aaaSAndroid Build Coastguard Worker ) 788*c2e18aaaSAndroid Build Coastguard Worker ]) 789*c2e18aaaSAndroid Build Coastguard Worker 790*c2e18aaaSAndroid Build Coastguard Worker # module_that_is_not_in_module_info is not found in mod_info. 791*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 792*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_code_under_test('module_that_is_not_in_module_info'), [], 793*c2e18aaaSAndroid Build Coastguard Worker ) 794*c2e18aaaSAndroid Build Coastguard Worker 795*c2e18aaaSAndroid Build Coastguard Worker def test_get_code_under_test_code_under_test_is_not_defined_in_module_info(self): 796*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([module(name='my_module')]) 797*c2e18aaaSAndroid Build Coastguard Worker 798*c2e18aaaSAndroid Build Coastguard Worker # my_module is found in mod_info but code_under_test is not defined. 799*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 800*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_code_under_test('my_module'), [], 801*c2e18aaaSAndroid Build Coastguard Worker ) 802*c2e18aaaSAndroid Build Coastguard Worker 803*c2e18aaaSAndroid Build Coastguard Worker def test_get_code_under_test_code_under_test_is_defined_in_module_info(self): 804*c2e18aaaSAndroid Build Coastguard Worker mod_info = create_module_info([ 805*c2e18aaaSAndroid Build Coastguard Worker module( 806*c2e18aaaSAndroid Build Coastguard Worker name='my_module', 807*c2e18aaaSAndroid Build Coastguard Worker code_under_test='code_under_test_module', 808*c2e18aaaSAndroid Build Coastguard Worker ) 809*c2e18aaaSAndroid Build Coastguard Worker ]) 810*c2e18aaaSAndroid Build Coastguard Worker 811*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 812*c2e18aaaSAndroid Build Coastguard Worker mod_info.get_code_under_test('my_module'), 813*c2e18aaaSAndroid Build Coastguard Worker 'code_under_test_module', 814*c2e18aaaSAndroid Build Coastguard Worker ) 815*c2e18aaaSAndroid Build Coastguard Worker 816*c2e18aaaSAndroid Build Coastguard Worker 817*c2e18aaaSAndroid Build Coastguard Workerclass ModuleInfoTestFixture(fake_filesystem_unittest.TestCase): 818*c2e18aaaSAndroid Build Coastguard Worker """Fixture for ModuleInfo tests.""" 819*c2e18aaaSAndroid Build Coastguard Worker 820*c2e18aaaSAndroid Build Coastguard Worker def setUp(self): 821*c2e18aaaSAndroid Build Coastguard Worker self.setUpPyfakefs() 822*c2e18aaaSAndroid Build Coastguard Worker 823*c2e18aaaSAndroid Build Coastguard Worker # pylint: disable=protected-access 824*c2e18aaaSAndroid Build Coastguard Worker def create_empty_module_info(self): 825*c2e18aaaSAndroid Build Coastguard Worker fake_temp_file_name = next(tempfile._get_candidate_names()) 826*c2e18aaaSAndroid Build Coastguard Worker self.fs.create_file(fake_temp_file_name, contents='{}') 827*c2e18aaaSAndroid Build Coastguard Worker return module_info.load_from_file(module_file=fake_temp_file_name) 828*c2e18aaaSAndroid Build Coastguard Worker 829*c2e18aaaSAndroid Build Coastguard Worker def create_module_info(self, modules=None): 830*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_empty_module_info() 831*c2e18aaaSAndroid Build Coastguard Worker modules = modules or [] 832*c2e18aaaSAndroid Build Coastguard Worker 833*c2e18aaaSAndroid Build Coastguard Worker for m in modules: 834*c2e18aaaSAndroid Build Coastguard Worker mod_info.name_to_module_info[m['module_name']] = m 835*c2e18aaaSAndroid Build Coastguard Worker for path in m['path']: 836*c2e18aaaSAndroid Build Coastguard Worker if path in mod_info.path_to_module_info: 837*c2e18aaaSAndroid Build Coastguard Worker mod_info.path_to_module_info[path].append(m) 838*c2e18aaaSAndroid Build Coastguard Worker else: 839*c2e18aaaSAndroid Build Coastguard Worker mod_info.path_to_module_info[path] = [m] 840*c2e18aaaSAndroid Build Coastguard Worker 841*c2e18aaaSAndroid Build Coastguard Worker return mod_info 842*c2e18aaaSAndroid Build Coastguard Worker 843*c2e18aaaSAndroid Build Coastguard Worker 844*c2e18aaaSAndroid Build Coastguard Workerclass HasTestConfonfigTest(ModuleInfoTestFixture): 845*c2e18aaaSAndroid Build Coastguard Worker """Tests has_test_config in various conditions.""" 846*c2e18aaaSAndroid Build Coastguard Worker 847*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_if_test_config_is_not_empty(self): 848*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(test_config=['config_file']) 849*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 850*c2e18aaaSAndroid Build Coastguard Worker 851*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.has_test_config(test_module_info) 852*c2e18aaaSAndroid Build Coastguard Worker 853*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 854*c2e18aaaSAndroid Build Coastguard Worker 855*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_if_auto_test_config_is_not_empty(self): 856*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(auto_test_config=['no_empty']) 857*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 858*c2e18aaaSAndroid Build Coastguard Worker 859*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.has_test_config(test_module_info) 860*c2e18aaaSAndroid Build Coastguard Worker 861*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 862*c2e18aaaSAndroid Build Coastguard Worker 863*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_if_auto_test_config_and_test_config_empty(self): 864*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(test_config=[], auto_test_config=[]) 865*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 866*c2e18aaaSAndroid Build Coastguard Worker 867*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.has_test_config(test_module_info) 868*c2e18aaaSAndroid Build Coastguard Worker 869*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 870*c2e18aaaSAndroid Build Coastguard Worker 871*c2e18aaaSAndroid Build Coastguard Worker 872*c2e18aaaSAndroid Build Coastguard Workerclass ModuleInfoCompatibilitySuiteTest(ModuleInfoTestFixture): 873*c2e18aaaSAndroid Build Coastguard Worker """Tests the compatibility suite in the module info.""" 874*c2e18aaaSAndroid Build Coastguard Worker 875*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_if_suite_in_test(self): 876*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(compatibility_suites=['test_suite']) 877*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 878*c2e18aaaSAndroid Build Coastguard Worker 879*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_suite_in_compatibility_suites( 880*c2e18aaaSAndroid Build Coastguard Worker 'test_suite', test_module_info 881*c2e18aaaSAndroid Build Coastguard Worker ) 882*c2e18aaaSAndroid Build Coastguard Worker 883*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 884*c2e18aaaSAndroid Build Coastguard Worker 885*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_if_suite_not_in_test(self): 886*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(compatibility_suites=['no_suite']) 887*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 888*c2e18aaaSAndroid Build Coastguard Worker 889*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_suite_in_compatibility_suites( 890*c2e18aaaSAndroid Build Coastguard Worker 'test_suite', test_module_info 891*c2e18aaaSAndroid Build Coastguard Worker ) 892*c2e18aaaSAndroid Build Coastguard Worker 893*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 894*c2e18aaaSAndroid Build Coastguard Worker 895*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_when_mod_info_is_empty(self): 896*c2e18aaaSAndroid Build Coastguard Worker test_module_info = None 897*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 898*c2e18aaaSAndroid Build Coastguard Worker 899*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_suite_in_compatibility_suites( 900*c2e18aaaSAndroid Build Coastguard Worker 'test_suite', test_module_info 901*c2e18aaaSAndroid Build Coastguard Worker ) 902*c2e18aaaSAndroid Build Coastguard Worker 903*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 904*c2e18aaaSAndroid Build Coastguard Worker 905*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_when_mod_info_is_not_a_dict(self): 906*c2e18aaaSAndroid Build Coastguard Worker test_module_info = ['no_a_dict'] 907*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 908*c2e18aaaSAndroid Build Coastguard Worker 909*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_suite_in_compatibility_suites( 910*c2e18aaaSAndroid Build Coastguard Worker 'test_suite', test_module_info 911*c2e18aaaSAndroid Build Coastguard Worker ) 912*c2e18aaaSAndroid Build Coastguard Worker 913*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 914*c2e18aaaSAndroid Build Coastguard Worker 915*c2e18aaaSAndroid Build Coastguard Worker 916*c2e18aaaSAndroid Build Coastguard Workerclass RobolectricTestNameTest(ModuleInfoTestFixture): 917*c2e18aaaSAndroid Build Coastguard Worker """Tests the Robolectric test name in the module info.""" 918*c2e18aaaSAndroid Build Coastguard Worker 919*c2e18aaaSAndroid Build Coastguard Worker def test_return_empty_for_a_modern_robolectric_test(self): 920*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 921*c2e18aaaSAndroid Build Coastguard Worker info = modern_robolectric_test_module(name=f'{module_name}') 922*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info(modules=[info]) 923*c2e18aaaSAndroid Build Coastguard Worker 924*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 925*c2e18aaaSAndroid Build Coastguard Worker 926*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual('', return_module) 927*c2e18aaaSAndroid Build Coastguard Worker 928*c2e18aaaSAndroid Build Coastguard Worker def test_return_related_robolectric_run_module_name(self): 929*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 930*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Run{module_name}' 931*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 932*c2e18aaaSAndroid Build Coastguard Worker info = non_test_module(name=f'{module_name}', path=module_path) 933*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 934*c2e18aaaSAndroid Build Coastguard Worker modules=[ 935*c2e18aaaSAndroid Build Coastguard Worker info, 936*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_non_test_module( 937*c2e18aaaSAndroid Build Coastguard Worker name=f'{run_module_name}', path=module_path 938*c2e18aaaSAndroid Build Coastguard Worker ), 939*c2e18aaaSAndroid Build Coastguard Worker ] 940*c2e18aaaSAndroid Build Coastguard Worker ) 941*c2e18aaaSAndroid Build Coastguard Worker 942*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 943*c2e18aaaSAndroid Build Coastguard Worker 944*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(run_module_name, return_module) 945*c2e18aaaSAndroid Build Coastguard Worker 946*c2e18aaaSAndroid Build Coastguard Worker def test_return_empty_when_no_related_robolectic_class_module(self): 947*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 948*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Run{module_name}' 949*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 950*c2e18aaaSAndroid Build Coastguard Worker info = non_test_module(name=f'{module_name}', path=module_path) 951*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 952*c2e18aaaSAndroid Build Coastguard Worker modules=[ 953*c2e18aaaSAndroid Build Coastguard Worker info, 954*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name=f'{run_module_name}', path=module_path), 955*c2e18aaaSAndroid Build Coastguard Worker ] 956*c2e18aaaSAndroid Build Coastguard Worker ) 957*c2e18aaaSAndroid Build Coastguard Worker 958*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 959*c2e18aaaSAndroid Build Coastguard Worker 960*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual('', return_module) 961*c2e18aaaSAndroid Build Coastguard Worker 962*c2e18aaaSAndroid Build Coastguard Worker def test_return_empty_if_related_module_name_not_start_with_Run(self): 963*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 964*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Not_Run{module_name}' 965*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 966*c2e18aaaSAndroid Build Coastguard Worker info = robolectric_class_non_test_module( 967*c2e18aaaSAndroid Build Coastguard Worker name=f'{run_module_name}', path=module_path 968*c2e18aaaSAndroid Build Coastguard Worker ) 969*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 970*c2e18aaaSAndroid Build Coastguard Worker modules=[ 971*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name=f'{module_name}', path=module_path), 972*c2e18aaaSAndroid Build Coastguard Worker info, 973*c2e18aaaSAndroid Build Coastguard Worker ] 974*c2e18aaaSAndroid Build Coastguard Worker ) 975*c2e18aaaSAndroid Build Coastguard Worker 976*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 977*c2e18aaaSAndroid Build Coastguard Worker 978*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual('', return_module) 979*c2e18aaaSAndroid Build Coastguard Worker 980*c2e18aaaSAndroid Build Coastguard Worker def test_return_itself_for_a_robolectric_class_test_module(self): 981*c2e18aaaSAndroid Build Coastguard Worker module_name = 'Run_hello_world_test' 982*c2e18aaaSAndroid Build Coastguard Worker info = robolectric_class_non_test_module(name=f'{module_name}') 983*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info(modules=[info]) 984*c2e18aaaSAndroid Build Coastguard Worker 985*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 986*c2e18aaaSAndroid Build Coastguard Worker 987*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(module_name, return_module) 988*c2e18aaaSAndroid Build Coastguard Worker 989*c2e18aaaSAndroid Build Coastguard Worker def test_return_empty_if_robolectric_class_module_not_start_with_Run(self): 990*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 991*c2e18aaaSAndroid Build Coastguard Worker info = robolectric_class_non_test_module(name=f'{module_name}') 992*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info(modules=[info]) 993*c2e18aaaSAndroid Build Coastguard Worker 994*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 995*c2e18aaaSAndroid Build Coastguard Worker 996*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual('', return_module) 997*c2e18aaaSAndroid Build Coastguard Worker 998*c2e18aaaSAndroid Build Coastguard Worker def test_return_0_when_no_mod_info(self): 999*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1000*c2e18aaaSAndroid Build Coastguard Worker info = non_test_module(name=module_name) 1001*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info(modules=[info]) 1002*c2e18aaaSAndroid Build Coastguard Worker 1003*c2e18aaaSAndroid Build Coastguard Worker return_module = mod_info.get_robolectric_test_name(info) 1004*c2e18aaaSAndroid Build Coastguard Worker 1005*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual('', return_module) 1006*c2e18aaaSAndroid Build Coastguard Worker 1007*c2e18aaaSAndroid Build Coastguard Worker 1008*c2e18aaaSAndroid Build Coastguard Workerclass RobolectricTestTypeTest(ModuleInfoTestFixture): 1009*c2e18aaaSAndroid Build Coastguard Worker """Tests the Robolectric test type in the module info.""" 1010*c2e18aaaSAndroid Build Coastguard Worker 1011*c2e18aaaSAndroid Build Coastguard Worker def test_modern_robolectric_test_type(self): 1012*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1013*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1014*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1015*c2e18aaaSAndroid Build Coastguard Worker modern_robolectric_test_module(name=f'{module_name}'), 1016*c2e18aaaSAndroid Build Coastguard Worker ] 1017*c2e18aaaSAndroid Build Coastguard Worker ) 1018*c2e18aaaSAndroid Build Coastguard Worker 1019*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1020*c2e18aaaSAndroid Build Coastguard Worker 1021*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, constants.ROBOTYPE_MODERN) 1022*c2e18aaaSAndroid Build Coastguard Worker 1023*c2e18aaaSAndroid Build Coastguard Worker def test_return_modern_if_compliant_with_modern_and_legacy(self): 1024*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1025*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 1026*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Run{module_name}' 1027*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1028*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1029*c2e18aaaSAndroid Build Coastguard Worker modern_robolectric_test_module( 1030*c2e18aaaSAndroid Build Coastguard Worker name=f'{module_name}', path=module_path 1031*c2e18aaaSAndroid Build Coastguard Worker ), 1032*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_non_test_module( 1033*c2e18aaaSAndroid Build Coastguard Worker name=f'{run_module_name}', path=module_path 1034*c2e18aaaSAndroid Build Coastguard Worker ), 1035*c2e18aaaSAndroid Build Coastguard Worker ] 1036*c2e18aaaSAndroid Build Coastguard Worker ) 1037*c2e18aaaSAndroid Build Coastguard Worker 1038*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1039*c2e18aaaSAndroid Build Coastguard Worker 1040*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, constants.ROBOTYPE_MODERN) 1041*c2e18aaaSAndroid Build Coastguard Worker 1042*c2e18aaaSAndroid Build Coastguard Worker def test_not_modern_robolectric_test_if_suite_is_not_robolectric(self): 1043*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1044*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1045*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1046*c2e18aaaSAndroid Build Coastguard Worker non_test_module( 1047*c2e18aaaSAndroid Build Coastguard Worker name=f'{module_name}', 1048*c2e18aaaSAndroid Build Coastguard Worker compatibility_suites='not_robolectric_tests', 1049*c2e18aaaSAndroid Build Coastguard Worker ), 1050*c2e18aaaSAndroid Build Coastguard Worker ] 1051*c2e18aaaSAndroid Build Coastguard Worker ) 1052*c2e18aaaSAndroid Build Coastguard Worker 1053*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1054*c2e18aaaSAndroid Build Coastguard Worker 1055*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, 0) 1056*c2e18aaaSAndroid Build Coastguard Worker 1057*c2e18aaaSAndroid Build Coastguard Worker def test_legacy_robolectric_test_type_if_has_related_run_robolectric_class_module( 1058*c2e18aaaSAndroid Build Coastguard Worker self, 1059*c2e18aaaSAndroid Build Coastguard Worker ): 1060*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1061*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Run{module_name}' 1062*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 1063*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1064*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1065*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name=f'{module_name}', path=module_path), 1066*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_non_test_module( 1067*c2e18aaaSAndroid Build Coastguard Worker name=f'{run_module_name}', path=module_path 1068*c2e18aaaSAndroid Build Coastguard Worker ), 1069*c2e18aaaSAndroid Build Coastguard Worker ] 1070*c2e18aaaSAndroid Build Coastguard Worker ) 1071*c2e18aaaSAndroid Build Coastguard Worker 1072*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1073*c2e18aaaSAndroid Build Coastguard Worker 1074*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, constants.ROBOTYPE_LEGACY) 1075*c2e18aaaSAndroid Build Coastguard Worker 1076*c2e18aaaSAndroid Build Coastguard Worker def test_not_legacy_robolectric_test_type_if_module_is_tradefed_testable( 1077*c2e18aaaSAndroid Build Coastguard Worker self, 1078*c2e18aaaSAndroid Build Coastguard Worker ): 1079*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1080*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Run{module_name}' 1081*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 1082*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1083*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1084*c2e18aaaSAndroid Build Coastguard Worker test_module(name=f'{module_name}', path=module_path), 1085*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_test_module( 1086*c2e18aaaSAndroid Build Coastguard Worker name=f'{run_module_name}', path=module_path 1087*c2e18aaaSAndroid Build Coastguard Worker ), 1088*c2e18aaaSAndroid Build Coastguard Worker ] 1089*c2e18aaaSAndroid Build Coastguard Worker ) 1090*c2e18aaaSAndroid Build Coastguard Worker 1091*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1092*c2e18aaaSAndroid Build Coastguard Worker 1093*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, 0) 1094*c2e18aaaSAndroid Build Coastguard Worker 1095*c2e18aaaSAndroid Build Coastguard Worker def test_robolectric_class_test_module(self): 1096*c2e18aaaSAndroid Build Coastguard Worker module_name = 'Run_hello_world_test' 1097*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1098*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1099*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_non_test_module(name=f'{module_name}'), 1100*c2e18aaaSAndroid Build Coastguard Worker ] 1101*c2e18aaaSAndroid Build Coastguard Worker ) 1102*c2e18aaaSAndroid Build Coastguard Worker 1103*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1104*c2e18aaaSAndroid Build Coastguard Worker 1105*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, constants.ROBOTYPE_LEGACY) 1106*c2e18aaaSAndroid Build Coastguard Worker 1107*c2e18aaaSAndroid Build Coastguard Worker def test_not_robolectric_test_if_module_name_not_start_with_Run(self): 1108*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1109*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1110*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1111*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_non_test_module(name=f'{module_name}'), 1112*c2e18aaaSAndroid Build Coastguard Worker ] 1113*c2e18aaaSAndroid Build Coastguard Worker ) 1114*c2e18aaaSAndroid Build Coastguard Worker 1115*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1116*c2e18aaaSAndroid Build Coastguard Worker 1117*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, 0) 1118*c2e18aaaSAndroid Build Coastguard Worker 1119*c2e18aaaSAndroid Build Coastguard Worker def test_return_0_when_no_related_robolectic_class_module(self): 1120*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1121*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Run{module_name}' 1122*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 1123*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1124*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1125*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name=f'{module_name}', path=module_path), 1126*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name=f'{run_module_name}', path=module_path), 1127*c2e18aaaSAndroid Build Coastguard Worker ] 1128*c2e18aaaSAndroid Build Coastguard Worker ) 1129*c2e18aaaSAndroid Build Coastguard Worker 1130*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1131*c2e18aaaSAndroid Build Coastguard Worker 1132*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, 0) 1133*c2e18aaaSAndroid Build Coastguard Worker 1134*c2e18aaaSAndroid Build Coastguard Worker def test_return_0_when_no_related_module_name_start_with_Run(self): 1135*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1136*c2e18aaaSAndroid Build Coastguard Worker run_module_name = f'Not_Run{module_name}' 1137*c2e18aaaSAndroid Build Coastguard Worker module_path = 'robolectric_path' 1138*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info( 1139*c2e18aaaSAndroid Build Coastguard Worker modules=[ 1140*c2e18aaaSAndroid Build Coastguard Worker non_test_module(name=f'{module_name}', path=module_path), 1141*c2e18aaaSAndroid Build Coastguard Worker robolectric_class_non_test_module( 1142*c2e18aaaSAndroid Build Coastguard Worker name=f'{run_module_name}', path=module_path 1143*c2e18aaaSAndroid Build Coastguard Worker ), 1144*c2e18aaaSAndroid Build Coastguard Worker ] 1145*c2e18aaaSAndroid Build Coastguard Worker ) 1146*c2e18aaaSAndroid Build Coastguard Worker 1147*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1148*c2e18aaaSAndroid Build Coastguard Worker 1149*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, 0) 1150*c2e18aaaSAndroid Build Coastguard Worker 1151*c2e18aaaSAndroid Build Coastguard Worker def test_return_0_when_no_mod_info(self): 1152*c2e18aaaSAndroid Build Coastguard Worker module_name = 'hello_world_test' 1153*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1154*c2e18aaaSAndroid Build Coastguard Worker 1155*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.get_robolectric_type(module_name) 1156*c2e18aaaSAndroid Build Coastguard Worker 1157*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual(return_value, 0) 1158*c2e18aaaSAndroid Build Coastguard Worker 1159*c2e18aaaSAndroid Build Coastguard Worker 1160*c2e18aaaSAndroid Build Coastguard Workerclass IsLegacyRobolectricClassTest(ModuleInfoTestFixture): 1161*c2e18aaaSAndroid Build Coastguard Worker """Tests is_legacy_robolectric_class in various conditions.""" 1162*c2e18aaaSAndroid Build Coastguard Worker 1163*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_if_module_class_is_robolectric(self): 1164*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(classes=[constants.MODULE_CLASS_ROBOLECTRIC]) 1165*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1166*c2e18aaaSAndroid Build Coastguard Worker 1167*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_legacy_robolectric_class(test_module_info) 1168*c2e18aaaSAndroid Build Coastguard Worker 1169*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 1170*c2e18aaaSAndroid Build Coastguard Worker 1171*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_if_module_class_is_not_robolectric(self): 1172*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(classes=['not_robolectric']) 1173*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1174*c2e18aaaSAndroid Build Coastguard Worker 1175*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_legacy_robolectric_class(test_module_info) 1176*c2e18aaaSAndroid Build Coastguard Worker 1177*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 1178*c2e18aaaSAndroid Build Coastguard Worker 1179*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_if_module_class_is_empty(self): 1180*c2e18aaaSAndroid Build Coastguard Worker test_module_info = module(classes=[]) 1181*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1182*c2e18aaaSAndroid Build Coastguard Worker 1183*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_legacy_robolectric_class(test_module_info) 1184*c2e18aaaSAndroid Build Coastguard Worker 1185*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 1186*c2e18aaaSAndroid Build Coastguard Worker 1187*c2e18aaaSAndroid Build Coastguard Worker 1188*c2e18aaaSAndroid Build Coastguard Workerclass IsTestableModuleTest(ModuleInfoTestFixture): 1189*c2e18aaaSAndroid Build Coastguard Worker """Tests is_testable_module in various conditions.""" 1190*c2e18aaaSAndroid Build Coastguard Worker 1191*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_for_tradefed_testable_module(self): 1192*c2e18aaaSAndroid Build Coastguard Worker info = test_module() 1193*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1194*c2e18aaaSAndroid Build Coastguard Worker 1195*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_testable_module(info) 1196*c2e18aaaSAndroid Build Coastguard Worker 1197*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 1198*c2e18aaaSAndroid Build Coastguard Worker 1199*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_for_modern_robolectric_test_module(self): 1200*c2e18aaaSAndroid Build Coastguard Worker info = modern_robolectric_test_module() 1201*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1202*c2e18aaaSAndroid Build Coastguard Worker 1203*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_testable_module(info) 1204*c2e18aaaSAndroid Build Coastguard Worker 1205*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 1206*c2e18aaaSAndroid Build Coastguard Worker 1207*c2e18aaaSAndroid Build Coastguard Worker def test_return_true_for_legacy_robolectric_test_module(self): 1208*c2e18aaaSAndroid Build Coastguard Worker info = legacy_robolectric_test_module() 1209*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info(modules=[info]) 1210*c2e18aaaSAndroid Build Coastguard Worker 1211*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_testable_module(info) 1212*c2e18aaaSAndroid Build Coastguard Worker 1213*c2e18aaaSAndroid Build Coastguard Worker self.assertTrue(return_value) 1214*c2e18aaaSAndroid Build Coastguard Worker 1215*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_for_non_tradefed_testable_module(self): 1216*c2e18aaaSAndroid Build Coastguard Worker info = module( 1217*c2e18aaaSAndroid Build Coastguard Worker auto_test_config=[], test_config=[], installed=['installed_path'] 1218*c2e18aaaSAndroid Build Coastguard Worker ) 1219*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1220*c2e18aaaSAndroid Build Coastguard Worker 1221*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_testable_module(info) 1222*c2e18aaaSAndroid Build Coastguard Worker 1223*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 1224*c2e18aaaSAndroid Build Coastguard Worker 1225*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_for_no_installed_path_module(self): 1226*c2e18aaaSAndroid Build Coastguard Worker info = module(auto_test_config=['true'], installed=[]) 1227*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1228*c2e18aaaSAndroid Build Coastguard Worker 1229*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_testable_module(info) 1230*c2e18aaaSAndroid Build Coastguard Worker 1231*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 1232*c2e18aaaSAndroid Build Coastguard Worker 1233*c2e18aaaSAndroid Build Coastguard Worker def test_return_false_if_module_info_is_empty(self): 1234*c2e18aaaSAndroid Build Coastguard Worker info = {} 1235*c2e18aaaSAndroid Build Coastguard Worker mod_info = self.create_module_info() 1236*c2e18aaaSAndroid Build Coastguard Worker 1237*c2e18aaaSAndroid Build Coastguard Worker return_value = mod_info.is_testable_module(info) 1238*c2e18aaaSAndroid Build Coastguard Worker 1239*c2e18aaaSAndroid Build Coastguard Worker self.assertFalse(return_value) 1240*c2e18aaaSAndroid Build Coastguard Worker 1241*c2e18aaaSAndroid Build Coastguard Worker 1242*c2e18aaaSAndroid Build Coastguard Workerdef create_module_info(modules=None): 1243*c2e18aaaSAndroid Build Coastguard Worker name_to_module_info = {} 1244*c2e18aaaSAndroid Build Coastguard Worker modules = modules or [] 1245*c2e18aaaSAndroid Build Coastguard Worker 1246*c2e18aaaSAndroid Build Coastguard Worker for m in modules: 1247*c2e18aaaSAndroid Build Coastguard Worker name_to_module_info[m['module_name']] = m 1248*c2e18aaaSAndroid Build Coastguard Worker 1249*c2e18aaaSAndroid Build Coastguard Worker return module_info.load_from_dict(name_to_module_info) 1250*c2e18aaaSAndroid Build Coastguard Worker 1251*c2e18aaaSAndroid Build Coastguard Worker 1252*c2e18aaaSAndroid Build Coastguard Workerdef test_module(**kwargs): 1253*c2e18aaaSAndroid Build Coastguard Worker kwargs.setdefault('name', 'hello_world_test') 1254*c2e18aaaSAndroid Build Coastguard Worker return test(module(**kwargs)) 1255*c2e18aaaSAndroid Build Coastguard Worker 1256*c2e18aaaSAndroid Build Coastguard Worker 1257*c2e18aaaSAndroid Build Coastguard Workerdef non_test_module(**kwargs): 1258*c2e18aaaSAndroid Build Coastguard Worker kwargs.setdefault('name', 'not_a_test') 1259*c2e18aaaSAndroid Build Coastguard Worker return non_test(module(**kwargs)) 1260*c2e18aaaSAndroid Build Coastguard Worker 1261*c2e18aaaSAndroid Build Coastguard Worker 1262*c2e18aaaSAndroid Build Coastguard Workerdef modern_robolectric_test_module(**kwargs): 1263*c2e18aaaSAndroid Build Coastguard Worker kwargs.setdefault('name', 'hello_world_test') 1264*c2e18aaaSAndroid Build Coastguard Worker return test(robolectric_tests_suite(module(**kwargs))) 1265*c2e18aaaSAndroid Build Coastguard Worker 1266*c2e18aaaSAndroid Build Coastguard Worker 1267*c2e18aaaSAndroid Build Coastguard Workerdef legacy_robolectric_test_module(**kwargs): 1268*c2e18aaaSAndroid Build Coastguard Worker kwargs.setdefault('name', 'Run_hello_world_test') 1269*c2e18aaaSAndroid Build Coastguard Worker return robolectric_class_non_test_module(**kwargs) 1270*c2e18aaaSAndroid Build Coastguard Worker 1271*c2e18aaaSAndroid Build Coastguard Worker 1272*c2e18aaaSAndroid Build Coastguard Workerdef robolectric_class_test_module(**kwargs): 1273*c2e18aaaSAndroid Build Coastguard Worker kwargs.setdefault('name', 'hello_world_test') 1274*c2e18aaaSAndroid Build Coastguard Worker return test(robolectric_class(module(**kwargs))) 1275*c2e18aaaSAndroid Build Coastguard Worker 1276*c2e18aaaSAndroid Build Coastguard Worker 1277*c2e18aaaSAndroid Build Coastguard Workerdef robolectric_class_non_test_module(**kwargs): 1278*c2e18aaaSAndroid Build Coastguard Worker kwargs.setdefault('name', 'hello_world_test') 1279*c2e18aaaSAndroid Build Coastguard Worker return non_test(robolectric_class(module(**kwargs))) 1280*c2e18aaaSAndroid Build Coastguard Worker 1281*c2e18aaaSAndroid Build Coastguard Worker 1282*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=too-many-arguments, too-many-locals 1283*c2e18aaaSAndroid Build Coastguard Workerdef module( 1284*c2e18aaaSAndroid Build Coastguard Worker name=None, 1285*c2e18aaaSAndroid Build Coastguard Worker path=None, 1286*c2e18aaaSAndroid Build Coastguard Worker installed=None, 1287*c2e18aaaSAndroid Build Coastguard Worker classes=None, 1288*c2e18aaaSAndroid Build Coastguard Worker auto_test_config=None, 1289*c2e18aaaSAndroid Build Coastguard Worker test_config=None, 1290*c2e18aaaSAndroid Build Coastguard Worker shared_libs=None, 1291*c2e18aaaSAndroid Build Coastguard Worker dependencies=None, 1292*c2e18aaaSAndroid Build Coastguard Worker runtime_dependencies=None, 1293*c2e18aaaSAndroid Build Coastguard Worker data=None, 1294*c2e18aaaSAndroid Build Coastguard Worker data_dependencies=None, 1295*c2e18aaaSAndroid Build Coastguard Worker compatibility_suites=None, 1296*c2e18aaaSAndroid Build Coastguard Worker host_dependencies=None, 1297*c2e18aaaSAndroid Build Coastguard Worker srcs=None, 1298*c2e18aaaSAndroid Build Coastguard Worker supported_variants=None, 1299*c2e18aaaSAndroid Build Coastguard Worker code_under_test=None, 1300*c2e18aaaSAndroid Build Coastguard Worker): 1301*c2e18aaaSAndroid Build Coastguard Worker name = name or 'libhello' 1302*c2e18aaaSAndroid Build Coastguard Worker 1303*c2e18aaaSAndroid Build Coastguard Worker m = {} 1304*c2e18aaaSAndroid Build Coastguard Worker 1305*c2e18aaaSAndroid Build Coastguard Worker m['module_name'] = name 1306*c2e18aaaSAndroid Build Coastguard Worker m['class'] = classes or ['ETC'] 1307*c2e18aaaSAndroid Build Coastguard Worker m['path'] = [path or ''] 1308*c2e18aaaSAndroid Build Coastguard Worker m['installed'] = installed or [] 1309*c2e18aaaSAndroid Build Coastguard Worker m['is_unit_test'] = 'false' 1310*c2e18aaaSAndroid Build Coastguard Worker m['auto_test_config'] = auto_test_config or [] 1311*c2e18aaaSAndroid Build Coastguard Worker m['test_config'] = test_config or [] 1312*c2e18aaaSAndroid Build Coastguard Worker m['shared_libs'] = shared_libs or [] 1313*c2e18aaaSAndroid Build Coastguard Worker m['runtime_dependencies'] = runtime_dependencies or [] 1314*c2e18aaaSAndroid Build Coastguard Worker m['dependencies'] = dependencies or [] 1315*c2e18aaaSAndroid Build Coastguard Worker m['data'] = data or [] 1316*c2e18aaaSAndroid Build Coastguard Worker m['data_dependencies'] = data_dependencies or [] 1317*c2e18aaaSAndroid Build Coastguard Worker m['compatibility_suites'] = compatibility_suites or [] 1318*c2e18aaaSAndroid Build Coastguard Worker m['host_dependencies'] = host_dependencies or [] 1319*c2e18aaaSAndroid Build Coastguard Worker m['srcs'] = srcs or [] 1320*c2e18aaaSAndroid Build Coastguard Worker m['supported_variants'] = supported_variants or [] 1321*c2e18aaaSAndroid Build Coastguard Worker m['code_under_test'] = code_under_test or [] 1322*c2e18aaaSAndroid Build Coastguard Worker return m 1323*c2e18aaaSAndroid Build Coastguard Worker 1324*c2e18aaaSAndroid Build Coastguard Worker 1325*c2e18aaaSAndroid Build Coastguard Workerdef test(info): 1326*c2e18aaaSAndroid Build Coastguard Worker info['auto_test_config'] = ['true'] 1327*c2e18aaaSAndroid Build Coastguard Worker info['installed'] = ['installed_path'] 1328*c2e18aaaSAndroid Build Coastguard Worker return info 1329*c2e18aaaSAndroid Build Coastguard Worker 1330*c2e18aaaSAndroid Build Coastguard Worker 1331*c2e18aaaSAndroid Build Coastguard Workerdef non_test(info): 1332*c2e18aaaSAndroid Build Coastguard Worker info['auto_test_config'] = [] 1333*c2e18aaaSAndroid Build Coastguard Worker info['installed'] = [] 1334*c2e18aaaSAndroid Build Coastguard Worker return info 1335*c2e18aaaSAndroid Build Coastguard Worker 1336*c2e18aaaSAndroid Build Coastguard Worker 1337*c2e18aaaSAndroid Build Coastguard Workerdef robolectric_class(info): 1338*c2e18aaaSAndroid Build Coastguard Worker info['class'] = ['ROBOLECTRIC'] 1339*c2e18aaaSAndroid Build Coastguard Worker return info 1340*c2e18aaaSAndroid Build Coastguard Worker 1341*c2e18aaaSAndroid Build Coastguard Worker 1342*c2e18aaaSAndroid Build Coastguard Workerdef robolectric_tests_suite(info): 1343*c2e18aaaSAndroid Build Coastguard Worker info = test(info) 1344*c2e18aaaSAndroid Build Coastguard Worker info.setdefault('compatibility_suites', []).append('robolectric-tests') 1345*c2e18aaaSAndroid Build Coastguard Worker return info 1346*c2e18aaaSAndroid Build Coastguard Worker 1347*c2e18aaaSAndroid Build Coastguard Worker 1348*c2e18aaaSAndroid Build Coastguard Workerif __name__ == '__main__': 1349*c2e18aaaSAndroid Build Coastguard Worker unittest.main() 1350