Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Jul 2, 2018
1 parent 2610078 commit 49a915d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
6 changes: 5 additions & 1 deletion flit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ def __init__(self, data):
assert hasattr(self, k), "data does not have attribute '{}'".format(k)
setattr(self, k, v)
if extras_require:
self.requires_dist = self.requires_dist + ['{}; extra == "{}"'.format(d, e) for e, d in extras_require.items()]
self.requires_dist = list(self.requires_dist) + [
'{}; extra == "{}"'.format(d, e)
for e, ds in extras_require.items()
for d in ds
]

def _normalise_name(self, n):
return n.lower().replace('-', '_')
Expand Down
1 change: 1 addition & 0 deletions tests/samples/extras.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
description-file = "EG_README.rst"
requires = ["toml"]

[tool.flit.metadata.extras-require]
test = ["pytest"]
Expand Down
30 changes: 30 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,36 @@ def test_install_requires(self):
assert len(calls) == 1
assert calls[0]['argv'][1:5] == ['-m', 'pip', 'install', '-r']

@pytest.mark.parametrize(('deps', 'extras', 'installed'), [
('none', [], set()),
('dev', [], {'pytest;'}), # TODO: why not also normal reqs, i.e. toml?
('production', [], {'toml;'}),
('all', [], {'toml;', 'pytest;', 'requests;'}),
])
def test_install_requires_extras(deps, extras, installed, samples_dir):
it = InstallTests()
try:
it.setUp()
ins = Installer(samples_dir / 'extras.toml', python='mock_python',
user=False, deps=deps, extras=extras)

cmd = MockCommand('mock_python')
get_reqs = (
"#!{python}\n"
"import sys, pathlib\n"
"pathlib.Path({recording_file!r}).write_text(pathlib.Path(sys.argv[-1]).read_text())\n"
).format(python=sys.executable, recording_file=cmd.recording_file)
cmd.content = get_reqs

with cmd as mock_py:
ins.install_requirements()
str_deps = pathlib.Path(mock_py.recording_file).read_text()
deps = str_deps.split('\n') if str_deps else []

assert set(deps) == installed
finally:
it.tearDown()

def test_requires_dist_to_pip_requirement():
rd = 'pathlib2 (>=2.3); python_version == "2.7"'
assert _requires_dist_to_pip_requirement(rd) == \
Expand Down
7 changes: 6 additions & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ def test_extras(samples_dir):
def test_extras_dev_conflict(samples_dir):
info = read_pkg_ini(samples_dir / 'extras-dev-conflict.toml')
with pytest.raises(ValueError, match=r'Ambiguity'):
Metadata(dict(name=info['module'], version='0.0', summary='', **info['metadata']))
Metadata(dict(name=info['module'], version='0.0', summary='', **info['metadata']))

def test_extra_conditions(samples_dir):
info = read_pkg_ini(samples_dir / 'extras.toml')
meta = Metadata(dict(name=info['module'], version='0.0', summary='', **info['metadata']))
assert set(meta.requires_dist) == {'toml', 'pytest; extra == "test"', 'requests; extra == "custom"'}

0 comments on commit 49a915d

Please sign in to comment.