Skip to content

Commit 161ee7f

Browse files
authored
Merge pull request #8548 from chrahunt/better-wheel-empty-dir-test
Refactor test for empty directory in wheel
2 parents 547a8e9 + 5e4c1a9 commit 161ee7f

File tree

9 files changed

+46
-133
lines changed

9 files changed

+46
-133
lines changed

src/pip/_internal/operations/install/wheel.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -726,13 +726,12 @@ def install_wheel(
726726
req_description, # type: str
727727
pycompile=True, # type: bool
728728
warn_script_location=True, # type: bool
729-
_temp_dir_for_testing=None, # type: Optional[str]
730729
direct_url=None, # type: Optional[DirectUrl]
731730
requested=False, # type: bool
732731
):
733732
# type: (...) -> None
734733
with TempDirectory(
735-
path=_temp_dir_for_testing, kind="unpacked-wheel"
734+
kind="unpacked-wheel"
736735
) as unpacked_dir, ZipFile(wheel_path, allowZip64=True) as z:
737736
unpack_file(wheel_path, unpacked_dir.path)
738737
install_unpacked_wheel(
Binary file not shown.

tests/data/src/sample/MANIFEST.in

-8
This file was deleted.

tests/data/src/sample/data/data_file

-1
This file was deleted.

tests/data/src/sample/sample/__init__.py

-5
This file was deleted.

tests/data/src/sample/sample/package_data.dat

-1
This file was deleted.

tests/data/src/sample/setup.cfg

-5
This file was deleted.

tests/data/src/sample/setup.py

-103
This file was deleted.

tests/unit/test_wheel.py

+45-8
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,51 @@ def prep(self, data, tmpdir):
264264
# to a string here.
265265
tmpdir = str(tmpdir)
266266
self.name = 'sample'
267-
self.wheelpath = os.path.join(
268-
str(data.packages), 'sample-1.2.0-py2.py3-none-any.whl'
269-
)
267+
self.wheelpath = make_wheel(
268+
"sample",
269+
"1.2.0",
270+
metadata_body=textwrap.dedent(
271+
"""
272+
A sample Python project
273+
=======================
274+
275+
...
276+
"""
277+
),
278+
metadata_updates={
279+
"Requires-Dist": ["peppercorn"],
280+
},
281+
extra_files={
282+
"sample/__init__.py": textwrap.dedent(
283+
'''
284+
__version__ = '1.2.0'
285+
286+
def main():
287+
"""Entry point for the application script"""
288+
print("Call your main application code here")
289+
'''
290+
),
291+
"sample/package_data.dat": "some data",
292+
},
293+
extra_metadata_files={
294+
"DESCRIPTION.rst": textwrap.dedent(
295+
"""
296+
A sample Python project
297+
=======================
298+
299+
...
300+
"""
301+
),
302+
"top_level.txt": "sample\n",
303+
"empty_dir/empty_dir/": "",
304+
},
305+
extra_data_files={
306+
"data/my_data/data_file": "some data",
307+
},
308+
console_scripts=[
309+
"sample = sample:main",
310+
],
311+
).save_to_dir(tmpdir)
270312
self.req = Requirement('sample')
271313
self.src = os.path.join(tmpdir, 'src')
272314
self.dest = os.path.join(tmpdir, 'dest')
@@ -406,16 +448,11 @@ def test_dist_info_contains_empty_dir(self, data, tmpdir):
406448
"""
407449
# e.g. https://github.com/pypa/pip/issues/1632#issuecomment-38027275
408450
self.prep(data, tmpdir)
409-
src_empty_dir = os.path.join(
410-
self.src_dist_info, 'empty_dir', 'empty_dir')
411-
os.makedirs(src_empty_dir)
412-
assert os.path.isdir(src_empty_dir)
413451
wheel.install_wheel(
414452
self.name,
415453
self.wheelpath,
416454
scheme=self.scheme,
417455
req_description=str(self.req),
418-
_temp_dir_for_testing=self.src,
419456
)
420457
self.assert_installed(0o644)
421458
assert not os.path.isdir(

0 commit comments

Comments
 (0)