From 141d093b0e7f50459c8053ee4619c9991473be6e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 28 Nov 2015 11:51:17 -0500 Subject: Move test into pkg_resources tests --- pkg_resources/tests/test_pkg_resources.py | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) (limited to 'pkg_resources/tests/test_pkg_resources.py') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 564d7cec..257cbb5b 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -5,9 +5,17 @@ import zipfile import datetime import time import subprocess +import stat + +import pytest import pkg_resources +from setuptools.tests.textwrap import DALS +from setuptools.tests import contexts +from setuptools.tests import environment + + try: unicode except NameError: @@ -109,3 +117,91 @@ class TestIndependence: ) cmd = [sys.executable, '-c', '; '.join(lines)] subprocess.check_call(cmd) + + + +class TestEggInfoDistutils(object): + + version = '1.11.0.dev0+2329eae' + setup_script = DALS(""" + from distutils.core import setup + + setup( + name='foo', + py_modules=['hello'], + version='%s', + ) + """) + + def _create_project(self): + with open('setup.py', 'w') as f: + f.write(self.setup_script % self.version) + + with open('hello.py', 'w') as f: + f.write(DALS(""" + def run(): + print('hello') + """)) + + @pytest.yield_fixture + def env(self): + class Environment(str): + pass + with contexts.tempdir(prefix='setuptools-test.') as env_dir: + env = Environment(env_dir) + os.chmod(env_dir, stat.S_IRWXU) + subs = 'home', 'lib', 'scripts', 'data', 'egg-base' + env.paths = dict( + (dirname, os.path.join(env_dir, dirname)) + for dirname in subs + ) + list(map(os.mkdir, env.paths.values())) + config = os.path.join(env.paths['home'], '.pydistutils.cfg') + with open(config, 'w') as f: + f.write(DALS(""" + [egg_info] + egg-base = %(egg-base)s + """ % env.paths)) + yield env + + def test_egg_base_installed_egg_info(self, tmpdir_cwd, env): + self._create_project() + + environ = os.environ.copy().update( + HOME=env.paths['home'], + ) + cmd = [ + 'install', + '--home', env.paths['home'], + '--install-lib', env.paths['lib'], + '--install-scripts', env.paths['scripts'], + '--install-data', env.paths['data'], + ] + code, data = environment.run_setup_py( + cmd=cmd, + pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), + data_stream=1, + env=environ, + ) + if code: + raise AssertionError(data) + + actual = self._find_egg_info_file(env.paths['lib']) + # On Py3k it can be e.g. foo-1.11.0.dev0_2329eae-py3.4.egg-info + # but 2.7 doesn't add the Python version, so to be expedient we + # just check our start and end, omitting the potential version num + assert actual.startswith('foo-' + self.version.replace('+', '_')) + assert actual.endswith('.egg-info') + # 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 == self.version + + def _find_egg_info_file(self, root): + # expect exactly one result + result = (filename for dirpath, dirnames, filenames in os.walk(root) + for filename in filenames if filename.endswith('.egg-info')) + result, = result + return result + -- cgit v1.2.3 From 25fc8c1d05c84ea9d6155be4326e837f90dd173d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 28 Nov 2015 11:54:23 -0500 Subject: Rename test to match intention. --- pkg_resources/tests/test_pkg_resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pkg_resources/tests/test_pkg_resources.py') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 257cbb5b..698aefbd 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -164,7 +164,7 @@ class TestEggInfoDistutils(object): """ % env.paths)) yield env - def test_egg_base_installed_egg_info(self, tmpdir_cwd, env): + def test_version_resolved_from_egg_info(self, tmpdir_cwd, env): self._create_project() environ = os.environ.copy().update( -- cgit v1.2.3 From 41868fe7c4f75708b3cb663bf1b76405223869b0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 28 Nov 2015 12:54:28 -0500 Subject: Rewrite test to simply create the egg_info. --- pkg_resources/tests/test_pkg_resources.py | 115 +++++++++--------------------- 1 file changed, 35 insertions(+), 80 deletions(-) (limited to 'pkg_resources/tests/test_pkg_resources.py') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 698aefbd..8b9a317a 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -8,13 +8,10 @@ import subprocess import stat import pytest +import py import pkg_resources -from setuptools.tests.textwrap import DALS -from setuptools.tests import contexts -from setuptools.tests import environment - try: unicode @@ -120,88 +117,46 @@ class TestIndependence: -class TestEggInfoDistutils(object): +class TestDeepVersionLookup(object): - version = '1.11.0.dev0+2329eae' - setup_script = DALS(""" - from distutils.core import setup + @pytest.fixture + def env(self, tmpdir): + """ + Create a package environment, similar to a virtualenv, + in which packages are installed. + """ + class Environment(str): + pass - setup( - name='foo', - py_modules=['hello'], - version='%s', + 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 ) - """) - - def _create_project(self): - with open('setup.py', 'w') as f: - f.write(self.setup_script % self.version) + list(map(os.mkdir, env.paths.values())) + return env - with open('hello.py', 'w') as f: - f.write(DALS(""" - def run(): - print('hello') - """)) + def create_foo_pkg(self, env, version): + """ + Create a foo package installed to env.paths['lib'] + as version. + """ + safe_version = pkg_resources.safe_version(version) + lib = py.path.local(env.paths['lib']) + egg_info = lib / 'foo-' + safe_version + '.egg-info' + egg_info.mkdir() + pkg_info = egg_info / 'PKG_INFO' + with pkg_info.open('w') as strm: + strm.write('version: ' + version) + + def test_version_resolved_from_egg_info(self, env): + version = '1.11.0.dev0+2329eae' + self.create_foo_pkg(env, version) - @pytest.yield_fixture - def env(self): - class Environment(str): - pass - with contexts.tempdir(prefix='setuptools-test.') as env_dir: - env = Environment(env_dir) - os.chmod(env_dir, stat.S_IRWXU) - subs = 'home', 'lib', 'scripts', 'data', 'egg-base' - env.paths = dict( - (dirname, os.path.join(env_dir, dirname)) - for dirname in subs - ) - list(map(os.mkdir, env.paths.values())) - config = os.path.join(env.paths['home'], '.pydistutils.cfg') - with open(config, 'w') as f: - f.write(DALS(""" - [egg_info] - egg-base = %(egg-base)s - """ % env.paths)) - yield env - - def test_version_resolved_from_egg_info(self, tmpdir_cwd, env): - self._create_project() - - environ = os.environ.copy().update( - HOME=env.paths['home'], - ) - cmd = [ - 'install', - '--home', env.paths['home'], - '--install-lib', env.paths['lib'], - '--install-scripts', env.paths['scripts'], - '--install-data', env.paths['data'], - ] - code, data = environment.run_setup_py( - cmd=cmd, - pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), - data_stream=1, - env=environ, - ) - if code: - raise AssertionError(data) - - actual = self._find_egg_info_file(env.paths['lib']) - # On Py3k it can be e.g. foo-1.11.0.dev0_2329eae-py3.4.egg-info - # but 2.7 doesn't add the Python version, so to be expedient we - # just check our start and end, omitting the potential version num - assert actual.startswith('foo-' + self.version.replace('+', '_')) - assert actual.endswith('.egg-info') # 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 == self.version - - def _find_egg_info_file(self, root): - # expect exactly one result - result = (filename for dirpath, dirnames, filenames in os.walk(root) - for filename in filenames if filename.endswith('.egg-info')) - result, = result - return result - + assert dist.version == version -- cgit v1.2.3 From 9744cf2edf82eeda796ca22bf21ac0056c8aa925 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 28 Nov 2015 13:00:32 -0500 Subject: Rewrite test to use distutils' install_egg_info to generate the metadata. --- pkg_resources/tests/test_pkg_resources.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'pkg_resources/tests/test_pkg_resources.py') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 8b9a317a..0a03dd93 100644 --- a/pkg_resources/tests/test_pkg_resources.py +++ b/pkg_resources/tests/test_pkg_resources.py @@ -6,9 +6,10 @@ import datetime import time import subprocess import stat +import distutils.dist +import distutils.command.install_egg_info import pytest -import py import pkg_resources @@ -117,7 +118,7 @@ class TestIndependence: -class TestDeepVersionLookup(object): +class TestDeepVersionLookupDistutils(object): @pytest.fixture def env(self, tmpdir): @@ -140,16 +141,16 @@ class TestDeepVersionLookup(object): def create_foo_pkg(self, env, version): """ - Create a foo package installed to env.paths['lib'] + Create a foo package installed (distutils-style) to env.paths['lib'] as version. """ - safe_version = pkg_resources.safe_version(version) - lib = py.path.local(env.paths['lib']) - egg_info = lib / 'foo-' + safe_version + '.egg-info' - egg_info.mkdir() - pkg_info = egg_info / 'PKG_INFO' - with pkg_info.open('w') as strm: - strm.write('version: ' + version) + attrs = dict(name='foo', version=version) + 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' -- cgit v1.2.3 From dfbc96168d8b921bd6b02fe7aeceeeb930f68cfe Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Dec 2015 09:24:52 -0500 Subject: Add test for regression on Python 3 when LANG=C and there is non-ascii in the metadata file before the version. Ref #469. --- pkg_resources/tests/test_pkg_resources.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'pkg_resources/tests/test_pkg_resources.py') diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py index 0a03dd93..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 @@ -144,7 +147,8 @@ class TestDeepVersionLookupDistutils(object): Create a foo package installed (distutils-style) to env.paths['lib'] as version. """ - attrs = dict(name='foo', version=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() -- cgit v1.2.3