fix: unittests on Windows

This commit is contained in:
debugtalk
2020-06-17 22:09:51 +08:00
parent 429276c43b
commit 74dab0e8ec
3 changed files with 85 additions and 25 deletions

View File

@@ -14,7 +14,7 @@ class TestLoader(unittest.TestCase):
self.assertEqual(len(testcase_obj.teststeps), 3) self.assertEqual(len(testcase_obj.teststeps), 3)
def test_load_json_file_file_format_error(self): def test_load_json_file_file_format_error(self):
json_tmp_file = "/tmp/tmp.json" json_tmp_file = "tmp.json"
# create empty file # create empty file
with open(json_tmp_file, "w") as f: with open(json_tmp_file, "w") as f:
f.write("") f.write("")
@@ -111,7 +111,7 @@ class TestLoader(unittest.TestCase):
start_path = os.path.join(os.getcwd(), "examples", "httpbin") start_path = os.path.join(os.getcwd(), "examples", "httpbin")
self.assertEqual( self.assertEqual(
loader.locate_file(start_path, "debugtalk.py"), loader.locate_file(start_path, "debugtalk.py"),
os.path.join(os.getcwd(), "examples/httpbin/debugtalk.py"), os.path.join(os.getcwd(), "examples", "httpbin", "debugtalk.py"),
) )
self.assertEqual( self.assertEqual(
loader.locate_file("examples/httpbin/", "debugtalk.py"), loader.locate_file("examples/httpbin/", "debugtalk.py"),
@@ -119,5 +119,5 @@ class TestLoader(unittest.TestCase):
) )
self.assertEqual( self.assertEqual(
loader.locate_file("examples/httpbin/", "debugtalk.py"), loader.locate_file("examples/httpbin/", "debugtalk.py"),
os.path.join(os.getcwd(), "examples/httpbin/debugtalk.py"), os.path.join(os.getcwd(), "examples", "httpbin", "debugtalk.py"),
) )

View File

@@ -25,7 +25,12 @@ class TestMake(unittest.TestCase):
testcase_python_list[0], testcase_python_list[0],
os.path.join( os.path.join(
os.getcwd(), os.getcwd(),
"examples/postman_echo/request_methods/request_with_variables_test.py", os.path.join(
"examples",
"postman_echo",
"request_methods",
"request_with_variables_test.py",
),
), ),
) )
@@ -38,13 +43,23 @@ class TestMake(unittest.TestCase):
self.assertIn( self.assertIn(
os.path.join( os.path.join(
os.getcwd(), os.getcwd(),
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py", os.path.join(
"examples",
"postman_echo",
"request_methods",
"request_with_testcase_reference_test.py",
),
), ),
testcase_python_list, testcase_python_list,
) )
with open( with open(
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py" os.path.join(
"examples",
"postman_echo",
"request_methods",
"request_with_testcase_reference_test.py",
)
) as f: ) as f:
content = f.read() content = f.read()
self.assertIn( self.assertIn(
@@ -65,7 +80,12 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
self.assertIn( self.assertIn(
os.path.join( os.path.join(
os.getcwd(), os.getcwd(),
"examples/postman_echo/request_methods/request_with_functions_test.py", os.path.join(
"examples",
"postman_echo",
"request_methods",
"request_with_functions_test.py",
),
), ),
testcase_python_list, testcase_python_list,
) )
@@ -76,20 +96,42 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
(os.path.join(os.getcwd(), "mubu_login_test.py"), "MubuLogin"), (os.path.join(os.getcwd(), "mubu_login_test.py"), "MubuLogin"),
) )
self.assertEqual( self.assertEqual(
convert_testcase_path(os.path.join(os.getcwd(), "path/to/mubu.login.yml")), convert_testcase_path(
(os.path.join(os.getcwd(), "path/to/mubu_login_test.py"), "MubuLogin"), os.path.join(os.getcwd(), os.path.join("path", "to", "mubu.login.yml"))
),
(
os.path.join(
os.getcwd(), os.path.join("path", "to", "mubu_login_test.py")
),
"MubuLogin",
),
) )
self.assertEqual( self.assertEqual(
convert_testcase_path("path/to 2/mubu.login.yml"), convert_testcase_path(os.path.join("path", "to 2", "mubu.login.yml")),
(os.path.join(os.getcwd(), "path/to_2/mubu_login_test.py"), "MubuLogin"), (
os.path.join(
os.getcwd(), os.path.join("path", "to_2", "mubu_login_test.py")
),
"MubuLogin",
),
) )
self.assertEqual( self.assertEqual(
convert_testcase_path("path/to-2/mubu login.yml"), convert_testcase_path(os.path.join("path", "to-2", "mubu login.yml")),
(os.path.join(os.getcwd(), "path/to_2/mubu_login_test.py"), "MubuLogin"), (
os.path.join(
os.getcwd(), os.path.join("path", "to_2", "mubu_login_test.py")
),
"MubuLogin",
),
) )
self.assertEqual( self.assertEqual(
convert_testcase_path("path/to.2/幕布login.yml"), convert_testcase_path(os.path.join("path", "to.2", "幕布login.yml")),
(os.path.join(os.getcwd(), "path/to_2/幕布login_test.py"), "幕布Login"), (
os.path.join(
os.getcwd(), os.path.join("path", "to_2", "幕布login_test.py")
),
"幕布Login",
),
) )
def test_make_testsuite(self): def test_make_testsuite(self):
@@ -99,14 +141,26 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
self.assertIn( self.assertIn(
os.path.join( os.path.join(
os.getcwd(), os.getcwd(),
"examples/postman_echo/request_methods/demo_testsuite_yml/request_with_functions_test.py", os.path.join(
"examples",
"postman_echo",
"request_methods",
"demo_testsuite_yml",
"request_with_functions_test.py",
),
), ),
testcase_python_list, testcase_python_list,
) )
self.assertIn( self.assertIn(
os.path.join( os.path.join(
os.getcwd(), os.getcwd(),
"examples/postman_echo/request_methods/demo_testsuite_yml/request_with_testcase_reference_test.py", os.path.join(
"examples",
"postman_echo",
"request_methods",
"demo_testsuite_yml",
"request_with_testcase_reference_test.py",
),
), ),
testcase_python_list, testcase_python_list,
) )

View File

@@ -107,20 +107,26 @@ class TestUtils(unittest.TestCase):
def test_ensure_file_path_valid(self): def test_ensure_file_path_valid(self):
self.assertEqual( self.assertEqual(
ensure_file_path_valid("examples/a-b.c/d f/hardcode.yml"), ensure_file_path_valid(
os.path.join(os.getcwd(), "examples/a_b_c/d_f/hardcode.yml"), os.path.join("examples", "a-b.c", "d f", "hardcode.yml")
),
os.path.join(os.getcwd(), "examples", "a_b_c", "d_f", "hardcode.yml"),
) )
self.assertEqual( self.assertEqual(
ensure_file_path_valid("1/2B/3.yml"), ensure_file_path_valid(os.path.join("1", "2B", "3.yml")),
os.path.join(os.getcwd(), "T1/T2B/T3.yml"), os.path.join(os.getcwd(), "T1", "T2B", "T3.yml"),
) )
self.assertEqual( self.assertEqual(
ensure_file_path_valid("examples/a-b.c/2B/hardcode.yml"), ensure_file_path_valid(
os.path.join(os.getcwd(), "examples/a_b_c/T2B/hardcode.yml"), os.path.join("examples", "a-b.c", "2B", "hardcode.yml")
),
os.path.join(os.getcwd(), "examples", "a_b_c", "T2B", "hardcode.yml"),
) )
self.assertEqual( self.assertEqual(
ensure_file_path_valid("examples/postman_echo/request_methods/"), ensure_file_path_valid(
os.path.join(os.getcwd(), "examples/postman_echo/request_methods"), os.path.join("examples", "postman_echo", "request_methods")
),
os.path.join(os.getcwd(), "examples", "postman_echo", "request_methods"),
) )
self.assertEqual( self.assertEqual(
ensure_file_path_valid(os.path.join(os.getcwd(), "test.yml")), ensure_file_path_valid(os.path.join(os.getcwd(), "test.yml")),