Skip to content

Commit

Permalink
Add unittest for invalid working directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan-Feng committed May 30, 2024
1 parent 4bfbe9b commit 6746efb
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/api/test_flexible_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,68 @@ def test_no_dir_provided(self):
"INFO:root:No working_dir is specified",
)

def test_invalid_str(self):
"""This test checks when working directory is not a valid string,
if the program will behave correctly"""
with self.assertLogs() as logobs:
json_case_path = "./tests/api/data/flexible_calling_unit_test/verification_case_unit_test_Path.json"

# Change working_dir value in the json file to a invalid string
with open(json_case_path, "r") as f:
workflow_dict = json.load(f)
workflow_dict["working_dir"] = []

with open(json_case_path, "w") as f:
json.dump(workflow_dict, f)

workflow = Workflow(workflow=json_case_path)
self.assertEqual(
logobs.output[0],
"ERROR:root:working directory specified is not a valid string.",
)

def test_invalid_escape_sequence_path(self):
"""This test checks when working directory is not a invalid escape sequence string,
if the program will behave correctly"""
with self.assertLogs() as logobs:
json_case_path = "./tests/api/data/flexible_calling_unit_test/verification_case_unit_test_Path.json"

# Change working_dir value in the json file to a invalid string
with open(json_case_path, "r") as f:
workflow_dict = json.load(f)
workflow_dict["working_dir"] = ".\tests\api\result"

with open(json_case_path, "w") as f:
json.dump(workflow_dict, f)

workflow = Workflow(workflow=json_case_path)
self.assertEqual(
logobs.output[0],
"ERROR:root:The working directory specified is an invalid escape sequence string.",
)

def test_Linux_path(self):
"""This test check if the program can detect the working path provided is in Linux format."""
with self.assertLogs() as logobs:
json_case_path = "./tests/api/data/flexible_calling_unit_test/verification_case_unit_test_Path.json"

# Change working_dir value in the json file to a valid path in Linux format
with open(json_case_path, "r") as f:
workflow_dict = json.load(f)
workflow_dict["working_dir"] = "./tests/api/result"

with open(json_case_path, "w") as f:
json.dump(workflow_dict, f)

workflow = Workflow(workflow=json_case_path)
# change current working directory back
os.chdir("../../..")

self.assertEqual(
logobs.output[0],
"INFO:root:Change current working path to the specified path.",
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 6746efb

Please sign in to comment.