From 9d50b1635c1f5b9fe1273a7e3d10074a5a88b6cb Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 2 Nov 2017 13:32:51 +0800 Subject: [PATCH] rename function name, resolve conflict with unittest --- ate/testcase.py | 12 ++++++------ tests/test_context.py | 2 +- tests/test_runner.py | 2 +- tests/test_testcase.py | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ate/testcase.py b/ate/testcase.py index 0f0dfed4..9f714faa 100644 --- a/ate/testcase.py +++ b/ate/testcase.py @@ -19,7 +19,7 @@ test_def_overall_dict = { testcases_cache_mapping = {} -def load_yaml_file(yaml_file): +def _load_yaml_file(yaml_file): """ load yaml file and check file content format """ with codecs.open(yaml_file, 'r+', encoding='utf-8') as stream: @@ -27,7 +27,7 @@ def load_yaml_file(yaml_file): check_format(yaml_file, yaml_content) return yaml_content -def load_json_file(json_file): +def _load_json_file(json_file): """ load json file and check file content format """ with codecs.open(json_file, encoding='utf-8') as data_file: @@ -41,12 +41,12 @@ def load_json_file(json_file): check_format(json_file, json_content) return json_content -def load_tests(testcase_file_path): +def _load_file(testcase_file_path): file_suffix = os.path.splitext(testcase_file_path)[1] if file_suffix == '.json': - return load_json_file(testcase_file_path) + return _load_json_file(testcase_file_path) elif file_suffix in ['.yaml', '.yml']: - return load_yaml_file(testcase_file_path) + return _load_yaml_file(testcase_file_path) else: # '' or other suffix return [] @@ -226,7 +226,7 @@ def load_test_file(file_path): "api": {}, "testcases": [] } - tests_list = load_tests(file_path) + tests_list = _load_file(file_path) for item in tests_list: for key in item: diff --git a/tests/test_context.py b/tests/test_context.py index 484b5f2d..d56f6bdf 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -12,7 +12,7 @@ class VariableBindsUnittest(unittest.TestCase): def setUp(self): self.context = Context() testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml') - self.testcases = testcase.load_tests(testcase_file_path) + self.testcases = testcase._load_file(testcase_file_path) def test_context_init_functions(self): self.assertIn("get_timestamp", self.context.testset_functions_config) diff --git a/tests/test_runner.py b/tests/test_runner.py index 0ef7458f..f2d8e684 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -25,7 +25,7 @@ class TestRunner(ApiServerUnittest): def test_run_single_testcase(self): for testcase_file_path in self.testcase_file_path_list: - testcases = testcase.load_tests(testcase_file_path) + testcases = testcase._load_file(testcase_file_path) test = testcases[0]["test"] self.assertTrue(self.test_runner._run_test(test)) diff --git a/tests/test_testcase.py b/tests/test_testcase.py index a6f3060e..10d752d6 100644 --- a/tests/test_testcase.py +++ b/tests/test_testcase.py @@ -10,12 +10,12 @@ class TestcaseParserUnittest(unittest.TestCase): def test_load_testcases_bad_filepath(self): testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo') - self.assertEqual(testcase.load_tests(testcase_file_path), []) + self.assertEqual(testcase._load_file(testcase_file_path), []) def test_load_json_testcases(self): testcase_file_path = os.path.join( os.getcwd(), 'tests/data/demo_testset_hardcode.json') - testcases = testcase.load_tests(testcase_file_path) + testcases = testcase._load_file(testcase_file_path) self.assertEqual(len(testcases), 3) test = testcases[0]["test"] self.assertIn('name', test) @@ -26,7 +26,7 @@ class TestcaseParserUnittest(unittest.TestCase): def test_load_yaml_testcases(self): testcase_file_path = os.path.join( os.getcwd(), 'tests/data/demo_testset_hardcode.yml') - testcases = testcase.load_tests(testcase_file_path) + testcases = testcase._load_file(testcase_file_path) self.assertEqual(len(testcases), 3) test = testcases[0]["test"] self.assertIn('name', test) @@ -41,7 +41,7 @@ class TestcaseParserUnittest(unittest.TestCase): f.write("") with self.assertRaises(FileFormatError): - testcase.load_yaml_file(yaml_tmp_file) + testcase._load_yaml_file(yaml_tmp_file) os.remove(yaml_tmp_file) @@ -50,7 +50,7 @@ class TestcaseParserUnittest(unittest.TestCase): f.write("abc") with self.assertRaises(FileFormatError): - testcase.load_yaml_file(yaml_tmp_file) + testcase._load_yaml_file(yaml_tmp_file) os.remove(yaml_tmp_file) @@ -61,7 +61,7 @@ class TestcaseParserUnittest(unittest.TestCase): f.write("") with self.assertRaises(FileFormatError): - testcase.load_json_file(json_tmp_file) + testcase._load_json_file(json_tmp_file) os.remove(json_tmp_file) @@ -70,7 +70,7 @@ class TestcaseParserUnittest(unittest.TestCase): f.write("{}") with self.assertRaises(FileFormatError): - testcase.load_json_file(json_tmp_file) + testcase._load_json_file(json_tmp_file) os.remove(json_tmp_file) @@ -79,7 +79,7 @@ class TestcaseParserUnittest(unittest.TestCase): f.write("abc") with self.assertRaises(FileFormatError): - testcase.load_json_file(json_tmp_file) + testcase._load_json_file(json_tmp_file) os.remove(json_tmp_file)