1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/unit/test_wheel.py

153 lines
5.2 KiB
Python
Raw Normal View History

2013-05-28 23:58:08 +02:00
"""Tests for wheel binary packages and .dist-info."""
import pkg_resources
from mock import patch, Mock
2013-05-28 23:58:08 +02:00
from pip import wheel
from pip.exceptions import InstallationError
from pip.index import PackageFinder
from tests.lib import assert_raises_regexp
from nose.tools import assert_raises
2013-05-28 23:58:08 +02:00
def test_uninstallation_paths():
class dist(object):
def get_metadata_lines(self, record):
return ['file.py,,',
'file.pyc,,',
'file.so,,',
'nopyc.py']
location = ''
d = dist()
paths = list(wheel.uninstallation_paths(d))
expected = ['file.py',
'file.pyc',
'file.so',
'nopyc.py',
'nopyc.pyc']
assert paths == expected
# Avoid an easy 'unique generator' bug
paths2 = list(wheel.uninstallation_paths(d))
assert paths2 == paths
class TestWheelSupported(object):
def raise_not_found(self, dist):
raise pkg_resources.DistributionNotFound()
def set_use_wheel_true(self, finder):
finder.use_wheel = True
@patch("pip.wheel.pkg_resources.get_distribution")
def test_wheel_supported_true(self, mock_get_distribution):
"""
Test wheel_supported returns true, when setuptools is installed and requirement is met
2013-05-28 23:58:08 +02:00
"""
mock_get_distribution.return_value = pkg_resources.Distribution(project_name='setuptools', version='0.9')
assert wheel.wheel_setuptools_support()
2013-05-28 23:58:08 +02:00
@patch("pip.wheel.pkg_resources.get_distribution")
def test_wheel_supported_false_no_install(self, mock_get_distribution):
"""
Test wheel_supported returns false, when setuptools not installed
2013-05-28 23:58:08 +02:00
"""
mock_get_distribution.side_effect = self.raise_not_found
assert not wheel.wheel_setuptools_support()
2013-05-28 23:58:08 +02:00
@patch("pip.wheel.pkg_resources.get_distribution")
def test_wheel_supported_false_req_fail(self, mock_get_distribution):
"""
Test wheel_supported returns false, when setuptools is installed, but req is not met
2013-05-28 23:58:08 +02:00
"""
mock_get_distribution.return_value = pkg_resources.Distribution(project_name='setuptools', version='0.7')
assert not wheel.wheel_setuptools_support()
2013-05-28 23:58:08 +02:00
@patch("pip.wheel.pkg_resources.get_distribution")
def test_finder_raises_error(self, mock_get_distribution):
"""
Test the PackageFinder raises an error when wheel is not supported
"""
mock_get_distribution.side_effect = self.raise_not_found
# on initialization
assert_raises_regexp(InstallationError, 'wheel support', PackageFinder, [], [], use_wheel=True)
# when setting property later
p = PackageFinder([], [])
assert_raises_regexp(InstallationError, 'wheel support', self.set_use_wheel_true, p)
@patch("pip.wheel.pkg_resources.get_distribution")
def test_finder_no_raises_error(self, mock_get_distribution):
"""
Test the PackageFinder doesn't raises an error when use_wheel is False, and wheel is supported
"""
mock_get_distribution.return_value = pkg_resources.Distribution(project_name='setuptools', version='0.9')
2013-05-28 23:58:08 +02:00
p = PackageFinder( [], [], use_wheel=False)
p = PackageFinder([], [])
p.use_wheel = False
class TestWheelFile(object):
def test_supported_single_version(self):
"""
Test single-version wheel is known to be supported
"""
w = wheel.Wheel('simple-0.1-py2-none-any.whl')
2013-06-30 20:54:45 +02:00
assert w.supported(tags=[('py2', 'none', 'any')])
2013-05-28 23:58:08 +02:00
def test_supported_multi_version(self):
"""
Test multi-version wheel is known to be supported
"""
w = wheel.Wheel('simple-0.1-py2.py3-none-any.whl')
2013-06-30 20:54:45 +02:00
assert w.supported(tags=[('py3', 'none', 'any')])
2013-05-28 23:58:08 +02:00
def test_not_supported_version(self):
"""
Test unsupported wheel is known to be unsupported
"""
w = wheel.Wheel('simple-0.1-py2-none-any.whl')
2013-06-30 20:54:45 +02:00
assert not w.supported(tags=[('py1', 'none', 'any')])
2013-05-28 23:58:08 +02:00
def test_support_index_min(self):
"""
Test results from `support_index_min`
"""
2013-06-30 20:54:45 +02:00
tags = [
('py2', 'none', 'TEST'),
('py2', 'TEST', 'any'),
('py2', 'none', 'any'),
]
2013-05-28 23:58:08 +02:00
w = wheel.Wheel('simple-0.1-py2-none-any.whl')
assert w.support_index_min(tags=tags) == 2
2013-05-28 23:58:08 +02:00
w = wheel.Wheel('simple-0.1-py2-none-TEST.whl')
assert w.support_index_min(tags=tags) == 0
2013-05-28 23:58:08 +02:00
def test_support_index_min_none(self):
"""
Test `support_index_min` returns None, when wheel not supported
"""
w = wheel.Wheel('simple-0.1-py2-none-any.whl')
2013-06-30 20:54:45 +02:00
assert w.support_index_min(tags=[]) == None
2013-05-28 23:58:08 +02:00
def test_unpack_wheel_no_flatten(self):
from pip import util
from tempfile import mkdtemp
from shutil import rmtree
import os
from nose import SkipTest
filepath = '../data/packages/meta-1.0-py2.py3-none-any.whl'
if not os.path.exists(filepath):
raise SkipTest
try:
tmpdir = mkdtemp()
util.unpack_file(filepath, tmpdir, 'application/zip', None )
assert os.path.isdir(os.path.join(tmpdir,'meta-1.0.dist-info'))
finally:
rmtree(tmpdir)
pass