Skip to content

Commit

Permalink
Move Wheel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrahunt committed Dec 2, 2019
1 parent 60f6ed9 commit b8c16a0
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 174 deletions.
179 changes: 179 additions & 0 deletions tests/unit/test_models_wheel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import pytest

from pip._internal import pep425tags
from pip._internal.exceptions import InvalidWheelFilename
from pip._internal.models.wheel import Wheel


class TestWheelFile(object):

def test_std_wheel_pattern(self):
w = Wheel('simple-1.1.1-py2-none-any.whl')
assert w.name == 'simple'
assert w.version == '1.1.1'
assert w.pyversions == ['py2']
assert w.abis == ['none']
assert w.plats == ['any']

def test_wheel_pattern_multi_values(self):
w = Wheel('simple-1.1-py2.py3-abi1.abi2-any.whl')
assert w.name == 'simple'
assert w.version == '1.1'
assert w.pyversions == ['py2', 'py3']
assert w.abis == ['abi1', 'abi2']
assert w.plats == ['any']

def test_wheel_with_build_tag(self):
# pip doesn't do anything with build tags, but theoretically, we might
# see one, in this case the build tag = '4'
w = Wheel('simple-1.1-4-py2-none-any.whl')
assert w.name == 'simple'
assert w.version == '1.1'
assert w.pyversions == ['py2']
assert w.abis == ['none']
assert w.plats == ['any']

def test_single_digit_version(self):
w = Wheel('simple-1-py2-none-any.whl')
assert w.version == '1'

def test_non_pep440_version(self):
w = Wheel('simple-_invalid_-py2-none-any.whl')
assert w.version == '-invalid-'

def test_missing_version_raises(self):
with pytest.raises(InvalidWheelFilename):
Wheel('Cython-cp27-none-linux_x86_64.whl')

def test_invalid_filename_raises(self):
with pytest.raises(InvalidWheelFilename):
Wheel('invalid.whl')

def test_supported_single_version(self):
"""
Test single-version wheel is known to be supported
"""
w = Wheel('simple-0.1-py2-none-any.whl')
assert w.supported(tags=[('py2', 'none', 'any')])

def test_supported_multi_version(self):
"""
Test multi-version wheel is known to be supported
"""
w = Wheel('simple-0.1-py2.py3-none-any.whl')
assert w.supported(tags=[('py3', 'none', 'any')])

def test_not_supported_version(self):
"""
Test unsupported wheel is known to be unsupported
"""
w = Wheel('simple-0.1-py2-none-any.whl')
assert not w.supported(tags=[('py1', 'none', 'any')])

def test_supported_osx_version(self):
"""
Wheels built for macOS 10.6 are supported on 10.9
"""
tags = pep425tags.get_supported(
'27', platform='macosx_10_9_intel', impl='cp'
)
w = Wheel('simple-0.1-cp27-none-macosx_10_6_intel.whl')
assert w.supported(tags=tags)
w = Wheel('simple-0.1-cp27-none-macosx_10_9_intel.whl')
assert w.supported(tags=tags)

def test_not_supported_osx_version(self):
"""
Wheels built for macOS 10.9 are not supported on 10.6
"""
tags = pep425tags.get_supported(
'27', platform='macosx_10_6_intel', impl='cp'
)
w = Wheel('simple-0.1-cp27-none-macosx_10_9_intel.whl')
assert not w.supported(tags=tags)

def test_supported_multiarch_darwin(self):
"""
Multi-arch wheels (intel) are supported on components (i386, x86_64)
"""
universal = pep425tags.get_supported(
'27', platform='macosx_10_5_universal', impl='cp'
)
intel = pep425tags.get_supported(
'27', platform='macosx_10_5_intel', impl='cp'
)
x64 = pep425tags.get_supported(
'27', platform='macosx_10_5_x86_64', impl='cp'
)
i386 = pep425tags.get_supported(
'27', platform='macosx_10_5_i386', impl='cp'
)
ppc = pep425tags.get_supported(
'27', platform='macosx_10_5_ppc', impl='cp'
)
ppc64 = pep425tags.get_supported(
'27', platform='macosx_10_5_ppc64', impl='cp'
)

w = Wheel('simple-0.1-cp27-none-macosx_10_5_intel.whl')
assert w.supported(tags=intel)
assert w.supported(tags=x64)
assert w.supported(tags=i386)
assert not w.supported(tags=universal)
assert not w.supported(tags=ppc)
assert not w.supported(tags=ppc64)
w = Wheel('simple-0.1-cp27-none-macosx_10_5_universal.whl')
assert w.supported(tags=universal)
assert w.supported(tags=intel)
assert w.supported(tags=x64)
assert w.supported(tags=i386)
assert w.supported(tags=ppc)
assert w.supported(tags=ppc64)

