rename function name, resolve conflict with unittest

This commit is contained in:
debugtalk
2017-11-02 13:32:51 +08:00
parent 6e65f5cf0c
commit 9d50b1635c
4 changed files with 16 additions and 16 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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))

View File

@@ -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)