Skip to content

Commit

Permalink
Release file handles in tests (python-poetry#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaptDept authored and sdispater committed Jul 27, 2018
1 parent ceb48cd commit ec98cdc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 55 deletions.
17 changes: 7 additions & 10 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ def test_wheel_c_extension():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "extended-0.1/build.py" in tar.getnames()
assert "extended-0.1/extended/extended.c" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "extended-0.1/build.py" in tar.getnames()
assert "extended-0.1/extended/extended.c" in tar.getnames()

whl = list((module_path / "dist").glob("extended-0.1-cp*-cp*-*.whl"))[0]

Expand Down Expand Up @@ -167,9 +166,8 @@ def test_module_src():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "module-src-0.1/src/module_src.py" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "module-src-0.1/src/module_src.py" in tar.getnames()

whl = module_path / "dist" / "module_src-0.1-py2.py3-none-any.whl"

Expand All @@ -192,9 +190,8 @@ def test_package_src():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "package-src-0.1/src/package_src/module.py" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "package-src-0.1/src/package_src/module.py" in tar.getnames()

whl = module_path / "dist" / "package_src-0.1-py2.py3-none-any.whl"

Expand Down
58 changes: 26 additions & 32 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,8 @@ def test_package():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "my-package-1.2.3/LICENSE" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "my-package-1.2.3/LICENSE" in tar.getnames()


def test_module():
Expand All @@ -254,9 +253,8 @@ def test_module():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "module1-0.1/module1.py" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "module1-0.1/module1.py" in tar.getnames()


def test_prelease():
Expand All @@ -280,10 +278,9 @@ def test_with_c_extensions():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "extended-0.1/build.py" in tar.getnames()
assert "extended-0.1/extended/extended.c" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "extended-0.1/build.py" in tar.getnames()
assert "extended-0.1/extended/extended.c" in tar.getnames()


def test_with_src_module_file():
Expand All @@ -307,9 +304,8 @@ def test_with_src_module_file():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "module-src-0.1/src/module_src.py" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "module-src-0.1/src/module_src.py" in tar.getnames()


def test_with_src_module_dir():
Expand All @@ -333,10 +329,9 @@ def test_with_src_module_dir():

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

assert "package-src-0.1/src/package_src/__init__.py" in tar.getnames()
assert "package-src-0.1/src/package_src/module.py" in tar.getnames()
with tarfile.open(str(sdist), "r") as tar:
assert "package-src-0.1/src/package_src/__init__.py" in tar.getnames()
assert "package-src-0.1/src/package_src/module.py" in tar.getnames()


def test_package_with_include(mocker):
Expand Down Expand Up @@ -380,21 +375,20 @@ def test_package_with_include(mocker):

assert sdist.exists()

tar = tarfile.open(str(sdist), "r")

names = tar.getnames()
assert "with-include-1.2.3/LICENSE" in names
assert "with-include-1.2.3/README.rst" in names
assert "with-include-1.2.3/extra_dir/__init__.py" in names
assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in names
assert "with-include-1.2.3/extra_dir/sub_pkg/__init__.py" in names
assert "with-include-1.2.3/extra_dir/sub_pkg/vcs_excluded.txt" not in names
assert "with-include-1.2.3/my_module.py" in names
assert "with-include-1.2.3/notes.txt" in names
assert "with-include-1.2.3/package_with_include/__init__.py" in names
assert "with-include-1.2.3/pyproject.toml" in names
assert "with-include-1.2.3/setup.py" in names
assert "with-include-1.2.3/PKG-INFO" in names
with tarfile.open(str(sdist), "r") as tar:
names = tar.getnames()
assert "with-include-1.2.3/LICENSE" in names
assert "with-include-1.2.3/README.rst" in names
assert "with-include-1.2.3/extra_dir/__init__.py" in names
assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in names
assert "with-include-1.2.3/extra_dir/sub_pkg/__init__.py" in names
assert "with-include-1.2.3/extra_dir/sub_pkg/vcs_excluded.txt" not in names
assert "with-include-1.2.3/my_module.py" in names
assert "with-include-1.2.3/notes.txt" in names
assert "with-include-1.2.3/package_with_include/__init__.py" in names
assert "with-include-1.2.3/pyproject.toml" in names
assert "with-include-1.2.3/setup.py" in names
assert "with-include-1.2.3/PKG-INFO" in names


def test_proper_python_requires_if_single_version_specified():
Expand Down
22 changes: 9 additions & 13 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def test_wheel_module():

assert whl.exists()

z = zipfile.ZipFile(str(whl))

assert "module1.py" in z.namelist()
with zipfile.ZipFile(str(whl)) as z:
assert "module1.py" in z.namelist()


def test_wheel_package():
Expand All @@ -48,9 +47,8 @@ def test_wheel_package():

assert whl.exists()

z = zipfile.ZipFile(str(whl))

assert "my_package/sub_pkg1/__init__.py" in z.namelist()
with zipfile.ZipFile(str(whl)) as z:
assert "my_package/sub_pkg1/__init__.py" in z.namelist()


def test_wheel_prerelease():
Expand All @@ -70,10 +68,9 @@ def test_wheel_package_src():

assert whl.exists()

z = zipfile.ZipFile(str(whl))

assert "package_src/__init__.py" in z.namelist()
assert "package_src/module.py" in z.namelist()
with zipfile.ZipFile(str(whl)) as z:
assert "package_src/__init__.py" in z.namelist()
assert "package_src/module.py" in z.namelist()


def test_wheel_module_src():
Expand All @@ -84,6 +81,5 @@ def test_wheel_module_src():

assert whl.exists()

z = zipfile.ZipFile(str(whl))

assert "module_src.py" in z.namelist()
with zipfile.ZipFile(str(whl)) as z:
assert "module_src.py" in z.namelist()

0 comments on commit ec98cdc

Please sign in to comment.