def test_not_supported_multiarch_darwin(self):
"""
Single-arch wheels (x86_64) are not supported on multi-arch (intel)
"""
universal = pep425tags.get_supported(
'27', platform='macosx_10_5_universal', impl='cp'
)
intel = pep425tags.get_supported(
'27', platform='macosx_10_5_intel', impl='cp'
)

w = Wheel('simple-0.1-cp27-none-macosx_10_5_i386.whl')
assert not w.supported(tags=intel)
assert not w.supported(tags=universal)
w = Wheel('simple-0.1-cp27-none-macosx_10_5_x86_64.whl')
assert not w.supported(tags=intel)
assert not w.supported(tags=universal)

def test_support_index_min(self):
"""
Test results from `support_index_min`
"""
tags = [
('py2', 'none', 'TEST'),
('py2', 'TEST', 'any'),
('py2', 'none', 'any'),
]
w = Wheel('simple-0.1-py2-none-any.whl')
assert w.support_index_min(tags=tags) == 2
w = Wheel('simple-0.1-py2-none-TEST.whl')
assert w.support_index_min(tags=tags) == 0

def test_support_index_min__none_supported(self):
"""
Test a wheel not supported by the given tags.
"""
w = Wheel('simple-0.1-py2-none-any.whl')
with pytest.raises(ValueError):
w.support_index_min(tags=[])

def test_version_underscore_conversion(self):
"""
Test that we convert '_' to '-' for versions parsed out of wheel
filenames
"""
w = Wheel('simple-0.1_1-py2-none-any.whl')
assert w.version == '0.1-1'
176 changes: 2 additions & 174 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from mock import patch
from pip._vendor.packaging.requirements import Requirement

from pip._internal import pep425tags, wheel
from pip._internal import wheel
from pip._internal.commands.wheel import WheelCommand
from pip._internal.exceptions import InvalidWheelFilename, UnsupportedWheel
from pip._internal.exceptions import UnsupportedWheel
from pip._internal.locations import get_scheme
from pip._internal.models.scheme import Scheme
from pip._internal.models.wheel import Wheel
from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.misc import hash_file
from pip._internal.utils.unpacking import unpack_file
Expand Down Expand Up @@ -227,169 +226,6 @@ def test_check_compatibility():

class TestWheelFile(object):

def test_std_wheel_pattern(self):
w = Wheel('simple-1.1.1-py2-none-any.whl')
assert w.name == 'simple'
assert w.version == '1.1.1'
assert w.pyversions == ['py2']
assert w.abis == ['none']
assert w.plats == ['any']

def test_wheel_pattern_multi_values(self):
w = Wheel('simple-1.1-py2.py3-abi1.abi2-any.whl')
assert w.name == 'simple'
assert w.version == '1.1'
assert w.pyversions == ['py2', 'py3']
assert w.abis == ['abi1', 'abi2']
assert w.plats == ['any']

def test_wheel_with_build_tag(self):
# pip doesn't do anything with build tags, but theoretically, we might
# see one, in this case the build tag = '4'
w = Wheel('simple-1.1-4-py2-none-any.whl')
assert w.name == 'simple'
assert w.version == '1.1'
assert w.pyversions == ['py2']
assert w.abis == ['none']
assert w.plats == ['any']

def test_single_digit_version(self):
w = Wheel('simple-1-py2-none-any.whl')
assert w.version == '1'

def test_non_pep440_version(self):
w = Wheel('simple-_invalid_-py2-none-any.whl')
assert w.version == '-invalid-'

def test_missing_version_raises(self):
with pytest.raises(InvalidWheelFilename):
Wheel('Cython-cp27-none-linux_x86_64.whl')

def test_invalid_filename_raises(self):
with pytest.raises(InvalidWheelFilename):
Wheel('invalid.whl')

def test_supported_single_version(self):
"""
Test single-version wheel is known to be supported
"""
w = Wheel('simple-0.1-py2-none-any.whl')
assert w.supported(tags=[('py2', 'none', 'any')])

def test_supported_multi_version(self):
"""
Test multi-version wheel is known to be supported
"""
w = Wheel('simple-0.1-py2.py3-none-any.whl')
assert w.supported(tags=[('py3', 'none', 'any')])

