Edit python-rpm-macros tests to work with Python 3.11

Related: rhbz#2207631

All skipped tests have explanations as to why they're not applicable.
This commit is contained in:
Tomas Orsava 2023-08-10 14:45:56 +02:00
parent 80aa391644
commit 0d34243a1f
4 changed files with 63 additions and 22 deletions

View File

@ -1,3 +1,4 @@
%global __python3 /usr/bin/python3.11
%global basedir /opt/test/byte_compilation %global basedir /opt/test/byte_compilation
# We have 3 different ways of bytecompiling: for 3.9+, 3.4-3.8, and 2.7 # We have 3 different ways of bytecompiling: for 3.9+, 3.4-3.8, and 2.7
@ -11,8 +12,10 @@ Release: 0%{?dist}
Summary: ... Summary: ...
License: MIT License: MIT
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python3.6 BuildRequires: python3
BuildRequires: python2.7 BuildRequires: python2
BuildRequires: python3.11-devel
BuildRequires: python3.11-rpm-macros
%description %description
... ...
@ -44,6 +47,12 @@ LOCATIONS="
%{buildroot}%{python27_sitelib}/directory/ %{buildroot}%{python27_sitelib}/directory/
" "
echo "============== Print .py files found in LOCATIONS =================="
find $LOCATIONS -name "*.py"
echo "============== Print .pyc files found in LOCATIONS =================="
find $LOCATIONS -name "*.py[co]"
echo "============== End of print =================="
# Count .py and .pyc files # Count .py and .pyc files
PY=$(find $LOCATIONS -name "*.py" | wc -l) PY=$(find $LOCATIONS -name "*.py" | wc -l)
PYC=$(find $LOCATIONS -name "*.py[co]" | wc -l) PYC=$(find $LOCATIONS -name "*.py[co]" | wc -l)

View File

