From 047ecfad50069aaa55dcbb4261371571de1c58d9 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Moreno Date: Thu, 1 Feb 2024 07:57:44 +0100 Subject: [PATCH] test: Improve name of mock packages See https://github.com/rpm-software-management/rpmlint/issues/1104 --- test/mock_packages.py | 35 ++++++++++++++++++++++++++++------- test/test_python.py | 24 ++++++++++++------------ 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/test/mock_packages.py b/test/mock_packages.py index 8a2ab32e3..b4e87246c 100644 --- a/test/mock_packages.py +++ b/test/mock_packages.py @@ -1,7 +1,12 @@ -# mock_packages.py from Testing import get_tested_mock_package -PythonSitePackage = get_tested_mock_package( + +######################## +# Python mock packages # +######################## + +# Not valid doc folder in python packages +PythonDocFolderPackage = get_tested_mock_package( files=[ '/usr/lib/python2.7/site-packages/python-mypackage/doc', '/usr/lib/python2.7/site-packages/python-mypackage/docs', @@ -14,7 +19,9 @@ ] ) -PythonModuleMockPackage = get_tested_mock_package( + +# Valid doc folder in python package if it's a python module +PythonDocModulePackage = get_tested_mock_package( files={ '/usr/lib/python2.7/site-packages/python-mypackage/doc/__init__.py': {'create_dirs': True, 'include_dirs': 2}, '/usr/lib/python2.7/site-packages/python-mypackage/docs/__init__.py': {'create_dirs': True, 'include_dirs': 1}, @@ -27,7 +34,9 @@ } ) -PythonDistutilsMockPackage = get_tested_mock_package( + +# Python package with old egginfo file, not folder +PythonEggInfoFileackage = get_tested_mock_package( files={ '/usr/lib/python2.7/site-packages/mydistutilspackage.egg-info': {'content': 'Metadata-Version: 2.1\nName: pythoncheck'}, '/usr/lib/python3.10/site-packages/mydistutilspackage.egg-info': {'content': 'Metadata-Version: 2.1\nName: pythoncheck'}, @@ -36,6 +45,7 @@ } ) + PythonFlitMockPackage = get_tested_mock_package( files={ '/usr/lib/python3.10/site-packages/flit-3.8.0.dist-info/METADATA': { @@ -53,6 +63,7 @@ }, ) + PythonJupyterServerFileidMockPackage = get_tested_mock_package( files={ '/usr/lib/python3.10/site-packages/jupyter_server_fileid-0.9.0.dist-info/METADATA': { @@ -69,6 +80,7 @@ }, ) + PythonJupyterEventsMockPackage = get_tested_mock_package( files={ '/usr/lib/python3.10/site-packages/jupyter_events-0.6.3.dist-info/METADATA': { @@ -102,6 +114,7 @@ }, ) + PythonScikitBuildMockPackage = get_tested_mock_package( files={ '/usr/lib/python3.10/site-packages/scikit_build-0.17.2.dist-info/METADATA': { @@ -120,7 +133,9 @@ }, ) -PythonFlitUpdatedMockPackage = get_tested_mock_package( + +# Python flit package with python3.12dist(foo) requirements (used in Fedora see #1171) +PythonFlitFedoraMockPackage = get_tested_mock_package( files={ '/usr/lib/python3.10/site-packages/flit-3.8.0.dist-info/METADATA': { 'content-path': 'files/python-flit-metadata.txt', @@ -137,6 +152,8 @@ }, ) + +# Python package with old setuptools metadata format, egg-info folder PythonIcecreamPackage = get_tested_mock_package( files={ '/usr/lib/python3.10/site-packages/icecream-2.1.3-py3.10.egg-info/requires.txt': { @@ -160,7 +177,9 @@ ) -PythonBlinkerMockPackage = get_tested_mock_package( +# Python package with multiple pyc for different python versions in the same +# sitelib +PythonMultiplePYCMockPackage = get_tested_mock_package( files=[ '/usr/lib/python3.9/site-packages/blinker/__pycache__/base.cpython-310.pyc', '/usr/lib/python3.9/site-packages/blinker/__pycache__/base.cpython-39.opt-1.pyc', @@ -177,7 +196,9 @@ ] ) -PythonSiteBlinkerMockPackage = get_tested_mock_package( + +# Python package with pyc files but just the correct version +PythonSinglePYCMockPackage = get_tested_mock_package( files=[ '/usr/lib/python3.9/site-packages/blinker/__pycache__/base.cpython-39.opt-1.pyc', '/usr/lib/python3.9/site-packages/blinker/__pycache__/base.cpython-39.pyc', diff --git a/test/test_python.py b/test/test_python.py index 700844e92..c60640047 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -1,15 +1,15 @@ from mock_packages import ( - PythonBlinkerMockPackage, - PythonDistutilsMockPackage, + PythonDocFolderPackage, + PythonDocModulePackage, + PythonEggInfoFileackage, + PythonFlitFedoraMockPackage, PythonFlitMockPackage, - PythonFlitUpdatedMockPackage, PythonIcecreamPackage, PythonJupyterEventsMockPackage, PythonJupyterServerFileidMockPackage, - PythonModuleMockPackage, + PythonMultiplePYCMockPackage, PythonScikitBuildMockPackage, - PythonSiteBlinkerMockPackage, - PythonSitePackage, + PythonSinglePYCMockPackage, ) import pytest from rpmlint.checks.PythonCheck import PythonCheck @@ -38,7 +38,7 @@ def test(pythoncheck): yield test -@pytest.mark.parametrize('package', [PythonSitePackage]) +@pytest.mark.parametrize('package', [PythonDocFolderPackage]) def test_python_doc_in_package(package, test, output): test.check(package) out = output.print_results(output.results) @@ -52,7 +52,7 @@ def test_python_doc_in_package(package, test, output): assert 'W: python-doc-in-package /usr/lib64/python3.10/site-packages/python-mypackage/docs' in out -@pytest.mark.parametrize('package', [PythonModuleMockPackage]) +@pytest.mark.parametrize('package', [PythonDocModulePackage]) def test_python_doc_module_in_package(package, test, output): test.check(package) out = output.print_results(output.results) @@ -66,7 +66,7 @@ def test_python_doc_module_in_package(package, test, output): assert 'W: python-doc-in-package /usr/lib64/python3.10/site-packages/python-mypackage/docs' not in out -@pytest.mark.parametrize('package', [PythonDistutilsMockPackage]) +@pytest.mark.parametrize('package', [PythonEggInfoFileackage]) def test_python_distutils_egg_info(package, test, output): test.check(package) out = output.print_results(output.results) @@ -147,7 +147,7 @@ def test_python_tests_in_site_packages(package, test, output): PythonJupyterServerFileidMockPackage, PythonJupyterEventsMockPackage, PythonScikitBuildMockPackage, - PythonFlitUpdatedMockPackage,]) + PythonFlitFedoraMockPackage,]) def test_python_dependencies_metadata(package, test, output): test.check(package) out = output.print_results(output.results) @@ -257,14 +257,14 @@ def test_python_dependencies_leftover(package, test, output): assert 'W: python-leftover-require' in out -@pytest.mark.parametrize('package', [PythonBlinkerMockPackage]) +@pytest.mark.parametrize('package', [PythonMultiplePYCMockPackage]) def test_python_pyc_multiple_versions(package, test, output): test.check(package) out = output.print_results(output.results) assert 'W: python-pyc-multiple-versions expected: 310' in out -@pytest.mark.parametrize('package', [PythonSiteBlinkerMockPackage]) +@pytest.mark.parametrize('package', [PythonSinglePYCMockPackage]) def test_python_pyc_single_version(package, test, output): test.check(package) out = output.print_results(output.results)