Skip to content

Commit 97b98db

Browse files
committed
Fix RunManager job folder tests by using os.path.realpath for cross-platform path comparisons and proper handling of mixed, invalid, and non-job folder names
1 parent 113755c commit 97b98db

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

tests/test_CodeEntropy/test_run.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ def test_create_job_folder_with_existing_folders(self, mock_listdir, mock_makedi
6363
mock_listdir.return_value = ["job001", "job002", "job003"]
6464
new_folder_path = RunManager.create_job_folder()
6565
expected_path = os.path.join(self.test_dir, "job004")
66+
6667
self.assertEqual(
67-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
68+
os.path.normcase(os.path.realpath(new_folder_path)),
69+
os.path.normcase(os.path.realpath(expected_path)),
6870
)
6971
mock_makedirs.assert_called_once_with(
70-
os.path.realpath(expected_path), exist_ok=True
72+
os.path.normcase(os.path.realpath(expected_path)), exist_ok=True
7173
)
7274

7375
@patch("os.makedirs")
@@ -80,13 +82,16 @@ def test_create_job_folder_with_non_matching_folders(
8082
folders.
8183
"""
8284
mock_listdir.return_value = ["folderA", "another_one"]
85+
8386
new_folder_path = RunManager.create_job_folder()
8487
expected_path = os.path.join(self.test_dir, "job001")
88+
8589
self.assertEqual(
86-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
90+
os.path.normcase(os.path.realpath(new_folder_path)),
91+
os.path.normcase(os.path.realpath(expected_path)),
8792
)
8893
mock_makedirs.assert_called_once_with(
89-
os.path.realpath(expected_path), exist_ok=True
94+
os.path.normcase(os.path.realpath(expected_path)), exist_ok=True
9095
)
9196

9297
@patch("os.makedirs")
@@ -100,12 +105,14 @@ def test_create_job_folder_mixed_folder_names(self, mock_listdir, mock_makedirs)
100105
new_folder_path = RunManager.create_job_folder()
101106
expected_path = os.path.join(self.test_dir, "job003")
102107
self.assertEqual(
103-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
104-
)
105-
mock_makedirs.assert_called_once_with(
106-
os.path.realpath(expected_path), exist_ok=True
108+
os.path.normcase(os.path.abspath(new_folder_path)),
109+
os.path.normcase(os.path.abspath(expected_path)),
107110
)
108111

112+
called_path = os.path.normcase(os.path.abspath(mock_makedirs.call_args[0][0]))
113+
self.assertEqual(called_path, os.path.normcase(os.path.abspath(expected_path)))
114+
self.assertTrue(mock_makedirs.call_args[1]["exist_ok"])
115+
109116
@patch("os.makedirs")
110117
@patch("os.listdir")
111118
def test_create_job_folder_with_invalid_job_suffix(
@@ -122,10 +129,11 @@ def test_create_job_folder_with_invalid_job_suffix(
122129
expected_path = os.path.join(self.test_dir, "job003")
123130

124131
self.assertEqual(
125-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
132+
os.path.normcase(os.path.realpath(new_folder_path)),
133+
os.path.normcase(os.path.realpath(expected_path)),
126134
)
127135
mock_makedirs.assert_called_once_with(
128-
os.path.realpath(expected_path), exist_ok=True
136+
os.path.normcase(os.path.realpath(expected_path)), exist_ok=True
129137
)
130138

131139
@patch("requests.get")

0 commit comments

Comments
 (0)