2019-07-17 13:44:22 +00:00
|
|
|
from pathlib import Path
|
|
|
|
import io
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from pyproject_buildrequires import generate_requires
|
|
|
|
|
2019-08-10 12:34:24 +00:00
|
|
|
try:
|
|
|
|
import importlib.metadata as importlib_metadata
|
|
|
|
except ImportError:
|
|
|
|
import importlib_metadata
|
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
testcases = {}
|
2020-04-15 14:44:04 +00:00
|
|
|
with Path(__file__).parent.joinpath('pyproject_buildrequires_testcases.yaml').open() as f:
|
2019-07-17 13:44:22 +00:00
|
|
|
testcases = yaml.safe_load(f)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('case_name', testcases)
|
|
|
|
def test_data(case_name, capsys, tmp_path, monkeypatch):
|
|
|
|
case = testcases[case_name]
|
|
|
|
|
|
|
|
cwd = tmp_path.joinpath('cwd')
|
|
|
|
cwd.mkdir()
|
|
|
|
monkeypatch.chdir(cwd)
|
|
|
|
|
2019-07-18 09:00:23 +00:00
|
|
|
if case.get('xfail'):
|
|
|
|
pytest.xfail(case.get('xfail'))
|
|
|
|
|
2019-07-26 12:34:21 +00:00
|
|
|
for filename in 'pyproject.toml', 'setup.py', 'tox.ini':
|
|
|
|
if filename in case:
|
|
|
|
cwd.joinpath(filename).write_text(case[filename])
|
2019-07-17 13:44:22 +00:00
|
|
|
|
2019-08-10 12:34:24 +00:00
|
|
|
def get_installed_version(dist_name):
|
|
|
|
try:
|
|
|
|
return str(case['installed'][dist_name])
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
raise importlib_metadata.PackageNotFoundError(
|
|
|
|
f'info not found for {dist_name}'
|
|
|
|
)
|
|
|
|
|
2019-07-17 13:44:22 +00:00
|
|
|
try:
|
|
|
|
generate_requires(
|
2019-08-10 12:34:24 +00:00
|
|
|
get_installed_version=get_installed_version,
|
2019-07-17 16:16:16 +00:00
|
|
|
include_runtime=case.get('include_runtime', False),
|
2020-09-30 20:31:07 +00:00
|
|
|
extras=case.get('extras', []),
|
2019-07-26 12:34:21 +00:00
|
|
|
toxenv=case.get('toxenv', None),
|
2020-08-14 12:57:40 +00:00
|
|
|
generate_extras=case.get('generate_extras', False),
|
2019-07-17 13:44:22 +00:00
|
|
|
)
|
|
|
|
except SystemExit as e:
|
|
|
|
assert e.code == case['result']
|
|
|
|
except Exception as e:
|
2019-07-17 16:16:16 +00:00
|
|
|
if 'except' not in case:
|
|
|
|
raise
|
2019-07-17 13:44:22 +00:00
|
|
|
assert type(e).__name__ == case['except']
|
|
|
|
else:
|
|
|
|
assert 0 == case['result']
|
|
|
|
|
|
|
|
captured = capsys.readouterr()
|
|
|
|
assert captured.out == case['expected']
|