markdr | dd1893d | 2018-02-05 17:13:47 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2016 - 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 | |
| 17 | import os |
| 18 | import re |
| 19 | import sys |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 20 | import uuid |
| 21 | |
markdr | b2e826a | 2017-08-04 21:42:08 -0700 | [diff] [blame] | 22 | if sys.version_info < (3, ): |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 23 | import warnings |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 24 | |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 25 | with warnings.catch_warnings(): |
| 26 | warnings.filterwarnings('ignore', category=PendingDeprecationWarning) |
| 27 | import imp |
| 28 | |
| 29 | import importlib |
| 30 | import unittest2 as unittest |
| 31 | |
| 32 | def import_module(name, path): |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 33 | return imp.load_source(name, path) |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 34 | |
| 35 | def import_acts(): |
| 36 | return importlib.import_module('acts') |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 37 | else: |
| 38 | import importlib.machinery |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 39 | import unittest |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 40 | |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 41 | def import_module(name, path): |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 42 | return importlib.machinery.SourceFileLoader(name, path).load_module() |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 43 | |
| 44 | def import_acts(): |
| 45 | return importlib.import_module('acts') |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 46 | |
| 47 | |
| 48 | PY_FILE_REGEX = re.compile('.+\.py$') |
| 49 | |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 50 | BLACKLIST = [ |
markdr | b2e826a | 2017-08-04 21:42:08 -0700 | [diff] [blame] | 51 | 'acts/controllers/native.py', |
| 52 | 'acts/controllers/native_android_device.py', |
| 53 | 'acts/test_utils/wifi/wifi_power_test_utils.py', |
markdr | 346ad89 | 2017-10-19 11:59:41 -0700 | [diff] [blame] | 54 | 'acts/controllers/packet_sender.py', |
Omar El Ayach | dfdbd3e | 2017-10-02 15:23:53 -0700 | [diff] [blame] | 55 | 'acts/test_utils/wifi/wifi_retail_ap.py', |
markdr | b629b32 | 2017-05-22 13:44:06 -0700 | [diff] [blame] | 56 | 'acts/test_utils/bt/bt_power_test_utils.py', |
globaledge | c16ad34 | 2018-03-19 17:53:16 +0530 | [diff] [blame] | 57 | 'acts/test_utils/coex/coex_test_utils.py', |
Mark De Ruyter | 48f7c83 | 2018-05-08 15:26:03 -0700 | [diff] [blame] | 58 | 'acts/framework/acts/test_utils/coex/CoexBaseTest.py', |
| 59 | 'acts/framework/acts/test_utils/coex/CoexPerformanceBaseTest.py', |
Mark De Ruyter | 40e6885 | 2018-05-17 11:12:41 -0700 | [diff] [blame] | 60 | 'acts/framework/acts/test_utils/power/PowerWiFiBaseTest.py', |
| 61 | 'acts/framework/acts/test_utils/power/PowerCoexBaseTest.py', |
| 62 | 'acts/framework/acts/test_utils/power/PowerBaseTest.py', |
| 63 | 'acts/framework/acts/test_utils/power/PowerBTBaseTest.py', |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 64 | ] |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 65 | |
Mark De Ruyter | a4b9cd3 | 2018-10-17 16:26:02 -0700 | [diff] [blame^] | 66 | BLACKLIST_DIRECTORIES = [ |
| 67 | 'acts/framework/acts/test_utils/' |
| 68 | ] |
| 69 | |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 70 | |
| 71 | class ActsImportTestUtilsTest(unittest.TestCase): |
Mark De Ruyter | a4b9cd3 | 2018-10-17 16:26:02 -0700 | [diff] [blame^] | 72 | """Test that all acts framework imports work.""" |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 73 | |
| 74 | def test_import_acts_successful(self): |
Mark De Ruyter | a4b9cd3 | 2018-10-17 16:26:02 -0700 | [diff] [blame^] | 75 | """Test that importing ACTS works.""" |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 76 | acts = import_acts() |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 77 | self.assertIsNotNone(acts) |
| 78 | |
| 79 | def test_import_framework_successful(self): |
Mark De Ruyter | a4b9cd3 | 2018-10-17 16:26:02 -0700 | [diff] [blame^] | 80 | """Dynamically test all imports from the framework.""" |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 81 | acts = import_acts() |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 82 | if hasattr(acts, '__path__') and len(acts.__path__) > 0: |
| 83 | acts_path = acts.__path__[0] |
| 84 | else: |
| 85 | acts_path = os.path.dirname(acts.__file__) |
| 86 | |
| 87 | for root, _, files in os.walk(acts_path): |
| 88 | for f in files: |
| 89 | full_path = os.path.join(root, f) |
Mark De Ruyter | a4b9cd3 | 2018-10-17 16:26:02 -0700 | [diff] [blame^] | 90 | if (any(full_path.endswith(e) for e in BLACKLIST) or |
| 91 | any(e in full_path for e in BLACKLIST_DIRECTORIES)): |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 92 | continue |
| 93 | |
| 94 | path = os.path.relpath(os.path.join(root, f), os.getcwd()) |
| 95 | |
| 96 | if PY_FILE_REGEX.match(full_path): |
| 97 | with self.subTest(msg='import %s' % path): |
| 98 | fake_module_name = str(uuid.uuid4()) |
Benny Peake | 3d4c4d9 | 2016-12-21 17:18:05 -0800 | [diff] [blame] | 99 | module = import_module(fake_module_name, path) |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 100 | |
| 101 | self.assertIsNotNone(module) |
| 102 | |
| 103 | |
Mark De Ruyter | a4b9cd3 | 2018-10-17 16:26:02 -0700 | [diff] [blame^] | 104 | if __name__ == '__main__': |
Benny Peake | 2be7f95 | 2016-12-20 15:48:13 -0800 | [diff] [blame] | 105 | unittest.main() |