2019-07-17 13:44:22 +00:00
|
|
|
from pathlib import Path
|
|
|
|
import io
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from pyproject_buildrequires import generate_requires
|
|
|
|
|
|
|
|
testcases = {}
|
|
|
|
with Path(__file__).parent.joinpath('testcases.yaml').open() as f:
|
|
|
|
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-17 13:44:22 +00:00
|
|
|
if 'pyproject.toml' in case:
|
|
|
|
cwd.joinpath('pyproject.toml').write_text(case['pyproject.toml'])
|
|
|
|
|
|
|
|
if 'setup.py' in case:
|
|
|
|
cwd.joinpath('setup.py').write_text(case['setup.py'])
|
|
|
|
|
|
|
|
try:
|
|
|
|
generate_requires(
|
|
|
|
case['freeze_output'],
|
2019-07-17 16:16:16 +00:00
|
|
|
include_runtime=case.get('include_runtime', False),
|
2019-07-18 08:50:13 +00:00
|
|
|
extras=case.get('extras', ''),
|
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']
|