Skip to content

Commit e26b3fb

Browse files
committed
Remove the use of sh in tests
1 parent 09d7cee commit e26b3fb

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Run Tests
22

33
on:
44
push:
5-
branches:
6-
- main
75
pull_request:
86

97
concurrency:

tests/test_zip_imports.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import os
1+
import posixpath
2+
import subprocess
23
import sys
34
import textwrap
45
from typing import List
56
from unittest import mock
67
from zipfile import ZipFile
78

8-
import pytest
9-
10-
if sys.platform != "win32":
11-
import sh
12-
139

1410
def walk_to_root(path: str):
1511
last_dir = None
1612
current_dir = path
1713
while last_dir != current_dir:
1814
yield current_dir
19-
(parent_dir, _) = os.path.split(current_dir)
15+
parent_dir = posixpath.dirname(current_dir)
2016
last_dir, current_dir = current_dir, parent_dir
2117

2218

@@ -32,12 +28,11 @@ def setup_zipfile(path, files: List[FileToAdd]):
3228
with ZipFile(zip_file_path, "w") as zipfile:
3329
for f in files:
3430
zipfile.writestr(data=f.content, zinfo_or_arcname=f.path)
35-
for dirname in walk_to_root(os.path.dirname(f.path)):
31+
for dirname in walk_to_root(posixpath.dirname(f.path)):
3632
if dirname not in dirs_init_py_added_to:
37-
print(os.path.join(dirname, "__init__.py"))
38-
zipfile.writestr(
39-
data="", zinfo_or_arcname=os.path.join(dirname, "__init__.py")
40-
)
33+
init_path = posixpath.join(dirname, "__init__.py")
34+
print(f"setup_zipfile: {init_path}")
35+
zipfile.writestr(data="", zinfo_or_arcname=init_path)
4136
dirs_init_py_added_to.add(dirname)
4237
return zip_file_path
4338

@@ -65,7 +60,6 @@ def test_load_dotenv_gracefully_handles_zip_imports_when_no_env_file(tmp_path):
6560
import child1.child2.test # noqa
6661

6762

68-
@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows")
6963
def test_load_dotenv_outside_zip_file_when_called_in_zipfile(tmp_path):
7064
zip_file_path = setup_zipfile(
7165
tmp_path,
@@ -83,7 +77,7 @@ def test_load_dotenv_outside_zip_file_when_called_in_zipfile(tmp_path):
8377
],
8478
)
8579
dotenv_path = tmp_path / ".env"
86-
dotenv_path.write_bytes(b"a=b")
80+
dotenv_path.write_bytes(b"A=B")
8781
code_path = tmp_path / "code.py"
8882
code_path.write_text(
8983
textwrap.dedent(
@@ -95,12 +89,21 @@ def test_load_dotenv_outside_zip_file_when_called_in_zipfile(tmp_path):
9589
9690
import child1.child2.test
9791
98-
print(os.environ['a'])
92+
print(os.environ['A'])
9993
"""
10094
)
10195
)
102-
os.chdir(str(tmp_path))
10396

104-
result = sh.Command(sys.executable)(code_path)
97+
result = subprocess.run(
98+
[sys.executable, str(code_path)],
99+
capture_output=True,
100+
text=True,
101+
cwd=tmp_path,
102+
)
103+
104+
if result.returncode != 0:
105+
print(f"Process failed with code {result.returncode}")
106+
print(f"stderr: {result.stderr}")
107+
print(f"stdout: {result.stdout}")
105108

106-
assert result == "b\n"
109+
assert result.stdout == "B\n"

0 commit comments

Comments
 (0)