blob: 04ac8e89726912124250485f4d2e1680d67725ee [file] [log] [blame]
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -07001#!/usr/bin/env python3
2#
3# Copyright 2019 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import copy
18import unittest
19
Xianyuan Jia239dbea2019-08-19 16:21:49 -070020from acts.test_utils.instrumentation.config_wrapper import ConfigWrapper
Xianyuan Jia31b53e42019-07-26 12:26:03 -070021from acts.test_utils.instrumentation.instrumentation_base_test import \
22 InstrumentationBaseTest
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070023
Xianyuan Jia997ca682019-08-20 17:58:06 -070024MOCK_INSTRUMENTATION_CONFIG = {
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070025 'not_file': 'NOT_FILE',
26 'file1': 'FILE',
27 'lvl1': {
28 'file2': 'FILE',
29 'lvl2': {'file1': 'FILE'}
Xianyuan Jia239dbea2019-08-19 16:21:49 -070030 },
31 'MockController': {
32 'param1': 1
33 },
34 'MockInstrumentationBaseTest': {
35 'MockController': {
36 'param2': 2
37 },
38 'test_case': {
39 'MockController': {
40 'param3': 3
41 }
42 }
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070043 }
44}
45
46MOCK_ACTS_USERPARAMS = {
47 'file1': '/path/to/file1',
48 'file2': '/path/to/file2'
49}
50
51
52class MockInstrumentationBaseTest(InstrumentationBaseTest):
53 """Mock test class to initialize required attributes."""
54 def __init__(self):
55 self.user_params = MOCK_ACTS_USERPARAMS
Xianyuan Jia239dbea2019-08-19 16:21:49 -070056 self.current_test_name = None
Xianyuan Jia997ca682019-08-20 17:58:06 -070057 self._instrumentation_config = ConfigWrapper(
58 MOCK_INSTRUMENTATION_CONFIG)
Xianyuan Jiae327f5b2019-09-19 11:15:04 -070059 self._class_config = self._instrumentation_config.get_config(
60 self.__class__.__name__)
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070061
62
63class InstrumentationBaseTestTest(unittest.TestCase):
64 def setUp(self):
65 self.instrumentation_test = MockInstrumentationBaseTest()
66
67 def test_resolve_files_from_config(self):
68 """Test that params with the 'FILE' marker are properly substituted
69 with the corresponding paths from ACTS user_params.
70 """
Xianyuan Jia997ca682019-08-20 17:58:06 -070071 mock_config = copy.deepcopy(MOCK_INSTRUMENTATION_CONFIG)
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070072 self.instrumentation_test._resolve_file_paths(mock_config)
Xianyuan Jia997ca682019-08-20 17:58:06 -070073 self.assertEqual(mock_config['not_file'],
74 MOCK_INSTRUMENTATION_CONFIG['not_file'])
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070075 self.assertEqual(mock_config['file1'], MOCK_ACTS_USERPARAMS['file1'])
76 self.assertEqual(mock_config['lvl1']['file2'],
77 MOCK_ACTS_USERPARAMS['file2'])
78 self.assertEqual(mock_config['lvl1']['lvl2']['file1'],
79 MOCK_ACTS_USERPARAMS['file1'])
80
Xianyuan Jia239dbea2019-08-19 16:21:49 -070081 def test_get_controller_config_for_test_case(self):
82 """Test that _get_controller_config returns the corresponding
83 controller config for the current test case.
84 """
85 self.instrumentation_test.current_test_name = 'test_case'
86 config = self.instrumentation_test._get_controller_config(
87 'MockController')
88 self.assertNotIn('param1', config)
89 self.assertNotIn('param2', config)
90 self.assertIn('param3', config)
91
92 def test_get_controller_config_for_test_class(self):
93 """Test that _get_controller_config returns the controller config for
94 the current test class (while no test case is running).
95 """
96 config = self.instrumentation_test._get_controller_config(
97 'MockController')
98 self.assertIn('param1', config)
99 self.assertIn('param2', config)
100 self.assertNotIn('param3', config)
101
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -0700102
103if __name__ == '__main__':
104 unittest.main()