Skip to content

Commit ec689a9

Browse files
committed
fix: resolve environment test quality findings
1 parent 6cbc93c commit ec689a9

1 file changed

Lines changed: 5 additions & 22 deletions

File tree

tests/test_environment.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,15 @@ def test_detect_derivative_distro_pop_os(self, tmp_path: Path) -> None:
5555
os_release = tmp_path / "os-release"
5656
os_release.write_text('ID=pop\nVERSION_ID="22.04"\nID_LIKE="ubuntu debian"')
5757

58-
os_release_data = 'ID=pop\nVERSION_ID="22.04"\nID_LIKE="ubuntu debian"'
58+
missing_path = mock.Mock()
59+
missing_path.exists.return_value = False
5960

60-
with (
61-
mock.patch("promptfoo.environment.Path") as mock_path_class,
62-
mock.patch("builtins.open", mock.mock_open(read_data=os_release_data)),
63-
):
61+
with mock.patch("promptfoo.environment.Path") as mock_path_class:
6462

65-
def path_side_effect(path_str: str) -> mock.Mock:
66-
mock_path_obj = mock.Mock()
63+
def path_side_effect(path_str: str) -> object:
6764
if path_str == "/etc/os-release":
68-
mock_path_obj.exists.return_value = True
69-
mock_path_obj.__truediv__ = lambda self, other: os_release
70-
# Make the mock path object work with open()
7165
return os_release
72-
else:
73-
mock_path_obj.exists.return_value = False
74-
return mock_path_obj
66+
return missing_path
7567

7668
mock_path_class.side_effect = path_side_effect
7769

@@ -114,15 +106,6 @@ def test_detect_derivative_distro_linux_mint(self, tmp_path: Path) -> None:
114106
def test_usr_lib_os_release_fallback(self, tmp_path: Path) -> None:
115107
"""Detect distro from /usr/lib/os-release if /etc/os-release missing."""
116108
with mock.patch("promptfoo.environment.Path") as mock_path_class:
117-
118-
def path_exists_side_effect(path_obj: mock.Mock) -> bool:
119-
# /etc/os-release doesn't exist, /usr/lib/os-release does
120-
if "/etc/os-release" in str(path_obj):
121-
return False
122-
elif "/usr/lib/os-release" in str(path_obj):
123-
return True
124-
return False
125-
126109
# Create mock Path objects
127110
etc_path = mock.Mock()
128111
etc_path.exists.return_value = False

0 commit comments

Comments
 (0)