Skip to content

Commit 249b5ed

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

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
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: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import os
2+
import posixpath
3+
import subprocess
24
import sys
35
import textwrap
46
from typing import List
57
from unittest import mock
68
from zipfile import ZipFile
79

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

1411
def walk_to_root(path: str):
1512
last_dir = None
1613
current_dir = path
1714
while last_dir != current_dir:
1815
yield current_dir
19-
(parent_dir, _) = os.path.split(current_dir)
16+
parent_dir = posixpath.dirname(current_dir)
2017
last_dir, current_dir = current_dir, parent_dir
2118

2219

@@ -32,12 +29,11 @@ def setup_zipfile(path, files: List[FileToAdd]):
3229
with ZipFile(zip_file_path, "w") as zipfile:
3330
for f in files:
3431
zipfile.writestr(data=f.content, zinfo_or_arcname=f.path)
35-
for dirname in walk_to_root(os.path.dirname(f.path)):
32+
for dirname in walk_to_root(posixpath.dirname(f.path)):
3633
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-
)
34+
init_path = posixpath.join(dirname, "__init__.py")
35+
print(f"setup_zipfile: {init_path}")
36+
zipfile.writestr(data="", zinfo_or_arcname=init_path)
4137
dirs_init_py_added_to.add(dirname)
4238
return zip_file_path
4339

@@ -65,7 +61,6 @@ def test_load_dotenv_gracefully_handles_zip_imports_when_no_env_file(tmp_path):
6561
import child1.child2.test # noqa
6662

6763

68-
@pytest.mark.skipif(sys.platform == "win32", reason="sh module doesn't support Windows")
6964
def test_load_dotenv_outside_zip_file_when_called_in_zipfile(tmp_path):
7065
zip_file_path = setup_zipfile(
7166
tmp_path,
@@ -83,7 +78,7 @@ def test_load_dotenv_outside_zip_file_when_called_in_zipfile(tmp_path):
8378
],
8479
)
8580
dotenv_path = tmp_path / ".env"
86-
dotenv_path.write_bytes(b"a=b")
81+
dotenv_path.write_bytes(b"A=B")
8782
code_path = tmp_path / "code.py"
8883
code_path.write_text(
8984
textwrap.dedent(
@@ -95,12 +90,16 @@ def test_load_dotenv_outside_zip_file_when_called_in_zipfile(tmp_path):
9590
9691
import child1.child2.test
9792
98-
print(os.environ['a'])
93+
print(os.environ['A'])
9994
"""
10095
)
10196
)
102-
os.chdir(str(tmp_path))
10397

104-
result = sh.Command(sys.executable)(code_path)
98+
result = subprocess.run(
99+
[sys.executable, str(code_path)],
100+
capture_output=True,
101+
text=True,
102+
cwd=tmp_path,
103+
)
105104

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

0 commit comments

Comments
 (0)