diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-12-31 10:51:55 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-12-31 10:51:55 -0500 |
commit | 29fa01621c3de0a5c78c4f49b5d051386d0d566f (patch) | |
tree | fce7387c8ba82178be987b004cbda1c22005a04f /pkg_resources/tests/test_pkg_resources.py | |
parent | 928324bd76f35e9c8c526df828577b5640a95ed0 (diff) | |
parent | 6bdbe8957d8c8d293e3fea3fa4baf45eb7c3a3a4 (diff) | |
download | external_python_setuptools-29fa01621c3de0a5c78c4f49b5d051386d0d566f.tar.gz external_python_setuptools-29fa01621c3de0a5c78c4f49b5d051386d0d566f.tar.bz2 external_python_setuptools-29fa01621c3de0a5c78c4f49b5d051386d0d566f.zip |
Merge with master. Ref #229.
--HG--
branch : feature/issue-229
Diffstat (limited to 'pkg_resources/tests/test_pkg_resources.py')
-rw-r--r-- | pkg_resources/tests/test_pkg_resources.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 564d7cec..31eee635 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -1,3 +1,6 @@ +# coding: utf-8 +from __future__ import unicode_literals + import sys import tempfile import os @@ -5,9 +8,15 @@ import zipfile import datetime import time import subprocess +import stat +import distutils.dist +import distutils.command.install_egg_info + +import pytest import pkg_resources + try: unicode except NameError: @@ -109,3 +118,50 @@ class TestIndependence: ) cmd = [sys.executable, '-c', '; '.join(lines)] subprocess.check_call(cmd) + + + +class TestDeepVersionLookupDistutils(object): + + @pytest.fixture + def env(self, tmpdir): + """ + Create a package environment, similar to a virtualenv, + in which packages are installed. + """ + class Environment(str): + pass + + env = Environment(tmpdir) + tmpdir.chmod(stat.S_IRWXU) + subs = 'home', 'lib', 'scripts', 'data', 'egg-base' + env.paths = dict( + (dirname, str(tmpdir / dirname)) + for dirname in subs + ) + list(map(os.mkdir, env.paths.values())) + return env + + def create_foo_pkg(self, env, version): + """ + Create a foo package installed (distutils-style) to env.paths['lib'] + as version. + """ + ld = "This package has unicode metadata! ❄" + attrs = dict(name='foo', version=version, long_description=ld) + dist = distutils.dist.Distribution(attrs) + iei_cmd = distutils.command.install_egg_info.install_egg_info(dist) + iei_cmd.initialize_options() + iei_cmd.install_dir = env.paths['lib'] + iei_cmd.finalize_options() + iei_cmd.run() + + def test_version_resolved_from_egg_info(self, env): + version = '1.11.0.dev0+2329eae' + self.create_foo_pkg(env, version) + + # this requirement parsing will raise a VersionConflict unless the + # .egg-info file is parsed (see #419 on BitBucket) + req = pkg_resources.Requirement.parse('foo>=1.9') + dist = pkg_resources.WorkingSet([env.paths['lib']]).find(req) + assert dist.version == version |