|
1 | 1 | import os |
2 | 2 | import subprocess |
3 | | -import sys |
4 | 3 | from pathlib import Path |
5 | 4 | from typing import Optional, Sequence |
6 | 5 |
|
|
10 | 9 | from dotenv.cli import cli as dotenv_cli |
11 | 10 | from dotenv.version import __version__ |
12 | 11 |
|
13 | | -if sys.platform != "win32": |
14 | | - import sh |
15 | | - |
16 | 12 |
|
17 | 13 | def invoke_sub(args: Sequence[str]) -> subprocess.CompletedProcess: |
18 | 14 | """ |
@@ -192,67 +188,93 @@ def test_set_no_file(cli): |
192 | 188 | assert "Missing argument" in result.output |
193 | 189 |
|
194 | 190 |
|
195 | | -@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows") |
196 | 191 | def test_get_default_path(tmp_path): |
197 | | - with sh.pushd(tmp_path): |
198 | | - (tmp_path / ".env").write_text("a=b") |
| 192 | + (tmp_path / ".env").write_text("A=B") |
199 | 193 |
|
200 | | - result = sh.dotenv("get", "a") |
| 194 | + result = subprocess.run( |
| 195 | + ["dotenv", "get", "A"], |
| 196 | + capture_output=True, |
| 197 | + check=True, |
| 198 | + cwd=tmp_path, |
| 199 | + text=True, |
| 200 | + ) |
201 | 201 |
|
202 | | - assert result == "b\n" |
| 202 | + assert result.stdout == "B\n" |
203 | 203 |
|
204 | 204 |
|
205 | | -@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows") |
206 | 205 | def test_run(tmp_path): |
207 | | - with sh.pushd(tmp_path): |
208 | | - (tmp_path / ".env").write_text("a=b") |
| 206 | + (tmp_path / ".env").write_text("A=B") |
209 | 207 |
|
210 | | - result = sh.dotenv("run", "printenv", "a") |
| 208 | + result = subprocess.run( |
| 209 | + ["dotenv", "run", "printenv", "A"], |
| 210 | + capture_output=True, |
| 211 | + check=True, |
| 212 | + cwd=tmp_path, |
| 213 | + text=True, |
| 214 | + ) |
211 | 215 |
|
212 | | - assert result == "b\n" |
| 216 | + assert result.stdout == "B\n" |
213 | 217 |
|
214 | 218 |
|
215 | | -@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows") |
216 | 219 | def test_run_with_existing_variable(tmp_path): |
217 | | - with sh.pushd(tmp_path): |
218 | | - (tmp_path / ".env").write_text("a=b") |
219 | | - env = dict(os.environ) |
220 | | - env.update({"LANG": "en_US.UTF-8", "a": "c"}) |
| 220 | + (tmp_path / ".env").write_text("A=B") |
| 221 | + env = dict(os.environ) |
| 222 | + env.update({"LANG": "en_US.UTF-8", "A": "C"}) |
221 | 223 |
|
222 | | - result = sh.dotenv("run", "printenv", "a", _env=env) |
| 224 | + result = subprocess.run( |
| 225 | + ["dotenv", "run", "printenv", "A"], |
| 226 | + capture_output=True, |
| 227 | + check=True, |
| 228 | + cwd=tmp_path, |
| 229 | + text=True, |
| 230 | + env=env, |
| 231 | + ) |
223 | 232 |
|
224 | | - assert result == "b\n" |
| 233 | + assert result.stdout == "B\n" |
225 | 234 |
|
226 | 235 |
|
227 | | -@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows") |
228 | 236 | def test_run_with_existing_variable_not_overridden(tmp_path): |
229 | | - with sh.pushd(tmp_path): |
230 | | - (tmp_path / ".env").write_text("a=b") |
231 | | - env = dict(os.environ) |
232 | | - env.update({"LANG": "en_US.UTF-8", "a": "c"}) |
| 237 | + (tmp_path / ".env").write_text("A=B") |
| 238 | + env = dict(os.environ) |
| 239 | + env.update({"LANG": "en_US.UTF-8", "A": "C"}) |
233 | 240 |
|
234 | | - result = sh.dotenv("run", "--no-override", "printenv", "a", _env=env) |
| 241 | + result = subprocess.run( |
| 242 | + ["dotenv", "run", "--no-override", "printenv", "A"], |
| 243 | + capture_output=True, |
| 244 | + check=True, |
| 245 | + cwd=tmp_path, |
| 246 | + text=True, |
| 247 | + env=env, |
| 248 | + ) |
235 | 249 |
|
236 | | - assert result == "c\n" |
| 250 | + assert result.stdout == "C\n" |
237 | 251 |
|
238 | 252 |
|
239 | | -@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows") |
240 | 253 | def test_run_with_none_value(tmp_path): |
241 | | - with sh.pushd(tmp_path): |
242 | | - (tmp_path / ".env").write_text("a=b\nc") |
| 254 | + (tmp_path / ".env").write_text("A=B\nc") |
243 | 255 |
|
244 | | - result = sh.dotenv("run", "printenv", "a") |
| 256 | + result = subprocess.run( |
| 257 | + ["dotenv", "run", "printenv", "A"], |
| 258 | + capture_output=True, |
| 259 | + check=True, |
| 260 | + cwd=tmp_path, |
| 261 | + text=True, |
| 262 | + ) |
245 | 263 |
|
246 | | - assert result == "b\n" |
| 264 | + assert result.stdout == "B\n" |
247 | 265 |
|
248 | 266 |
|
249 | | -@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows") |
250 | 267 | def test_run_with_other_env(dotenv_path): |
251 | | - dotenv_path.write_text("a=b") |
| 268 | + dotenv_path.write_text("A=B") |
252 | 269 |
|
253 | | - result = sh.dotenv("--file", dotenv_path, "run", "printenv", "a") |
| 270 | + result = subprocess.run( |
| 271 | + ["dotenv", "--file", dotenv_path, "run", "printenv", "A"], |
| 272 | + capture_output=True, |
| 273 | + check=True, |
| 274 | + text=True, |
| 275 | + ) |
254 | 276 |
|
255 | | - assert result == "b\n" |
| 277 | + assert result.stdout == "B\n" |
256 | 278 |
|
257 | 279 |
|
258 | 280 | def test_run_without_cmd(cli): |
|
0 commit comments