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 test_finder_handler.""" 18*c2e18aaaSAndroid Build Coastguard Worker 19*c2e18aaaSAndroid Build Coastguard Worker# pylint: disable=protected-access 20*c2e18aaaSAndroid Build Coastguard Workerimport unittest 21*c2e18aaaSAndroid Build Coastguard Workerfrom unittest import mock 22*c2e18aaaSAndroid Build Coastguard Worker 23*c2e18aaaSAndroid Build Coastguard Workerfrom atest import atest_error 24*c2e18aaaSAndroid Build Coastguard Workerfrom atest import test_finder_handler 25*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finder_handler import FinderMethod as REF_TYPE 26*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import test_finder_base 27*c2e18aaaSAndroid Build Coastguard Workerfrom atest.test_finders import test_info 28*c2e18aaaSAndroid Build Coastguard Worker 29*c2e18aaaSAndroid Build Coastguard Worker 30*c2e18aaaSAndroid Build Coastguard Worker_EXAMPLE_FINDER_A = 'EXAMPLE_A' 31*c2e18aaaSAndroid Build Coastguard Worker 32*c2e18aaaSAndroid Build Coastguard Worker 33*c2e18aaaSAndroid Build Coastguard Worker@test_finder_base.find_method_register 34*c2e18aaaSAndroid Build Coastguard Workerclass ExampleFinderA(test_finder_base.TestFinderBase): 35*c2e18aaaSAndroid Build Coastguard Worker """Example finder class A.""" 36*c2e18aaaSAndroid Build Coastguard Worker 37*c2e18aaaSAndroid Build Coastguard Worker NAME = _EXAMPLE_FINDER_A 38*c2e18aaaSAndroid Build Coastguard Worker _TEST_RUNNER = 'TEST_RUNNER' 39*c2e18aaaSAndroid Build Coastguard Worker 40*c2e18aaaSAndroid Build Coastguard Worker @test_finder_base.register() 41*c2e18aaaSAndroid Build Coastguard Worker def registered_find_method_from_example_finder(self, test): 42*c2e18aaaSAndroid Build Coastguard Worker """Registered Example find method.""" 43*c2e18aaaSAndroid Build Coastguard Worker if test == 'ExampleFinderATrigger': 44*c2e18aaaSAndroid Build Coastguard Worker return test_info.TestInfo( 45*c2e18aaaSAndroid Build Coastguard Worker test_name=test, test_runner=self._TEST_RUNNER, build_targets=set() 46*c2e18aaaSAndroid Build Coastguard Worker ) 47*c2e18aaaSAndroid Build Coastguard Worker return None 48*c2e18aaaSAndroid Build Coastguard Worker 49*c2e18aaaSAndroid Build Coastguard Worker def unregistered_find_method_from_example_finder(self, _test): 50*c2e18aaaSAndroid Build Coastguard Worker """Unregistered Example find method, should never be called.""" 51*c2e18aaaSAndroid Build Coastguard Worker raise atest_error.ShouldNeverBeCalledError() 52*c2e18aaaSAndroid Build Coastguard Worker 53*c2e18aaaSAndroid Build Coastguard Worker 54*c2e18aaaSAndroid Build Coastguard Worker_TEST_FINDERS_PATCH = { 55*c2e18aaaSAndroid Build Coastguard Worker ExampleFinderA, 56*c2e18aaaSAndroid Build Coastguard Worker} 57*c2e18aaaSAndroid Build Coastguard Worker 58*c2e18aaaSAndroid Build Coastguard Worker 59*c2e18aaaSAndroid Build Coastguard Worker_FINDER_INSTANCES = { 60*c2e18aaaSAndroid Build Coastguard Worker _EXAMPLE_FINDER_A: ExampleFinderA(), 61*c2e18aaaSAndroid Build Coastguard Worker} 62*c2e18aaaSAndroid Build Coastguard Worker 63*c2e18aaaSAndroid Build Coastguard Worker 64*c2e18aaaSAndroid Build Coastguard Workerclass TestFinderHandlerUnittests(unittest.TestCase): 65*c2e18aaaSAndroid Build Coastguard Worker """Unit tests for test_finder_handler.py""" 66*c2e18aaaSAndroid Build Coastguard Worker 67*c2e18aaaSAndroid Build Coastguard Worker def setUp(self): 68*c2e18aaaSAndroid Build Coastguard Worker """Set up for testing.""" 69*c2e18aaaSAndroid Build Coastguard Worker # pylint: disable=invalid-name 70*c2e18aaaSAndroid Build Coastguard Worker # This is so we can see the full diffs when there are mismatches. 71*c2e18aaaSAndroid Build Coastguard Worker self.maxDiff = None 72*c2e18aaaSAndroid Build Coastguard Worker self.empty_mod_info = None 73*c2e18aaaSAndroid Build Coastguard Worker # We want to control the finders we return. 74*c2e18aaaSAndroid Build Coastguard Worker mock.patch( 75*c2e18aaaSAndroid Build Coastguard Worker 'atest.test_finder_handler._get_test_finders', 76*c2e18aaaSAndroid Build Coastguard Worker lambda: _TEST_FINDERS_PATCH, 77*c2e18aaaSAndroid Build Coastguard Worker ).start() 78*c2e18aaaSAndroid Build Coastguard Worker # Since we're going to be comparing instance objects, we'll need to keep 79*c2e18aaaSAndroid Build Coastguard Worker # track of the objects so they align. 80*c2e18aaaSAndroid Build Coastguard Worker mock.patch( 81*c2e18aaaSAndroid Build Coastguard Worker 'atest.test_finder_handler._get_finder_instance_dict', 82*c2e18aaaSAndroid Build Coastguard Worker lambda x: _FINDER_INSTANCES, 83*c2e18aaaSAndroid Build Coastguard Worker ).start() 84*c2e18aaaSAndroid Build Coastguard Worker # We want to mock out the default find methods to make sure we got all 85*c2e18aaaSAndroid Build Coastguard Worker # the methods we expect. 86*c2e18aaaSAndroid Build Coastguard Worker mock.patch( 87*c2e18aaaSAndroid Build Coastguard Worker 'atest.test_finder_handler._get_default_find_methods', 88*c2e18aaaSAndroid Build Coastguard Worker lambda x, y: [ 89*c2e18aaaSAndroid Build Coastguard Worker test_finder_base.Finder( 90*c2e18aaaSAndroid Build Coastguard Worker _FINDER_INSTANCES[_EXAMPLE_FINDER_A], 91*c2e18aaaSAndroid Build Coastguard Worker ExampleFinderA.unregistered_find_method_from_example_finder, 92*c2e18aaaSAndroid Build Coastguard Worker _EXAMPLE_FINDER_A, 93*c2e18aaaSAndroid Build Coastguard Worker ) 94*c2e18aaaSAndroid Build Coastguard Worker ], 95*c2e18aaaSAndroid Build Coastguard Worker ).start() 96*c2e18aaaSAndroid Build Coastguard Worker 97*c2e18aaaSAndroid Build Coastguard Worker def tearDown(self): 98*c2e18aaaSAndroid Build Coastguard Worker """Tear down.""" 99*c2e18aaaSAndroid Build Coastguard Worker mock.patch.stopall() 100*c2e18aaaSAndroid Build Coastguard Worker 101*c2e18aaaSAndroid Build Coastguard Worker def test_get_test_reference_types(self): 102*c2e18aaaSAndroid Build Coastguard Worker """Test _get_test_reference_types parses reference types correctly.""" 103*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 104*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('ModuleOrClassName'), 105*c2e18aaaSAndroid Build Coastguard Worker [ 106*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 107*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE, 108*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 109*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CONFIG, 110*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN, 111*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CLASS, 112*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 113*c2e18aaaSAndroid Build Coastguard Worker ], 114*c2e18aaaSAndroid Build Coastguard Worker ) 115*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 116*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('Module_or_Class_name'), 117*c2e18aaaSAndroid Build Coastguard Worker [ 118*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 119*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE, 120*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 121*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CONFIG, 122*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN, 123*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CLASS, 124*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 125*c2e18aaaSAndroid Build Coastguard Worker ], 126*c2e18aaaSAndroid Build Coastguard Worker ) 127*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 128*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('SuiteName'), 129*c2e18aaaSAndroid Build Coastguard Worker [ 130*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 131*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE, 132*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 133*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CONFIG, 134*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN, 135*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CLASS, 136*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 137*c2e18aaaSAndroid Build Coastguard Worker ], 138*c2e18aaaSAndroid Build Coastguard Worker ) 139*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 140*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('Suite-Name'), 141*c2e18aaaSAndroid Build Coastguard Worker [ 142*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 143*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE, 144*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 145*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CONFIG, 146*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN, 147*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CLASS, 148*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 149*c2e18aaaSAndroid Build Coastguard Worker ], 150*c2e18aaaSAndroid Build Coastguard Worker ) 151*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 152*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('some.package'), 153*c2e18aaaSAndroid Build Coastguard Worker [ 154*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 155*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE, 156*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.QUALIFIED_CLASS, 157*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.PACKAGE, 158*c2e18aaaSAndroid Build Coastguard Worker ], 159*c2e18aaaSAndroid Build Coastguard Worker ) 160*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 161*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('fully.q.Class'), 162*c2e18aaaSAndroid Build Coastguard Worker [ 163*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 164*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE, 165*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.QUALIFIED_CLASS, 166*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.PACKAGE, 167*c2e18aaaSAndroid Build Coastguard Worker ], 168*c2e18aaaSAndroid Build Coastguard Worker ) 169*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 170*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('Integration.xml'), 171*c2e18aaaSAndroid Build Coastguard Worker [ 172*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 173*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 174*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 175*c2e18aaaSAndroid Build Coastguard Worker ], 176*c2e18aaaSAndroid Build Coastguard Worker ) 177*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 178*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('SomeClass.java'), 179*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 180*c2e18aaaSAndroid Build Coastguard Worker ) 181*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 182*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('SomeClass.kt'), 183*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 184*c2e18aaaSAndroid Build Coastguard Worker ) 185*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 186*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('Android.mk'), 187*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 188*c2e18aaaSAndroid Build Coastguard Worker ) 189*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 190*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('Android.bp'), 191*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 192*c2e18aaaSAndroid Build Coastguard Worker ) 193*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 194*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('SomeTest.cc'), 195*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 196*c2e18aaaSAndroid Build Coastguard Worker ) 197*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 198*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('SomeTest.cpp'), 199*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 200*c2e18aaaSAndroid Build Coastguard Worker ) 201*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 202*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('SomeTest.cc#method'), 203*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_FILE_PATH], 204*c2e18aaaSAndroid Build Coastguard Worker ) 205*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 206*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('module:Class'), 207*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_CLASS, REF_TYPE.INTEGRATION], 208*c2e18aaaSAndroid Build Coastguard Worker ) 209*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 210*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('module:f.q.Class'), 211*c2e18aaaSAndroid Build Coastguard Worker [ 212*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 213*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_CLASS, 214*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_PACKAGE, 215*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 216*c2e18aaaSAndroid Build Coastguard Worker ], 217*c2e18aaaSAndroid Build Coastguard Worker ) 218*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 219*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('module:a.package'), 220*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_PACKAGE, REF_TYPE.MODULE_CLASS], 221*c2e18aaaSAndroid Build Coastguard Worker ) 222*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 223*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('.'), 224*c2e18aaaSAndroid Build Coastguard Worker [ 225*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 226*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 227*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 228*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 229*c2e18aaaSAndroid Build Coastguard Worker ], 230*c2e18aaaSAndroid Build Coastguard Worker ) 231*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 232*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('..'), 233*c2e18aaaSAndroid Build Coastguard Worker [ 234*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 235*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 236*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 237*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 238*c2e18aaaSAndroid Build Coastguard Worker ], 239*c2e18aaaSAndroid Build Coastguard Worker ) 240*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 241*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('./rel/path/to/test'), 242*c2e18aaaSAndroid Build Coastguard Worker [ 243*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 244*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 245*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 246*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 247*c2e18aaaSAndroid Build Coastguard Worker ], 248*c2e18aaaSAndroid Build Coastguard Worker ) 249*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 250*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('rel/path/to/test'), 251*c2e18aaaSAndroid Build Coastguard Worker [ 252*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 253*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 254*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 255*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 256*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 257*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 258*c2e18aaaSAndroid Build Coastguard Worker ], 259*c2e18aaaSAndroid Build Coastguard Worker ) 260*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 261*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('/abs/path/to/test'), 262*c2e18aaaSAndroid Build Coastguard Worker [ 263*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 264*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 265*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 266*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 267*c2e18aaaSAndroid Build Coastguard Worker ], 268*c2e18aaaSAndroid Build Coastguard Worker ) 269*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 270*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('int/test'), 271*c2e18aaaSAndroid Build Coastguard Worker [ 272*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 273*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 274*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 275*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 276*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 277*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 278*c2e18aaaSAndroid Build Coastguard Worker ], 279*c2e18aaaSAndroid Build Coastguard Worker ) 280*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 281*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types( 282*c2e18aaaSAndroid Build Coastguard Worker 'int/test:fully.qual.Class#m' 283*c2e18aaaSAndroid Build Coastguard Worker ), 284*c2e18aaaSAndroid Build Coastguard Worker [ 285*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 286*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 287*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 288*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 289*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 290*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_CLASS, 291*c2e18aaaSAndroid Build Coastguard Worker ], 292*c2e18aaaSAndroid Build Coastguard Worker ) 293*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 294*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types('int/test:Class#method'), 295*c2e18aaaSAndroid Build Coastguard Worker [ 296*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 297*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 298*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 299*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 300*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 301*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_CLASS, 302*c2e18aaaSAndroid Build Coastguard Worker ], 303*c2e18aaaSAndroid Build Coastguard Worker ) 304*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 305*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types( 306*c2e18aaaSAndroid Build Coastguard Worker 'int_name_no_slash:Class#m' 307*c2e18aaaSAndroid Build Coastguard Worker ), 308*c2e18aaaSAndroid Build Coastguard Worker [REF_TYPE.CACHE, REF_TYPE.MODULE_CLASS, REF_TYPE.INTEGRATION], 309*c2e18aaaSAndroid Build Coastguard Worker ) 310*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 311*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types( 312*c2e18aaaSAndroid Build Coastguard Worker 'gtest_module:Class_Prefix/Class#Method/Method_Suffix' 313*c2e18aaaSAndroid Build Coastguard Worker ), 314*c2e18aaaSAndroid Build Coastguard Worker [ 315*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 316*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 317*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 318*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 319*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 320*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_CLASS, 321*c2e18aaaSAndroid Build Coastguard Worker ], 322*c2e18aaaSAndroid Build Coastguard Worker ) 323*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 324*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_test_reference_types( 325*c2e18aaaSAndroid Build Coastguard Worker 'Class_Prefix/Class#Method/Method_Suffix' 326*c2e18aaaSAndroid Build Coastguard Worker ), 327*c2e18aaaSAndroid Build Coastguard Worker [ 328*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CACHE, 329*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.MODULE_FILE_PATH, 330*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION_FILE_PATH, 331*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.INTEGRATION, 332*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.SUITE_PLAN_FILE_PATH, 333*c2e18aaaSAndroid Build Coastguard Worker REF_TYPE.CC_CLASS, 334*c2e18aaaSAndroid Build Coastguard Worker ], 335*c2e18aaaSAndroid Build Coastguard Worker ) 336*c2e18aaaSAndroid Build Coastguard Worker 337*c2e18aaaSAndroid Build Coastguard Worker def test_get_registered_find_methods(self): 338*c2e18aaaSAndroid Build Coastguard Worker """Test that we get the registered find methods.""" 339*c2e18aaaSAndroid Build Coastguard Worker empty_mod_info = None 340*c2e18aaaSAndroid Build Coastguard Worker example_finder_a_instance = test_finder_handler._get_finder_instance_dict( 341*c2e18aaaSAndroid Build Coastguard Worker empty_mod_info 342*c2e18aaaSAndroid Build Coastguard Worker )[_EXAMPLE_FINDER_A] 343*c2e18aaaSAndroid Build Coastguard Worker should_equal = [ 344*c2e18aaaSAndroid Build Coastguard Worker test_finder_base.Finder( 345*c2e18aaaSAndroid Build Coastguard Worker example_finder_a_instance, 346*c2e18aaaSAndroid Build Coastguard Worker ExampleFinderA.registered_find_method_from_example_finder, 347*c2e18aaaSAndroid Build Coastguard Worker _EXAMPLE_FINDER_A, 348*c2e18aaaSAndroid Build Coastguard Worker ) 349*c2e18aaaSAndroid Build Coastguard Worker ] 350*c2e18aaaSAndroid Build Coastguard Worker should_not_equal = [ 351*c2e18aaaSAndroid Build Coastguard Worker test_finder_base.Finder( 352*c2e18aaaSAndroid Build Coastguard Worker example_finder_a_instance, 353*c2e18aaaSAndroid Build Coastguard Worker ExampleFinderA.unregistered_find_method_from_example_finder, 354*c2e18aaaSAndroid Build Coastguard Worker _EXAMPLE_FINDER_A, 355*c2e18aaaSAndroid Build Coastguard Worker ) 356*c2e18aaaSAndroid Build Coastguard Worker ] 357*c2e18aaaSAndroid Build Coastguard Worker # Let's make sure we see the registered method. 358*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 359*c2e18aaaSAndroid Build Coastguard Worker should_equal, 360*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_registered_find_methods(empty_mod_info), 361*c2e18aaaSAndroid Build Coastguard Worker ) 362*c2e18aaaSAndroid Build Coastguard Worker # Make sure we don't see the unregistered method here. 363*c2e18aaaSAndroid Build Coastguard Worker self.assertNotEqual( 364*c2e18aaaSAndroid Build Coastguard Worker should_not_equal, 365*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler._get_registered_find_methods(empty_mod_info), 366*c2e18aaaSAndroid Build Coastguard Worker ) 367*c2e18aaaSAndroid Build Coastguard Worker 368*c2e18aaaSAndroid Build Coastguard Worker def test_get_find_methods_for_test(self): 369*c2e18aaaSAndroid Build Coastguard Worker """Test that we get the find methods we expect.""" 370*c2e18aaaSAndroid Build Coastguard Worker # Let's see that we get the unregistered and registered find methods in 371*c2e18aaaSAndroid Build Coastguard Worker # the order we expect. 372*c2e18aaaSAndroid Build Coastguard Worker test = '' 373*c2e18aaaSAndroid Build Coastguard Worker registered_find_methods = [ 374*c2e18aaaSAndroid Build Coastguard Worker test_finder_base.Finder( 375*c2e18aaaSAndroid Build Coastguard Worker _FINDER_INSTANCES[_EXAMPLE_FINDER_A], 376*c2e18aaaSAndroid Build Coastguard Worker ExampleFinderA.registered_find_method_from_example_finder, 377*c2e18aaaSAndroid Build Coastguard Worker _EXAMPLE_FINDER_A, 378*c2e18aaaSAndroid Build Coastguard Worker ) 379*c2e18aaaSAndroid Build Coastguard Worker ] 380*c2e18aaaSAndroid Build Coastguard Worker default_find_methods = [ 381*c2e18aaaSAndroid Build Coastguard Worker test_finder_base.Finder( 382*c2e18aaaSAndroid Build Coastguard Worker _FINDER_INSTANCES[_EXAMPLE_FINDER_A], 383*c2e18aaaSAndroid Build Coastguard Worker ExampleFinderA.unregistered_find_method_from_example_finder, 384*c2e18aaaSAndroid Build Coastguard Worker _EXAMPLE_FINDER_A, 385*c2e18aaaSAndroid Build Coastguard Worker ) 386*c2e18aaaSAndroid Build Coastguard Worker ] 387*c2e18aaaSAndroid Build Coastguard Worker should_equal = registered_find_methods + default_find_methods 388*c2e18aaaSAndroid Build Coastguard Worker self.assertEqual( 389*c2e18aaaSAndroid Build Coastguard Worker should_equal, 390*c2e18aaaSAndroid Build Coastguard Worker test_finder_handler.get_find_methods_for_test( 391*c2e18aaaSAndroid Build Coastguard Worker self.empty_mod_info, test 392*c2e18aaaSAndroid Build Coastguard Worker ), 393*c2e18aaaSAndroid Build Coastguard Worker ) 394*c2e18aaaSAndroid Build Coastguard Worker 395*c2e18aaaSAndroid Build Coastguard Worker 396*c2e18aaaSAndroid Build Coastguard Workerif __name__ == '__main__': 397*c2e18aaaSAndroid Build Coastguard Worker unittest.main() 398