From f5bea8c7b747063345fb07ed1449f3f65b0af422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 28 Apr 2020 19:28:31 +0200 Subject: [PATCH] Fedora CI: Add eval tests for %python_provide and %py_provides --- tests/.gitignore | 1 + tests/test_evals.py | 124 ++++++++++++++++++++++++++++++++++++++++++++ tests/tests.yml | 23 ++++++++ 3 files changed, 148 insertions(+) create mode 100644 tests/.gitignore create mode 100644 tests/test_evals.py create mode 100644 tests/tests.yml diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..5732c0f --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +__*__/ diff --git a/tests/test_evals.py b/tests/test_evals.py new file mode 100644 index 0000000..e1d91e7 --- /dev/null +++ b/tests/test_evals.py @@ -0,0 +1,124 @@ +import subprocess +import sys + +XY = f'{sys.version_info[0]}{sys.version_info[1]}' + + +def rpm_eval(expression, **kwargs): + cmd = ['rpmbuild'] + for var, value in kwargs.items(): + cmd += ['--define', f'{var} {value}'] + cmd += ['--eval', expression] + cp = subprocess.run(cmd, text=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + assert cp.returncode == 0, cp.stderr + return cp.stdout.strip().splitlines() + + +def test_python_provide_python(): + assert rpm_eval('%python_provide python-foo') == [] + + +def test_python_provide_python3(): + lines = rpm_eval('%python_provide python3-foo', version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert f'Provides: python{XY}-foo = 6-1.fc66' in lines + assert len(lines) == 3 + + +def test_python_provide_python3_epoched(): + lines = rpm_eval('%python_provide python3-foo', epoch='1', version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines + assert 'Provides: python-foo = 1:6-1.fc66' in lines + assert f'Provides: python{XY}-foo = 1:6-1.fc66' in lines + assert len(lines) == 3 + + +def test_python_provide_python3X(): + lines = rpm_eval(f'%python_provide python{XY}-foo', version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert 'Provides: python3-foo = 6-1.fc66' in lines + assert len(lines) == 3 + + +def test_python_provide_python3X_epoched(): + lines = rpm_eval(f'%python_provide python{XY}-foo', epoch='1', version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines + assert 'Provides: python-foo = 1:6-1.fc66' in lines + assert 'Provides: python3-foo = 1:6-1.fc66' in lines + assert len(lines) == 3 + + +def test_python_provide_doubleuse(): + lines = rpm_eval('%{python_provide python3-foo}%{python_provide python3-foo}', + version='6', release='1.fc66') + assert 'Obsoletes: python-foo < 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert f'Provides: python{XY}-foo = 6-1.fc66' in lines + assert len(lines) == 6 + assert len(set(lines)) == 3 + + +def test_py_provides_python(): + lines = rpm_eval('%py_provides python-foo', version='6', release='1.fc66') + assert 'Provides: python-foo = 6-1.fc66' in lines + assert len(lines) == 1 + + +def test_py_provides_whatever(): + lines = rpm_eval('%py_provides whatever', version='6', release='1.fc66') + assert 'Provides: whatever = 6-1.fc66' in lines + assert len(lines) == 1 + + +def test_py_provides_python3(): + lines = rpm_eval('%py_provides python3-foo', version='6', release='1.fc66') + assert 'Provides: python3-foo = 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert f'Provides: python{XY}-foo = 6-1.fc66' in lines + assert len(lines) == 3 + + +def test_py_provides_python3_epoched(): + lines = rpm_eval('%py_provides python3-foo', epoch='1', version='6', release='1.fc66') + assert 'Provides: python3-foo = 1:6-1.fc66' in lines + assert 'Provides: python-foo = 1:6-1.fc66' in lines + assert f'Provides: python{XY}-foo = 1:6-1.fc66' in lines + assert len(lines) == 3 + + +def test_py_provides_python3X(): + lines = rpm_eval(f'%py_provides python{XY}-foo', version='6', release='1.fc66') + assert f'Provides: python{XY}-foo = 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert 'Provides: python3-foo = 6-1.fc66' in lines + assert len(lines) == 3 + + +def test_py_provides_python3X_epoched(): + lines = rpm_eval(f'%py_provides python{XY}-foo', epoch='1', version='6', release='1.fc66') + assert f'Provides: python{XY}-foo = 1:6-1.fc66' in lines + assert 'Provides: python-foo = 1:6-1.fc66' in lines + assert 'Provides: python3-foo = 1:6-1.fc66' in lines + assert len(lines) == 3 + + +def test_py_provides_doubleuse(): + lines = rpm_eval('%{py_provides python3-foo}%{py_provides python3-foo}', + version='6', release='1.fc66') + assert 'Provides: python3-foo = 6-1.fc66' in lines + assert 'Provides: python-foo = 6-1.fc66' in lines + assert f'Provides: python{XY}-foo = 6-1.fc66' in lines + assert len(lines) == 6 + assert len(set(lines)) == 3 + + +def test_py_provides_with_evr(): + lines = rpm_eval('%py_provides python3-foo 123', + version='6', release='1.fc66') + assert 'Provides: python3-foo = 123' in lines + assert 'Provides: python-foo = 123' in lines + assert f'Provides: python{XY}-foo = 123' in lines + assert len(lines) == 3 diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..10c35b7 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,23 @@ +--- +- hosts: localhost + tags: + - classic + tasks: + - dnf: + name: "*" + state: latest + +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + tests: + - pytest: + dir: . + run: pytest -v + required_packages: + - rpm-build + - python-rpm-macros + - python3-pytest +