@ -99,15 +99,17 @@ def shell_stdout(script):
@pytest.mark.parametrize('macro', ['%__python3', '%python3']) @pytest.mark.parametrize('macro', ['%__python3', '%python3'])
def test_python3(macro): def test_python3(macro):
assert rpm_eval(macro) == ['/usr/bin/python3'] assert rpm_eval(macro) == ['/usr/bin/python3.11']
@pytest.mark.skip("Overriden in python3.11-rpm-macros")
@pytest.mark.parametrize('macro', ['%__python3', '%python3']) @pytest.mark.parametrize('macro', ['%__python3', '%python3'])
@pytest.mark.parametrize('pkgversion', ['3', '3.9', '3.12']) @pytest.mark.parametrize('pkgversion', ['3', '3.9', '3.12'])
def test_python3_with_pkgversion(macro, pkgversion): def test_python3_with_pkgversion(macro, pkgversion):
assert rpm_eval(macro, python3_pkgversion=pkgversion) == [f'/usr/bin/python{pkgversion}'] assert rpm_eval(macro, python3_pkgversion=pkgversion) == [f'/usr/bin/python{pkgversion}']
@pytest.mark.skip("py_dist_name uses the old canonicalization on RHEL 8")
@pytest.mark.parametrize('argument, result', [ @pytest.mark.parametrize('argument, result', [
('a', 'a'), ('a', 'a'),
('a-a', 'a-a'), ('a-a', 'a-a'),
@ -124,10 +126,12 @@ def test_pydist_name(argument, result):
assert rpm_eval(f'%py_dist_name {argument}') == [result] assert rpm_eval(f'%py_dist_name {argument}') == [result]
@pytest.mark.skip("py2_dist uses the old canonicalization on RHEL 8")
def test_py2_dist(): def test_py2_dist():
assert rpm_eval(f'%py2_dist Aha[Boom] a') == ['python2dist(aha[boom]) python2dist(a)'] assert rpm_eval(f'%py2_dist Aha[Boom] a') == ['python2dist(aha[boom]) python2dist(a)']
@pytest.mark.skip("py3_dist uses the old canonicalization on RHEL 8")
def test_py3_dist(): def test_py3_dist():
assert rpm_eval(f'%py3_dist Aha[Boom] a') == ['python3dist(aha[boom]) python3dist(a)'] assert rpm_eval(f'%py3_dist Aha[Boom] a') == ['python3dist(aha[boom]) python3dist(a)']
@ -136,10 +140,12 @@ def test_py3_dist_with_python3_pkgversion_redefined(alt_x_y):
assert rpm_eval(f'%py3_dist Aha[Boom] a', python3_pkgversion=alt_x_y) == [f'python{alt_x_y}dist(aha[boom]) python{alt_x_y}dist(a)'] assert rpm_eval(f'%py3_dist Aha[Boom] a', python3_pkgversion=alt_x_y) == [f'python{alt_x_y}dist(aha[boom]) python{alt_x_y}dist(a)']
@pytest.mark.skip("python_provide is still enabled on RHEL 8")
def test_python_provide_python(): def test_python_provide_python():
assert rpm_eval('%python_provide python-foo') == [] assert rpm_eval('%python_provide python-foo') == []
@pytest.mark.skip("python_provide does not work with this test when __python3 is overridden")
def test_python_provide_python3(): def test_python_provide_python3():
lines = rpm_eval('%python_provide python3-foo', version='6', release='1.fc66') lines = rpm_eval('%python_provide python3-foo', version='6', release='1.fc66')
assert 'Obsoletes: python-foo < 6-1.fc66' in lines assert 'Obsoletes: python-foo < 6-1.fc66' in lines
@ -148,6 +154,7 @@ def test_python_provide_python3():
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("python_provide does not work with this test when __python3 is overridden")
def test_python_provide_python3_epoched(): def test_python_provide_python3_epoched():
lines = rpm_eval('%python_provide python3-foo', epoch='1', version='6', release='1.fc66') 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 'Obsoletes: python-foo < 1:6-1.fc66' in lines
@ -156,6 +163,7 @@ def test_python_provide_python3_epoched():
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("python_provide does not work with this test when __python3 is overridden")
def test_python_provide_python3X(): def test_python_provide_python3X():
lines = rpm_eval(f'%python_provide python{X_Y}-foo', version='6', release='1.fc66') lines = rpm_eval(f'%python_provide python{X_Y}-foo', version='6', release='1.fc66')
assert 'Obsoletes: python-foo < 6-1.fc66' in lines assert 'Obsoletes: python-foo < 6-1.fc66' in lines
@ -164,6 +172,7 @@ def test_python_provide_python3X():
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("python_provide does not work with this test when __python3 is overridden")
def test_python_provide_python3X_epoched(): def test_python_provide_python3X_epoched():
lines = rpm_eval(f'%python_provide python{X_Y}-foo', epoch='1', version='6', release='1.fc66') lines = rpm_eval(f'%python_provide python{X_Y}-foo', epoch='1', version='6', release='1.fc66')
assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines assert 'Obsoletes: python-foo < 1:6-1.fc66' in lines
@ -172,6 +181,7 @@ def test_python_provide_python3X_epoched():
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("python_provide does not work with this test when __python3 is overridden")
def test_python_provide_doubleuse(): def test_python_provide_doubleuse():
lines = rpm_eval('%{python_provide python3-foo}%{python_provide python3-foo}', lines = rpm_eval('%{python_provide python3-foo}%{python_provide python3-foo}',
version='6', release='1.fc66') version='6', release='1.fc66')
@ -196,6 +206,7 @@ def test_py_provides_whatever(rhel):
assert len(lines) == 1 assert len(lines) == 1
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 9]) @pytest.mark.parametrize('rhel', [None, 9])
def test_py_provides_python3(rhel): def test_py_provides_python3(rhel):
lines = rpm_eval('%py_provides python3-foo', version='6', release='1.fc66', rhel=rhel) lines = rpm_eval('%py_provides python3-foo', version='6', release='1.fc66', rhel=rhel)
@ -209,6 +220,7 @@ def test_py_provides_python3(rhel):
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 9]) @pytest.mark.parametrize('rhel', [None, 9])
def test_py_provides_python3_with_isa(rhel): def test_py_provides_python3_with_isa(rhel):
lines = rpm_eval('%py_provides python3-foo(x86_64)', version='6', release='1.fc66', rhel=rhel) lines = rpm_eval('%py_provides python3-foo(x86_64)', version='6', release='1.fc66', rhel=rhel)
@ -219,6 +231,7 @@ def test_py_provides_python3_with_isa(rhel):
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 13]) @pytest.mark.parametrize('rhel', [None, 13])
def test_py_provides_python3_epoched(rhel): def test_py_provides_python3_epoched(rhel):
lines = rpm_eval('%py_provides python3-foo', epoch='1', version='6', release='1.fc66', rhel=rhel) lines = rpm_eval('%py_provides python3-foo', epoch='1', version='6', release='1.fc66', rhel=rhel)
@ -232,6 +245,7 @@ def test_py_provides_python3_epoched(rhel):
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 13]) @pytest.mark.parametrize('rhel', [None, 13])
def test_py_provides_python3X(rhel): def test_py_provides_python3X(rhel):
lines = rpm_eval(f'%py_provides python{X_Y}-foo', version='6', release='1.fc66', rhel=rhel) lines = rpm_eval(f'%py_provides python{X_Y}-foo', version='6', release='1.fc66', rhel=rhel)
@ -241,6 +255,7 @@ def test_py_provides_python3X(rhel):
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 27]) @pytest.mark.parametrize('rhel', [None, 27])
def test_py_provides_python3X_epoched(rhel): def test_py_provides_python3X_epoched(rhel):
lines = rpm_eval(f'%py_provides python{X_Y}-foo', epoch='1', version='6', release='1.fc66', rhel=rhel) lines = rpm_eval(f'%py_provides python{X_Y}-foo', epoch='1', version='6', release='1.fc66', rhel=rhel)
@ -250,6 +265,7 @@ def test_py_provides_python3X_epoched(rhel):
assert len(lines) == 3 assert len(lines) == 3
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 2]) @pytest.mark.parametrize('rhel', [None, 2])
def test_py_provides_doubleuse(rhel): def test_py_provides_doubleuse(rhel):
lines = rpm_eval('%{py_provides python3-foo}%{py_provides python3-foo}', lines = rpm_eval('%{py_provides python3-foo}%{py_provides python3-foo}',
@ -266,6 +282,7 @@ def test_py_provides_doubleuse(rhel):
assert len(set(lines)) == 3 assert len(set(lines)) == 3
@pytest.mark.skip("py_provides behaves differently for alternative Python stacks")
@pytest.mark.parametrize('rhel', [None, 2]) @pytest.mark.parametrize('rhel', [None, 2])
def test_py_provides_with_evr(rhel): def test_py_provides_with_evr(rhel):
lines = rpm_eval('%py_provides python3-foo 123', lines = rpm_eval('%py_provides python3-foo 123',
@ -284,7 +301,7 @@ def test_python_wheel_pkg_prefix():
assert rpm_eval('%python_wheel_pkg_prefix', fedora='44', rhel=None, eln=None) == ['python'] assert rpm_eval('%python_wheel_pkg_prefix', fedora='44', rhel=None, eln=None) == ['python']
assert rpm_eval('%python_wheel_pkg_prefix', fedora='44', rhel=None, eln=None, python3_pkgversion='3.9') == ['python'] assert rpm_eval('%python_wheel_pkg_prefix', fedora='44', rhel=None, eln=None, python3_pkgversion='3.9') == ['python']
assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln='1') == ['python'] assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln='1') == ['python']
assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln=None) == ['python3'] assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln=None) == ['python3.11']
assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln=None, python3_pkgversion='3.10') == ['python3.10'] assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln=None, python3_pkgversion='3.10') == ['python3.10']
assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln=None, python3_pkgversion='3.11') == ['python3.11'] assert rpm_eval('%python_wheel_pkg_prefix', fedora=None, rhel='1', eln=None, python3_pkgversion='3.11') == ['python3.11']
@ -293,14 +310,14 @@ def test_python_wheel_dir():
assert rpm_eval('%python_wheel_dir', fedora='44', rhel=None, eln=None) == ['/usr/share/python-wheels'] assert rpm_eval('%python_wheel_dir', fedora='44', rhel=None, eln=None) == ['/usr/share/python-wheels']
assert rpm_eval('%python_wheel_dir', fedora='44', rhel=None, eln=None, python3_pkgversion='3.9') == ['/usr/share/python-wheels'] assert rpm_eval('%python_wheel_dir', fedora='44', rhel=None, eln=None, python3_pkgversion='3.9') == ['/usr/share/python-wheels']
assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln='1') == ['/usr/share/python-wheels'] assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln='1') == ['/usr/share/python-wheels']
assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln=None) == ['/usr/share/python3-wheels'] assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln=None) == ['/usr/share/python3.11-wheels']
assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln=None, python3_pkgversion='3.10') == ['/usr/share/python3.10-wheels'] assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln=None, python3_pkgversion='3.10') == ['/usr/share/python3.10-wheels']
assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln=None, python3_pkgversion='3.11') == ['/usr/share/python3.11-wheels'] assert rpm_eval('%python_wheel_dir', fedora=None, rhel='1', eln=None, python3_pkgversion='3.11') == ['/usr/share/python3.11-wheels']
def test_pytest_passes_options_naturally(): def test_pytest_passes_options_naturally():
lines = rpm_eval('%pytest -k foo') lines = rpm_eval('%pytest -k foo')
assert '/usr/bin/pytest -k foo' in lines[-1] assert '/usr/bin/pytest-3.11 -k foo' in lines[-1]
def test_pytest_different_command(): def test_pytest_different_command():
@ -310,7 +327,7 @@ def test_pytest_different_command():
def test_pytest_command_suffix(): def test_pytest_command_suffix():
lines = rpm_eval('%pytest -v') lines = rpm_eval('%pytest -v')
assert '/usr/bin/pytest -v' in lines[-1] assert '/usr/bin/pytest-3.11 -v' in lines[-1]
# this test does not require alternate Pythons to be installed # this test does not require alternate Pythons to be installed
@pytest.mark.parametrize('version', ['3.6', '3.7', '3.12']) @pytest.mark.parametrize('version', ['3.6', '3.7', '3.12'])
@ -319,6 +336,7 @@ def test_pytest_command_suffix_alternate_pkgversion(version):
assert f'/usr/bin/pytest-{version} -v' in lines[-1] assert f'/usr/bin/pytest-{version} -v' in lines[-1]
@pytest.mark.skip("This functionality is not present in RHEL 8")
def test_pytest_sets_pytest_xdist_auto_num_workers(): def test_pytest_sets_pytest_xdist_auto_num_workers():
lines = rpm_eval('%pytest', _smp_build_ncpus=2) lines = rpm_eval('%pytest', _smp_build_ncpus=2)
assert 'PYTEST_XDIST_AUTO_NUM_WORKERS=2' in '\n'.join(lines) assert 'PYTEST_XDIST_AUTO_NUM_WORKERS=2' in '\n'.join(lines)
@ -356,7 +374,7 @@ def test_pytest_addopts_preserves_envvar(__pytest_addopts):
assert 'option--' not in echoed assert 'option--' not in echoed
assert 'z--' not in echoed assert 'z--' not in echoed
@pytest.mark.skip("RHEL 8 predates py3_test_envvars")
@pytest.mark.parametrize('__pytest_addopts', ['-X', None]) @pytest.mark.parametrize('__pytest_addopts', ['-X', None])
def test_py3_test_envvars(lib, __pytest_addopts): def test_py3_test_envvars(lib, __pytest_addopts):
lines = rpm_eval('%{py3_test_envvars}\\\n%{python3} -m unittest', lines = rpm_eval('%{py3_test_envvars}\\\n%{python3} -m unittest',
@ -376,7 +394,7 @@ def test_py3_test_envvars(lib, __pytest_addopts):
assert f'PYTEST_ADDOPTS="${{PYTEST_ADDOPTS:-}} {__pytest_addopts}"' in stripped_lines assert f'PYTEST_ADDOPTS="${{PYTEST_ADDOPTS:-}} {__pytest_addopts}"' in stripped_lines
else: else:
assert 'PYTEST_ADDOPTS' not in ''.join(lines) assert 'PYTEST_ADDOPTS' not in ''.join(lines)
assert stripped_lines[-1] == '/usr/bin/python3 -m unittest' assert stripped_lines[-1] == '/usr/bin/python3.11 -m unittest'
def test_pypi_source_default_name(): def test_pypi_source_default_name():
@ -433,9 +451,10 @@ def test_pypi_source_explicit_tilde():
assert urls == ['https://files.pythonhosted.org/packages/source/f/foo/foo-6~6.tar.gz'] assert urls == ['https://files.pythonhosted.org/packages/source/f/foo/foo-6~6.tar.gz']
@pytest.mark.skip("%py3_shebang_fix has a complicated evaluation in RHEL 8 due to differences between Python stacks")
def test_py3_shebang_fix(): def test_py3_shebang_fix():
cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3')[-1].strip() cmd = rpm_eval('%py3_shebang_fix arg1 arg2 arg3')[-1].strip()
assert cmd == '/usr/bin/python3 -B /usr/lib/rpm/redhat/pathfix.py -pni /usr/bin/python3 $shebang_flags arg1 arg2 arg3' assert cmd == '/usr/bin/python3.11 -B /usr/lib/rpm/redhat/pathfix.py -pni /usr/bin/python3.11 $shebang_flags arg1 arg2 arg3'
def test_py3_shebang_fix_default_shebang_flags(): def test_py3_shebang_fix_default_shebang_flags():
@ -482,6 +501,7 @@ def test_py3_shebang_fix_no_shebang_flags(flags):
assert shell_stdout('\n'.join(lines)) == '-k' assert shell_stdout('\n'.join(lines)) == '-k'
@pytest.mark.skip("%py_shebang_fix has a complicated evaluation in RHEL 8 due to differences between Python stacks")
def test_py_shebang_fix_custom_python(): def test_py_shebang_fix_custom_python():
cmd = rpm_eval('%py_shebang_fix arg1 arg2 arg3', __python='/usr/bin/pypy')[-1].strip() cmd = rpm_eval('%py_shebang_fix arg1 arg2 arg3', __python='/usr/bin/pypy')[-1].strip()
assert cmd == '/usr/bin/pypy -B /usr/lib/rpm/redhat/pathfix.py -pni /usr/bin/pypy $shebang_flags arg1 arg2 arg3' assert cmd == '/usr/bin/pypy -B /usr/lib/rpm/redhat/pathfix.py -pni /usr/bin/pypy $shebang_flags arg1 arg2 arg3'
@ -535,6 +555,7 @@ def test_pycached_fails_with_extension_glob():
assert lines[0] == 'error: %pycached can only be used with paths explicitly ending with .py' assert lines[0] == 'error: %pycached can only be used with paths explicitly ending with .py'
@pytest.mark.skip("Python extras subpackages are not handled in RHEL 8")
def test_python_extras_subpkg_i(): def test_python_extras_subpkg_i():
lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -i %{python3_sitelib}/*.egg-info toml yaml', lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -i %{python3_sitelib}/*.egg-info toml yaml',
version='6', release='7') version='6', release='7')
@ -564,6 +585,7 @@ def test_python_extras_subpkg_i():
assert lines == expected assert lines == expected
@pytest.mark.skip("Python extras subpackages are not handled in RHEL 8")
def test_python_extras_subpkg_f(): def test_python_extras_subpkg_f():
lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -f ghost_filelist toml yaml', lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -f ghost_filelist toml yaml',
version='6', release='7') version='6', release='7')
@ -591,6 +613,7 @@ def test_python_extras_subpkg_f():
assert lines == expected assert lines == expected
@pytest.mark.skip("Python extras subpackages are not handled in RHEL 8")
def test_python_extras_subpkg_F(): def test_python_extras_subpkg_F():
lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -F toml yaml', lines = rpm_eval('%python_extras_subpkg -n python3-setuptools_scm -F toml yaml',
version='6', release='7') version='6', release='7')
@ -616,6 +639,7 @@ def test_python_extras_subpkg_F():
assert lines == expected assert lines == expected
@pytest.mark.skip("Python extras subpackages are not handled in RHEL 8")
def test_python_extras_subpkg_underscores(): def test_python_extras_subpkg_underscores():
lines = rpm_eval('%python_extras_subpkg -n python3-webscrapbook -F adhoc_ssl', lines = rpm_eval('%python_extras_subpkg -n python3-webscrapbook -F adhoc_ssl',
version='0.33.3', release='1.fc33') version='0.33.3', release='1.fc33')
@ -631,6 +655,7 @@ def test_python_extras_subpkg_underscores():
assert lines == expected assert lines == expected
@pytest.mark.skip("Python extras subpackages are not handled in RHEL 8")
@pytest.mark.parametrize('sep', [pytest.param(('', ' ', ' ', ''), id='spaces'), @pytest.mark.parametrize('sep', [pytest.param(('', ' ', ' ', ''), id='spaces'),
pytest.param(('', ',', ',', ''), id='commas'), pytest.param(('', ',', ',', ''), id='commas'),
pytest.param(('', ',', ',', ','), id='commas-trailing'), pytest.param(('', ',', ',', ','), id='commas-trailing'),
@ -672,6 +697,7 @@ def test_python_extras_subpkg_arg_separators(sep):
assert lines == expected assert lines == expected
@pytest.mark.skip("Python extras subpackages are not handled in RHEL 8")
@pytest.mark.parametrize('basename_len', [1, 10, 30, 45, 78]) @pytest.mark.parametrize('basename_len', [1, 10, 30, 45, 78])
@pytest.mark.parametrize('extra_len', [1, 13, 28, 52, 78]) @pytest.mark.parametrize('extra_len', [1, 13, 28, 52, 78])
def test_python_extras_subpkg_description_wrapping(basename_len, extra_len): def test_python_extras_subpkg_description_wrapping(basename_len, extra_len):
@ -717,6 +743,7 @@ unversioned_macros = pytest.mark.parametrize('macro', [
]) ])
@pytest.mark.skip("Not applicable for python3.11-rpm-macros")
@unversioned_macros @unversioned_macros
def test_unversioned_python_errors(macro): def test_unversioned_python_errors(macro):
lines = rpm_eval(macro, fails=True) lines = rpm_eval(macro, fails=True)
@ -734,10 +761,11 @@ def test_unversioned_python_errors(macro):
assert len(lines) < 3 assert len(lines) < 3
@pytest.mark.skip("Not applicable for python3.11-rpm-macros")
@unversioned_macros @unversioned_macros
def test_unversioned_python_works_when_defined(macro): def test_unversioned_python_works_when_defined(macro):
macro3 = macro.replace('python', 'python3').replace('py_', 'py3_') macro3 = macro.replace('python', 'python3').replace('py_', 'py3_')
assert rpm_eval(macro, __python='/usr/bin/python3') == rpm_eval(macro3) assert rpm_eval(macro, __python='/usr/bin/python3.11') == rpm_eval(macro3)
# we could rework the test for multiple architectures, but the Fedora CI currently only runs on x86_64 # we could rework the test for multiple architectures, but the Fedora CI currently only runs on x86_64
@ -766,6 +794,7 @@ def test_cache_tag_alternate_python3(alt_x_y, alt_xy):
assert rpm_eval("%python3_cache_tag", __python3=f"/usr/bin/python{alt_x_y}") == [f"cpython-{alt_xy}"] assert rpm_eval("%python3_cache_tag", __python3=f"/usr/bin/python{alt_x_y}") == [f"cpython-{alt_xy}"]
@pytest.mark.skip("Throws DeprecationWarning when run with Python 3.11, expected")
def test_python_sitelib_value_python3(): def test_python_sitelib_value_python3():
macro = '%python_sitelib' macro = '%python_sitelib'
assert rpm_eval(macro, __python='%__python3') == [f'/usr/lib/python{X_Y}/site-packages'] assert rpm_eval(macro, __python='%__python3') == [f'/usr/lib/python{X_Y}/site-packages']
@ -793,6 +822,7 @@ def test_python3_sitelib_value_alternate_prefix():
assert rpm_eval(macro, _prefix='/app') == [f'/app/lib/python{X_Y}/site-packages'] assert rpm_eval(macro, _prefix='/app') == [f'/app/lib/python{X_Y}/site-packages']
@pytest.mark.skip("Throws DeprecationWarning when run with Python 3.11, expected")
def test_python_sitearch_value_python3(lib): def test_python_sitearch_value_python3(lib):
macro = '%python_sitearch' macro = '%python_sitearch'
assert rpm_eval(macro, __python='%__python3') == [f'/usr/{lib}/python{X_Y}/site-packages'] assert rpm_eval(macro, __python='%__python3') == [f'/usr/{lib}/python{X_Y}/site-packages']
@ -865,7 +895,7 @@ def test_py3_check_import(args, expected_args, __python3, lib):
PYTHONPATH="${{PYTHONPATH:-BUILDROOT/usr/{lib}/python{x_y}/site-packages:BUILDROOT/usr/lib/python{x_y}/site-packages}}" PYTHONPATH="${{PYTHONPATH:-BUILDROOT/usr/{lib}/python{x_y}/site-packages:BUILDROOT/usr/lib/python{x_y}/site-packages}}"
_PYTHONSITE="BUILDROOT/usr/{lib}/python{x_y}/site-packages:BUILDROOT/usr/lib/python{x_y}/site-packages" _PYTHONSITE="BUILDROOT/usr/{lib}/python{x_y}/site-packages:BUILDROOT/usr/lib/python{x_y}/site-packages"
PYTHONDONTWRITEBYTECODE=1 PYTHONDONTWRITEBYTECODE=1
{__python3 or '/usr/bin/python3'} -s{safe_path_flag(x_y)} RPMCONFIGDIR/redhat/import_all_modules.py {expected_args} {__python3 or '/usr/bin/python3.11'} -s{safe_path_flag(x_y)} RPMCONFIGDIR/redhat/import_all_modules_py3_11.py {expected_args}
""") """)
assert lines == expected.splitlines() assert lines == expected.splitlines()
@ -888,5 +918,5 @@ def test_py3_check_import_respects_shebang_flags(shebang_flags_value, expected_s
} }
lines = rpm_eval('%py3_check_import sys', **macros) lines = rpm_eval('%py3_check_import sys', **macros)
# Compare the last line of the command, that's where lua part is evaluated # Compare the last line of the command, that's where lua part is evaluated
expected = f'/usr/bin/python3 {expected_shebang_flags} RPMCONFIGDIR/redhat/import_all_modules.py sys' expected = f'/usr/bin/python3 {expected_shebang_flags} RPMCONFIGDIR/redhat/import_all_modules_py3_11.py sys'
assert lines[-1].strip() == expected assert lines[-1].strip() == expected

View File

@ -1,6 +1,6 @@
from import_all_modules import argparser, exclude_unwanted_module_globs from import_all_modules_py3_11 import argparser, exclude_unwanted_module_globs
from import_all_modules import main as modules_main from import_all_modules_py3_11 import main as modules_main
from import_all_modules import read_modules_from_cli, filter_top_level_modules_only from import_all_modules_py3_11 import read_modules_from_cli, filter_top_level_modules_only
from pathlib import Path from pathlib import Path
@ -118,9 +118,9 @@ def test_import_all_modules_does_not_import():
# We already imported it in this file once, make sure it's not imported # We already imported it in this file once, make sure it's not imported
# from the cache # from the cache
sys.modules.pop('import_all_modules') sys.modules.pop('import_all_modules_py3_11')
with pytest.raises(ModuleNotFoundError): with pytest.raises(ModuleNotFoundError):
modules_main(['import_all_modules']) modules_main(['import_all_modules_py3_11'])
def test_modules_from_cwd_not_found(tmp_path, monkeypatch): def test_modules_from_cwd_not_found(tmp_path, monkeypatch):

View File

@ -15,7 +15,7 @@
tests: tests:
- pytest: - pytest:
dir: . dir: .
run: PYTHONPATH=/usr/lib/rpm/redhat ALTERNATE_PYTHON_VERSION=3.6 pytest -v run: PYTHONPATH=/usr/lib/rpm/redhat ALTERNATE_PYTHON_VERSION=skip pytest-3.11 -v
- manual_byte_compilation_clamp_mtime_off: - manual_byte_compilation_clamp_mtime_off:
dir: . dir: .
run: rpmbuild --define 'dist .clamp0' --define 'clamp_mtime_to_source_date_epoch 0' -ba pythontest.spec run: rpmbuild --define 'dist .clamp0' --define 'clamp_mtime_to_source_date_epoch 0' -ba pythontest.spec
@ -33,8 +33,10 @@
- rpmlint - rpmlint
- python-rpm-macros - python-rpm-macros
- python3-rpm-macros - python3-rpm-macros
- python3.11-rpm-macros
- python3.11-devel
- python3.11-pytest
- python3
- python3-devel - python3-devel
- python3-pytest - python2
- python3.6
- python2.7