fix: IndexError in ensure_file_path_valid when file_path=os.getcwd()

This commit is contained in:
debugtalk
2020-06-14 20:18:58 +08:00
parent ca395b5820
commit f4382139db
2 changed files with 13 additions and 0 deletions

View File

@@ -199,6 +199,9 @@ def ensure_file_path_valid(file_path: Text) -> Text:
else:
raw_file_relative_name = raw_file_name
if raw_file_relative_name == "":
return file_path
path_names = []
for name in raw_file_relative_name.rstrip(os.sep).split(os.sep):

View File

@@ -122,6 +122,16 @@ class TestUtils(unittest.TestCase):
ensure_file_path_valid("examples/postman_echo/request_methods/"),
os.path.join(os.getcwd(), "examples/postman_echo/request_methods"),
)
self.assertEqual(
ensure_file_path_valid(os.path.join(os.getcwd(), "test.yml")),
os.path.join(os.getcwd(), "test.yml"),
)
self.assertEqual(
ensure_file_path_valid(os.getcwd()), os.getcwd(),
)
self.assertEqual(
ensure_file_path_valid(os.getcwd() + ".csv"), os.getcwd() + ".csv",
)
def test_safe_dump_json(self):
class A(object):