Skip to content

Commit 56c4281

Browse files
committed
Fix tests in TestUnitBaselinesPerformance on my Mac
The problem was that read_baseline_file returns without doing anything if not os.path.exists(baseline_file). So we need to make it think that the file exists. Previously one of the failing tests had been doing this via `os.mknod("/tmp/cpl-mem.log")`, but that was itself giving an error on my Mac.
1 parent c64260e commit 56c4281

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

CIME/tests/test_unit_baselines_performance.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import gzip
44
import tempfile
55
import unittest
6-
import os
76
from unittest import mock
87
from pathlib import Path
98

@@ -128,24 +127,24 @@ def test_get_cpl_mem_usage(self, isfile):
128127
]
129128

130129
def test_read_baseline_file_multi_line(self):
131-
with mock.patch(
132-
"builtins.open",
133-
mock.mock_open(
134-
read_data="sha:1df0 date:2023 1000.0\nsha:3b05 date:2023 2000.0"
135-
),
136-
) as mock_file:
137-
baseline = performance.read_baseline_file("/tmp/cpl-mem.log")
130+
with mock.patch("os.path.exists", return_value=True):
131+
with mock.patch(
132+
"builtins.open",
133+
mock.mock_open(
134+
read_data="sha:1df0 date:2023 1000.0\nsha:3b05 date:2023 2000.0"
135+
),
136+
) as mock_file:
137+
baseline = performance.read_baseline_file("/tmp/cpl-mem.log")
138138

139139
mock_file.assert_called_with("/tmp/cpl-mem.log")
140140
assert baseline == "sha:1df0 date:2023 1000.0\nsha:3b05 date:2023 2000.0"
141141

142142
def test_read_baseline_file_content(self):
143-
if not os.path.exists("/tmp/cpl-mem.log"):
144-
os.mknod("/tmp/cpl-mem.log")
145-
with mock.patch(
146-
"builtins.open", mock.mock_open(read_data="sha:1df0 date:2023 1000.0")
147-
) as mock_file:
148-
baseline = performance.read_baseline_file("/tmp/cpl-mem.log")
143+
with mock.patch("os.path.exists", return_value=True):
144+
with mock.patch(
145+
"builtins.open", mock.mock_open(read_data="sha:1df0 date:2023 1000.0")
146+
) as mock_file:
147+
baseline = performance.read_baseline_file("/tmp/cpl-mem.log")
149148

150149
mock_file.assert_called_with("/tmp/cpl-mem.log")
151150
assert baseline == "sha:1df0 date:2023 1000.0"

0 commit comments

Comments
 (0)