Skip to content

Commit

Permalink
test: Improve name of mock packages
Browse files Browse the repository at this point in the history
See #1104
  • Loading branch information
danigm committed Feb 1, 2024
1 parent 3192919 commit 047ecfa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
35 changes: 28 additions & 7 deletions test/mock_packages.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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},
Expand All @@ -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'},
Expand All @@ -36,6 +45,7 @@
}
)


PythonFlitMockPackage = get_tested_mock_package(
files={
'/usr/lib/python3.10/site-packages/flit-3.8.0.dist-info/METADATA': {
Expand All @@ -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': {
Expand All @@ -69,6 +80,7 @@
},
)


PythonJupyterEventsMockPackage = get_tested_mock_package(
files={
'/usr/lib/python3.10/site-packages/jupyter_events-0.6.3.dist-info/METADATA': {
Expand Down Expand Up @@ -102,6 +114,7 @@
},
)


PythonScikitBuildMockPackage = get_tested_mock_package(
files={
'/usr/lib/python3.10/site-packages/scikit_build-0.17.2.dist-info/METADATA': {
Expand All @@ -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',
Expand All @@ -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': {
Expand All @@ -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',
Expand All @@ -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',
Expand Down
24 changes: 12 additions & 12 deletions test/test_python.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 047ecfa

Please sign in to comment.