Skip to content

Commit dca0f40

Browse files
committed
update to include oses
1 parent b168638 commit dca0f40

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

tests/test_shell_utils.py

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,33 @@ def test_valid_api_key(self):
6060
) as mock_file:
6161
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
6262
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
63-
with patch(
6463
"builtins.open", mock_open(read_data=f'export CODEFLASH_API_KEY=\'{self.api_key}\'\n')
65-
) as mock_file:
66-
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
67-
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
68-
with patch(
69-
"builtins.open", mock_open(read_data=f'#export CODEFLASH_API_KEY=\'{self.api_key}\'\n')
70-
) as mock_file:
71-
self.assertEqual(read_api_key_from_shell_config(), None)
72-
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
73-
with patch(
74-
"builtins.open", mock_open(read_data=f'export CODEFLASH_API_KEY={self.api_key}\n')
75-
) as mock_file:
76-
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
77-
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
64+
65+
if os.name != "nt":
66+
with patch(
67+
"builtins.open", mock_open(read_data=f'export CODEFLASH_API_KEY=\'{self.api_key}\'\n')
68+
) as mock_file:
69+
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
70+
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
71+
72+
with patch(
73+
"builtins.open", mock_open(read_data=f'#export CODEFLASH_API_KEY=\'{self.api_key}\'\n')
74+
) as mock_file:
75+
self.assertEqual(read_api_key_from_shell_config(), None)
76+
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
77+
78+
with patch(
79+
"builtins.open", mock_open(read_data=f'export CODEFLASH_API_KEY={self.api_key}\n')
80+
) as mock_file:
81+
self.assertEqual(read_api_key_from_shell_config(), self.api_key)
82+
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
83+
84+
elif os.name == "nt":
85+
with patch(
86+
"builtins.open", mock_open(read_data=f'REM set CODEFLASH_API_KEY={self.api_key}\n')
87+
) as mock_file:
88+
self.assertEqual(read_api_key_from_shell_config(), None)
89+
mock_file.assert_called_once_with(self.test_rc_path, encoding="utf8")
7890

7991

8092
@patch("codeflash.code_utils.shell_utils.get_shell_rc_path")
@@ -89,15 +101,27 @@ def test_no_api_key(self, mock_get_shell_rc_path):
89101
def test_malformed_api_key_export(self, mock_get_shell_rc_path):
90102
"""Test with a malformed API key export."""
91103
mock_get_shell_rc_path.return_value = self.test_rc_path
92-
with patch("builtins.open", mock_open(read_data=f"export API_KEY={self.api_key}\n")):
93-
result = read_api_key_from_shell_config()
94-
self.assertIsNone(result)
95-
with patch("builtins.open", mock_open(read_data=f"CODEFLASH_API_KEY={self.api_key}\n")):
96-
result = read_api_key_from_shell_config()
97-
self.assertIsNone(result)
98-
with patch("builtins.open", mock_open(read_data=f"export CODEFLASH_API_KEY=sk-{self.api_key}\n")):
99-
result = read_api_key_from_shell_config()
100-
self.assertIsNone(result)
104+
105+
if os.name == "nt":
106+
with patch("builtins.open", mock_open(read_data=f"set API_KEY={self.api_key}\n")):
107+
result = read_api_key_from_shell_config()
108+
self.assertIsNone(result)
109+
with patch("builtins.open", mock_open(read_data=f"CODEFLASH_API_KEY={self.api_key}\n")):
110+
result = read_api_key_from_shell_config()
111+
self.assertIsNone(result)
112+
with patch("builtins.open", mock_open(read_data=f"set CODEFLASH_API_KEY=sk-{self.api_key}\n")):
113+
result = read_api_key_from_shell_config()
114+
self.assertIsNone(result)
115+
else:
116+
with patch("builtins.open", mock_open(read_data=f"export API_KEY={self.api_key}\n")):
117+
result = read_api_key_from_shell_config()
118+
self.assertIsNone(result)
119+
with patch("builtins.open", mock_open(read_data=f"CODEFLASH_API_KEY={self.api_key}\n")):
120+
result = read_api_key_from_shell_config()
121+
self.assertIsNone(result)
122+
with patch("builtins.open", mock_open(read_data=f"export CODEFLASH_API_KEY=sk-{self.api_key}\n")):
123+
result = read_api_key_from_shell_config()
124+
self.assertIsNone(result)
101125

102126
@patch("codeflash.code_utils.shell_utils.get_shell_rc_path")
103127
def test_multiple_api_key_exports(self, mock_get_shell_rc_path):
@@ -106,7 +130,7 @@ def test_multiple_api_key_exports(self, mock_get_shell_rc_path):
106130
if os.name == "nt": # Windows
107131
first_export = 'set CODEFLASH_API_KEY=cf-firstkey'
108132
second_export = f'set CODEFLASH_API_KEY={self.api_key}'
109-
else: # Unix-like systems
133+
else:
110134
first_export = 'export CODEFLASH_API_KEY="cf-firstkey"'
111135
second_export = f'export CODEFLASH_API_KEY="{self.api_key}"'
112136
with patch(

0 commit comments

Comments
 (0)