Skip to content

Commit 5fd7935

Browse files
committed
Normalize paths in create_job_folder tests to fix cross-platform Windows/Linux/macOS assertion failures
1 parent 113755c commit 5fd7935

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

tests/test_CodeEntropy/test_run.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ 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-
self.assertEqual(
67-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
68-
)
69-
mock_makedirs.assert_called_once_with(
70-
os.path.realpath(expected_path), exist_ok=True
71-
)
66+
67+
normalized_new = os.path.normcase(os.path.normpath(new_folder_path))
68+
normalized_expected = os.path.normcase(os.path.normpath(expected_path))
69+
self.assertEqual(normalized_new, normalized_expected)
70+
71+
called_args, called_kwargs = mock_makedirs.call_args
72+
normalized_called = os.path.normcase(os.path.normpath(called_args[0]))
73+
self.assertEqual(normalized_called, normalized_expected)
74+
self.assertTrue(called_kwargs.get("exist_ok", False))
7275

7376
@patch("os.makedirs")
7477
@patch("os.listdir")
@@ -82,12 +85,15 @@ def test_create_job_folder_with_non_matching_folders(
8285
mock_listdir.return_value = ["folderA", "another_one"]
8386
new_folder_path = RunManager.create_job_folder()
8487
expected_path = os.path.join(self.test_dir, "job001")
85-
self.assertEqual(
86-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
87-
)
88-
mock_makedirs.assert_called_once_with(
89-
os.path.realpath(expected_path), exist_ok=True
90-
)
88+
89+
normalized_new = os.path.normcase(os.path.normpath(new_folder_path))
90+
normalized_expected = os.path.normcase(os.path.normpath(expected_path))
91+
self.assertEqual(normalized_new, normalized_expected)
92+
93+
called_args, called_kwargs = mock_makedirs.call_args
94+
normalized_called = os.path.normcase(os.path.normpath(called_args[0]))
95+
self.assertEqual(normalized_called, normalized_expected)
96+
self.assertTrue(called_kwargs.get("exist_ok", False))
9197

9298
@patch("os.makedirs")
9399
@patch("os.listdir")
@@ -121,12 +127,14 @@ def test_create_job_folder_with_invalid_job_suffix(
121127
new_folder_path = RunManager.create_job_folder()
122128
expected_path = os.path.join(self.test_dir, "job003")
123129

124-
self.assertEqual(
125-
os.path.realpath(new_folder_path), os.path.realpath(expected_path)
126-
)
127-
mock_makedirs.assert_called_once_with(
128-
os.path.realpath(expected_path), exist_ok=True
129-
)
130+
normalized_new = os.path.normcase(os.path.normpath(new_folder_path))
131+
normalized_expected = os.path.normcase(os.path.normpath(expected_path))
132+
self.assertEqual(normalized_new, normalized_expected)
133+
134+
called_args, called_kwargs = mock_makedirs.call_args
135+
normalized_called = os.path.normcase(os.path.normpath(called_args[0]))
136+
self.assertEqual(normalized_called, normalized_expected)
137+
self.assertTrue(called_kwargs.get("exist_ok", False))
130138

131139
@patch("requests.get")
132140
def test_load_citation_data_success(self, mock_get):

0 commit comments

Comments
 (0)