def test_not_supported_version(self):
"""
Test unsupported wheel is known to be unsupported
"""
w = Wheel('simple-0.1-py2-none-any.whl')
assert not w.supported(tags=[('py1', 'none', 'any')])

def test_supported_osx_version(self):
"""
Wheels built for macOS 10.6 are supported on 10.9
"""
tags = pep425tags.get_supported(
'27', platform='macosx_10_9_intel', impl='cp'
)
w = Wheel('simple-0.1-cp27-none-macosx_10_6_intel.whl')
assert w.supported(tags=tags)
w = Wheel('simple-0.1-cp27-none-macosx_10_9_intel.whl')
assert w.supported(tags=tags)

def test_not_supported_osx_version(self):
"""
Wheels built for macOS 10.9 are not supported on 10.6
"""
tags = pep425tags.get_supported(
'27', platform='macosx_10_6_intel', impl='cp'
)
w = Wheel('simple-0.1-cp27-none-macosx_10_9_intel.whl')
assert not w.supported(tags=tags)

def test_supported_multiarch_darwin(self):
"""
Multi-arch wheels (intel) are supported on components (i386, x86_64)
"""
universal = pep425tags.get_supported(
'27', platform='macosx_10_5_universal', impl='cp'
)
intel = pep425tags.get_supported(
'27', platform='macosx_10_5_intel', impl='cp'
)
x64 = pep425tags.get_supported(
'27', platform='macosx_10_5_x86_64', impl='cp'
)
i386 = pep425tags.get_supported(
'27', platform='macosx_10_5_i386', impl='cp'
)
ppc = pep425tags.get_supported(
'27', platform='macosx_10_5_ppc', impl='cp'
)
ppc64 = pep425tags.get_supported(
'27', platform='macosx_10_5_ppc64', impl='cp'
)

w = Wheel('simple-0.1-cp27-none-macosx_10_5_intel.whl')
assert w.supported(tags=intel)
assert w.supported(tags=x64)
assert w.supported(tags=i386)
assert not w.supported(tags=universal)
assert not w.supported(tags=ppc)
assert not w.supported(tags=ppc64)
w = Wheel('simple-0.1-cp27-none-macosx_10_5_universal.whl')
assert w.supported(tags=universal)
assert w.supported(tags=intel)
assert w.supported(tags=x64)
assert w.supported(tags=i386)
assert w.supported(tags=ppc)
assert w.supported(tags=ppc64)

def test_not_supported_multiarch_darwin(self):
"""
Single-arch wheels (x86_64) are not supported on multi-arch (intel)
"""
universal = pep425tags.get_supported(
'27', platform='macosx_10_5_universal', impl='cp'
)
intel = pep425tags.get_supported(
'27', platform='macosx_10_5_intel', impl='cp'
)

w = Wheel('simple-0.1-cp27-none-macosx_10_5_i386.whl')
assert not w.supported(tags=intel)
assert not w.supported(tags=universal)
w = Wheel('simple-0.1-cp27-none-macosx_10_5_x86_64.whl')
assert not w.supported(tags=intel)
assert not w.supported(tags=universal)

def test_support_index_min(self):
"""
Test results from `support_index_min`
"""
tags = [
('py2', 'none', 'TEST'),
('py2', 'TEST', 'any'),
('py2', 'none', 'any'),
]
w = Wheel('simple-0.1-py2-none-any.whl')
assert w.support_index_min(tags=tags) == 2
w = Wheel('simple-0.1-py2-none-TEST.whl')
assert w.support_index_min(tags=tags) == 0

def test_support_index_min__none_supported(self):
"""
Test a wheel not supported by the given tags.
"""
w = Wheel('simple-0.1-py2-none-any.whl')
with pytest.raises(ValueError):
w.support_index_min(tags=[])

def test_unpack_wheel_no_flatten(self, tmpdir):
filepath = os.path.join(DATA_DIR, 'packages',
'meta-1.0-py2.py3-none-any.whl')
Expand All @@ -412,14 +248,6 @@ def test_purelib_platlib(self, data):
for name, path, expected in packages:
assert wheel.root_is_purelib(name, path) == expected

def test_version_underscore_conversion(self):
"""
Test that we convert '_' to '-' for versions parsed out of wheel
filenames
"""
w = Wheel('simple-0.1_1-py2-none-any.whl')
assert w.version == '0.1-1'


class TestInstallUnpackedWheel(object):
"""
Expand Down

0 comments on commit b8c16a0

Please sign in to comment.