Commit 6c93713d authored by Jason R. Coombs's avatar Jason R. Coombs

Rewrite test_dist_info using pytest fixtures.

parent 573a34e3
......@@ -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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment