blob: 0a3ddde309e2a2ea746d36cb432bda7339593292 [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': {
Xianyuan Jiaa9855092019-10-01 16:20:21 -070032 'param1': 1,
33 'param2': 4
Xianyuan Jia239dbea2019-08-19 16:21:49 -070034 },
35 'MockInstrumentationBaseTest': {
36 'MockController': {
Xianyuan Jiaa9855092019-10-01 16:20:21 -070037 'param2': 2,
38 'param3': 5
Xianyuan Jia239dbea2019-08-19 16:21:49 -070039 },
40 'test_case': {
41 'MockController': {
42 'param3': 3
43 }
44 }
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070045 }
46}
47
48MOCK_ACTS_USERPARAMS = {
49 'file1': '/path/to/file1',
50 'file2': '/path/to/file2'
51}
52
53
54class MockInstrumentationBaseTest(InstrumentationBaseTest):
55 """Mock test class to initialize required attributes."""
56 def __init__(self):
57 self.user_params = MOCK_ACTS_USERPARAMS
Xianyuan Jia239dbea2019-08-19 16:21:49 -070058 self.current_test_name = None
Xianyuan Jia997ca682019-08-20 17:58:06 -070059 self._instrumentation_config = ConfigWrapper(
60 MOCK_INSTRUMENTATION_CONFIG)
Xianyuan Jiae327f5b2019-09-19 11:15:04 -070061 self._class_config = self._instrumentation_config.get_config(
62 self.__class__.__name__)
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070063
64
65class InstrumentationBaseTestTest(unittest.TestCase):
66 def setUp(self):
67 self.instrumentation_test = MockInstrumentationBaseTest()
68
69 def test_resolve_files_from_config(self):
70 """Test that params with the 'FILE' marker are properly substituted
71 with the corresponding paths from ACTS user_params.
72 """
Xianyuan Jia997ca682019-08-20 17:58:06 -070073 mock_config = copy.deepcopy(MOCK_INSTRUMENTATION_CONFIG)
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070074 self.instrumentation_test._resolve_file_paths(mock_config)
Xianyuan Jia997ca682019-08-20 17:58:06 -070075 self.assertEqual(mock_config['not_file'],
76 MOCK_INSTRUMENTATION_CONFIG['not_file'])
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -070077 self.assertEqual(mock_config['file1'], MOCK_ACTS_USERPARAMS['file1'])
78 self.assertEqual(mock_config['lvl1']['file2'],
79 MOCK_ACTS_USERPARAMS['file2'])
80 self.assertEqual(mock_config['lvl1']['lvl2']['file1'],
81 MOCK_ACTS_USERPARAMS['file1'])
82
Xianyuan Jia239dbea2019-08-19 16:21:49 -070083 def test_get_controller_config_for_test_case(self):
84 """Test that _get_controller_config returns the corresponding
85 controller config for the current test case.
86 """
87 self.instrumentation_test.current_test_name = 'test_case'
Xianyuan Jiaa9855092019-10-01 16:20:21 -070088 config = self.instrumentation_test._get_merged_config(
Xianyuan Jia239dbea2019-08-19 16:21:49 -070089 'MockController')
Xianyuan Jiaa9855092019-10-01 16:20:21 -070090 self.assertEqual(config.get('param1'), 1)
91 self.assertEqual(config.get('param2'), 2)
92 self.assertEqual(config.get('param3'), 3)
Xianyuan Jia239dbea2019-08-19 16:21:49 -070093
94 def test_get_controller_config_for_test_class(self):
95 """Test that _get_controller_config returns the controller config for
96 the current test class (while no test case is running).
97 """
Xianyuan Jiaa9855092019-10-01 16:20:21 -070098 config = self.instrumentation_test._get_merged_config(
Xianyuan Jia239dbea2019-08-19 16:21:49 -070099 'MockController')
Xianyuan Jiaa9855092019-10-01 16:20:21 -0700100 self.assertEqual(config.get('param1'), 1)
101 self.assertEqual(config.get('param2'), 2)
102 self.assertEqual(config.get('param3'), 5)
Xianyuan Jia239dbea2019-08-19 16:21:49 -0700103
Xianyuan Jiaae0d41a2019-04-23 15:09:05 -0700104
105if __name__ == '__main__':
106 unittest.main()