diff options
Diffstat (limited to 'tests/mobly/output_test.py')
-rwxr-xr-x | tests/mobly/output_test.py | 143 |
1 files changed, 84 insertions, 59 deletions
diff --git a/tests/mobly/output_test.py b/tests/mobly/output_test.py index 4b2d94a..bbffa89 100755 --- a/tests/mobly/output_test.py +++ b/tests/mobly/output_test.py @@ -47,7 +47,7 @@ class OutputTest(unittest.TestCase): self.base_mock_test_config.controller_configs = {} self.base_mock_test_config.user_params = { 'icecream': 42, - 'extra_param': 'haha' + 'extra_param': 'haha', } self.base_mock_test_config.log_path = self.tmp_dir self.log_dir = self.base_mock_test_config.log_path @@ -59,13 +59,10 @@ class OutputTest(unittest.TestCase): def create_mock_test_config(self, base_mock_test_config): mock_test_config = base_mock_test_config.copy() mock_ctrlr_config_name = mock_controller.MOBLY_CONTROLLER_CONFIG_NAME - my_config = [{ - 'serial': 'xxxx', - 'magic': 'Magic1' - }, { - 'serial': 'xxxx', - 'magic': 'Magic2' - }] + my_config = [ + {'serial': 'xxxx', 'magic': 'Magic1'}, + {'serial': 'xxxx', 'magic': 'Magic2'}, + ] mock_test_config.controller_configs[mock_ctrlr_config_name] = my_config return mock_test_config @@ -76,8 +73,9 @@ class OutputTest(unittest.TestCase): return (summary_file_path, debug_log_path, info_log_path) def assert_output_logs_exist(self, output_dir): - (summary_file_path, debug_log_path, - info_log_path) = self.get_output_logs(output_dir) + (summary_file_path, debug_log_path, info_log_path) = self.get_output_logs( + output_dir + ) self.assertTrue(os.path.isfile(summary_file_path)) self.assertTrue(os.path.isfile(debug_log_path)) self.assertTrue(os.path.isfile(info_log_path)) @@ -96,8 +94,10 @@ class OutputTest(unittest.TestCase): with tr.mobly_logger() as log_path: self.assertEqual(log_path, logging.log_path) - @unittest.skipIf(platform.system() == 'Windows', - 'Symlinks are usually specific to Unix operating systems') + @unittest.skipIf( + platform.system() == 'Windows', + 'Symlinks are usually specific to Unix operating systems', + ) def test_symlink(self): """Verifies the symlink is created and links properly.""" mock_test_config = self.create_mock_test_config(self.base_mock_test_config) @@ -107,12 +107,14 @@ class OutputTest(unittest.TestCase): symlink = os.path.join(self.log_dir, self.testbed_name, 'latest') self.assertEqual(os.readlink(symlink), logging.log_path) - @unittest.skipIf(platform.system() != 'Windows', - 'Shortcuts are specific to Windows operating systems') + @unittest.skipIf( + platform.system() != 'Windows', + 'Shortcuts are specific to Windows operating systems', + ) def test_shortcut(self): """Verifies the shortcut is created and links properly.""" shortcut_path = os.path.join(self.log_dir, self.testbed_name, 'latest.lnk') - shell = client.Dispatch("WScript.Shell") + shell = client.Dispatch('WScript.Shell') shortcut = shell.CreateShortCut(shortcut_path) self.assertFalse(shortcut.Targetpath) mock_test_config = self.create_mock_test_config(self.base_mock_test_config) @@ -122,9 +124,11 @@ class OutputTest(unittest.TestCase): shortcut = shell.CreateShortCut(shortcut_path) # Normalize paths for case and truncation normalized_shortcut_path = os.path.normcase( - win32file.GetLongPathName(shortcut.Targetpath)) + win32file.GetLongPathName(shortcut.Targetpath) + ) normalized_logger_path = os.path.normcase( - win32file.GetLongPathName(logging.log_path)) + win32file.GetLongPathName(logging.log_path) + ) self.assertEqual(normalized_shortcut_path, normalized_logger_path) @mock.patch('mobly.utils.create_alias') @@ -134,8 +138,9 @@ class OutputTest(unittest.TestCase): with tr.mobly_logger(): pass expected_alias_dir = os.path.join(self.log_dir, self.testbed_name, 'latest') - mock_create_alias.assert_called_once_with(logging.log_path, - expected_alias_dir) + mock_create_alias.assert_called_once_with( + logging.log_path, expected_alias_dir + ) @mock.patch('mobly.utils.create_alias') def test_mobly_logger_with_custom_latest_log_alias(self, mock_create_alias): @@ -143,14 +148,17 @@ class OutputTest(unittest.TestCase): tr = test_runner.TestRunner(self.log_dir, self.testbed_name) with tr.mobly_logger(alias='history'): pass - expected_alias_dir = os.path.join(self.log_dir, self.testbed_name, - 'history') - mock_create_alias.assert_called_once_with(logging.log_path, - expected_alias_dir) + expected_alias_dir = os.path.join( + self.log_dir, self.testbed_name, 'history' + ) + mock_create_alias.assert_called_once_with( + logging.log_path, expected_alias_dir + ) @mock.patch('mobly.utils.create_alias') def test_mobly_logger_skips_latest_log_alias_when_none( - self, mock_create_alias): + self, mock_create_alias + ): mock_test_config = self.create_mock_test_config(self.base_mock_test_config) tr = test_runner.TestRunner(self.log_dir, self.testbed_name) with tr.mobly_logger(alias=None): @@ -159,7 +167,8 @@ class OutputTest(unittest.TestCase): @mock.patch('mobly.utils.create_alias') def test_mobly_logger_skips_latest_log_alias_when_empty( - self, mock_create_alias): + self, mock_create_alias + ): mock_test_config = self.create_mock_test_config(self.base_mock_test_config) tr = test_runner.TestRunner(self.log_dir, self.testbed_name) with tr.mobly_logger(alias=''): @@ -182,15 +191,17 @@ class OutputTest(unittest.TestCase): tr.add_test_class(mock_test_config, integration_test.IntegrationTest) tr.run() output_dir = logging.root_output_path - (summary_file_path, debug_log_path, - info_log_path) = self.assert_output_logs_exist(output_dir) + (summary_file_path, debug_log_path, info_log_path) = ( + self.assert_output_logs_exist(output_dir) + ) self.assert_log_contents(debug_log_path, whitelist=[debug_uuid, info_uuid]) - self.assert_log_contents(info_log_path, - whitelist=[info_uuid], - blacklist=[debug_uuid]) + self.assert_log_contents( + info_log_path, whitelist=[info_uuid], blacklist=[debug_uuid] + ) - @mock.patch('mobly.logger.get_log_file_timestamp', - side_effect=str(time.time())) + @mock.patch( + 'mobly.logger.get_log_file_timestamp', side_effect=str(time.time()) + ) def test_run_twice_for_two_sets_of_logs(self, mock_timestamp): """Verifies the expected output files from a test run. @@ -210,8 +221,9 @@ class OutputTest(unittest.TestCase): self.assert_output_logs_exist(output_dir1) self.assert_output_logs_exist(output_dir2) - @mock.patch('mobly.logger.get_log_file_timestamp', - side_effect=str(time.time())) + @mock.patch( + 'mobly.logger.get_log_file_timestamp', side_effect=str(time.time()) + ) def test_teardown_erases_logs(self, mock_timestamp): """Verifies the expected output files from a test run. @@ -237,17 +249,23 @@ class OutputTest(unittest.TestCase): self.assertNotEqual(output_dir1, output_dir2) - (summary_file_path1, debug_log_path1, - info_log_path1) = self.get_output_logs(output_dir1) - (summary_file_path2, debug_log_path2, - info_log_path2) = self.get_output_logs(output_dir2) - - self.assert_log_contents(debug_log_path1, - whitelist=[debug_uuid1, info_uuid1], - blacklist=[info_uuid2, debug_uuid2]) - self.assert_log_contents(debug_log_path2, - whitelist=[debug_uuid2, info_uuid2], - blacklist=[info_uuid1, debug_uuid1]) + (summary_file_path1, debug_log_path1, info_log_path1) = ( + self.get_output_logs(output_dir1) + ) + (summary_file_path2, debug_log_path2, info_log_path2) = ( + self.get_output_logs(output_dir2) + ) + + self.assert_log_contents( + debug_log_path1, + whitelist=[debug_uuid1, info_uuid1], + blacklist=[info_uuid2, debug_uuid2], + ) + self.assert_log_contents( + debug_log_path2, + whitelist=[debug_uuid2, info_uuid2], + blacklist=[info_uuid1, debug_uuid1], + ) def test_basic_output(self): """Verifies the expected output files from a test run. @@ -260,22 +278,24 @@ class OutputTest(unittest.TestCase): with tr.mobly_logger(): tr.add_test_class(mock_test_config, integration_test.IntegrationTest) tr.run() - expected_class_path = os.path.join(logging.root_output_path, - 'IntegrationTest') + expected_class_path = os.path.join( + logging.root_output_path, 'IntegrationTest' + ) self.assertEqual(expected_class_path, logging.log_path) os.path.exists(logging.log_path) output_dir = logging.root_output_path - (summary_file_path, debug_log_path, - info_log_path) = self.assert_output_logs_exist(output_dir) + (summary_file_path, debug_log_path, info_log_path) = ( + self.assert_output_logs_exist(output_dir) + ) summary_entries = [] with io.open(summary_file_path, 'r', encoding='utf-8') as f: for entry in yaml.safe_load_all(f): self.assertTrue(entry['Type']) summary_entries.append(entry) self.assert_log_contents(debug_log_path, whitelist=['DEBUG', 'INFO']) - self.assert_log_contents(info_log_path, - whitelist=['INFO'], - blacklist=['DEBUG']) + self.assert_log_contents( + info_log_path, whitelist=['INFO'], blacklist=['DEBUG'] + ) def test_teardown_class_output(self): """Verifies the summary file includes the failure record for @@ -284,8 +304,9 @@ class OutputTest(unittest.TestCase): mock_test_config = self.base_mock_test_config.copy() tr = test_runner.TestRunner(self.log_dir, self.testbed_name) with tr.mobly_logger(): - tr.add_test_class(mock_test_config, - teardown_class_failure_test.TearDownClassFailureTest) + tr.add_test_class( + mock_test_config, teardown_class_failure_test.TearDownClassFailureTest + ) tr.run() output_dir = logging.root_output_path summary_file_path = os.path.join(output_dir, records.OUTPUT_FILE_SUMMARY) @@ -294,14 +315,18 @@ class OutputTest(unittest.TestCase): raw_content = f.read() f.seek(0) for entry in yaml.safe_load_all(f): - if (entry['Type'] == 'Record' and - entry[records.TestResultEnums.RECORD_NAME] == 'teardown_class'): + if ( + entry['Type'] == 'Record' + and entry[records.TestResultEnums.RECORD_NAME] == 'teardown_class' + ): found = True break self.assertTrue( - found, 'No record for teardown_class found in the output file:\n %s' % - raw_content) + found, + 'No record for teardown_class found in the output file:\n %s' + % raw_content, + ) -if __name__ == "__main__": +if __name__ == '__main__': unittest.main() |