aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-07-31 20:39:07 -0400
committerJason R. Coombs <jaraco@jaraco.com>2016-07-31 20:39:07 -0400
commit6c93713d75f5888cc9654ec23fc05f5b7772b51a (patch)
treebb3368c9a8b6c98759501855766ddd29e00f5ec0 /setuptools
parent573a34e3ab68a73ba2407d4990e68eba43c964ca (diff)
downloadexternal_python_setuptools-6c93713d75f5888cc9654ec23fc05f5b7772b51a.tar.gz
external_python_setuptools-6c93713d75f5888cc9654ec23fc05f5b7772b51a.tar.bz2
external_python_setuptools-6c93713d75f5888cc9654ec23fc05f5b7772b51a.zip
Rewrite test_dist_info using pytest fixtures.
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/tests/test_dist_info.py81
1 files changed, 43 insertions, 38 deletions
diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py
index db3cb2e7..92ef6e8c 100644
--- a/setuptools/tests/test_dist_info.py
+++ b/setuptools/tests/test_dist_info.py
@@ -14,10 +14,47 @@ from .textwrap import DALS
class TestDistInfo:
- def test_distinfo(self):
+ metadata_template = DALS("""
+ Metadata-Version: 1.2
+ Name: {name}
+ {version}
+ Requires-Dist: splort (==4)
+ Provides-Extra: baz
+ Requires-Dist: quux (>=1.1); extra == 'baz'
+ """)
+
+ @pytest.fixture
+ def metadata(self, tmpdir):
+ dist_info_name = 'VersionedDistribution-2.718.dist-info'
+ versioned = tmpdir / dist_info_name
+ versioned.mkdir()
+ filename = versioned / 'METADATA'
+ filename.write_text(
+ self.metadata_template.format(
+ name='VersionedDistribution',
+ version='',
+ ).replace('\n\n', '\n'),
+ encoding='utf-8',
+ )
+
+ dist_info_name = 'UnversionedDistribution.dist-info'
+ unversioned = tmpdir / dist_info_name
+ unversioned.mkdir()
+ filename = unversioned / 'METADATA'
+ filename.write_text(
+ self.metadata_template.format(
+ name='UnversionedDistribution',
+ version='Version: 0.3',
+ ),
+ encoding='utf-8',
+ )
+
+ return str(tmpdir)
+
+ def test_distinfo(self, metadata):
dists = dict(
(d.project_name, d)
- for d in pkg_resources.find_distributions(self.tmpdir)
+ for d in pkg_resources.find_distributions(metadata)
)
assert len(dists) == 2, dists
@@ -28,46 +65,14 @@ class TestDistInfo:
assert versioned.version == '2.718' # from filename
assert unversioned.version == '0.3' # from METADATA
- def test_conditional_dependencies(self):
+ def test_conditional_dependencies(self, metadata):
specs = 'splort==4', 'quux>=1.1'
requires = list(map(pkg_resources.Requirement.parse, specs))
- for d in pkg_resources.find_distributions(self.tmpdir):
+ for d in pkg_resources.find_distributions(metadata):
assert d.requires() == requires[:1]
assert d.requires(extras=('baz',)) == [
requires[0],
- pkg_resources.Requirement.parse('quux>=1.1;extra=="baz"')]
+ pkg_resources.Requirement.parse('quux>=1.1;extra=="baz"'),
+ ]
assert d.extras == ['baz']
-
- metadata_template = DALS("""
- Metadata-Version: 1.2
- Name: {name}
- {version}
- Requires-Dist: splort (==4)
- Provides-Extra: baz
- Requires-Dist: quux (>=1.1); extra == 'baz'
- """)
-
- def setup_method(self, method):
- self.tmpdir = tempfile.mkdtemp()
- dist_info_name = 'VersionedDistribution-2.718.dist-info'
- versioned = os.path.join(self.tmpdir, dist_info_name)
- os.mkdir(versioned)
- with open(os.path.join(versioned, 'METADATA'), 'w+') as metadata_file:
- metadata = self.metadata_template.format(
- name='VersionedDistribution',
- version='',
- ).replace('\n\n', '\n')
- metadata_file.write(metadata)
- dist_info_name = 'UnversionedDistribution.dist-info'
- unversioned = os.path.join(self.tmpdir, dist_info_name)
- os.mkdir(unversioned)
- with open(os.path.join(unversioned, 'METADATA'), 'w+') as metadata_file:
- metadata = self.metadata_template.format(
- name='UnversionedDistribution',
- version='Version: 0.3',
- )
- metadata_file.write(metadata)
-
- def teardown_method(self, method):
- shutil.rmtree(self.tmpdir)