Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failures with Python 3.12 #19

Closed
mgorny opened this issue Aug 23, 2023 · 3 comments
Closed

Test failures with Python 3.12 #19

mgorny opened this issue Aug 23, 2023 · 3 comments

Comments

@mgorny
Copy link

mgorny commented Aug 23, 2023

$ tox -e py312
.pkg: install_requires> python -I -m pip install 'setuptools>=40.8.0' wheel
.pkg: _optional_hooks> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: install_requires_for_build_wheel> python -I -m pip install wheel
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
.pkg: build_sdist> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
py312: install_package_deps> python -I -m pip install pytest tox
py312: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/paginate/.tox/.tmp/package/1/paginate-0.5.6.tar.gz
py312: commands[0]> pytest
========================================================= test session starts =========================================================
platform linux -- Python 3.12.0rc1, pytest-7.4.0, pluggy-1.2.0
cachedir: .tox/py312/.pytest_cache
rootdir: /tmp/paginate
collected 19 items                                                                                                                    

tests/test_paginate.py F.................F                                                                                      [100%]

============================================================== FAILURES ===============================================================
________________________________________________________ test_wrong_collection ________________________________________________________

    def test_wrong_collection():
        """Test whether an empty list is handled correctly."""
        with pytest.raises(TypeError):
>           page = paginate.Page({}, page=0)

tests/test_paginate.py:13: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[AttributeError("'Page' object has no attribute 'page_count'") raised in repr()] Page object at 0x7f84fa0b6d50>
collection = {}, page = 0, items_per_page = 20, item_count = None, wrapper_class = None, url_maker = None, kwargs = {}, first = 0
last = 20

    def __init__(
        self,
        collection,
        page=1,
        items_per_page=20,
        item_count=None,
        wrapper_class=None,
        url_maker=None,
        **kwargs
    ):
        """Create a "Page" instance.
    
        Parameters:
    
        collection
            Sequence representing the collection of items to page through.
    
        page
            The requested page number - starts with 1. Default: 1.
    
        items_per_page
            The maximal number of items to be displayed per page.
            Default: 20.
    
        item_count (optional)
            The total number of items in the collection - if known.
            If this parameter is not given then the paginator will count
            the number of elements in the collection every time a "Page"
            is created. Giving this parameter will speed up things. In a busy
            real-life application you may want to cache the number of items.
    
        url_maker (optional)
            Callback to generate the URL of other pages, given its numbers.
            Must accept one int parameter and return a URI string.
        """
        if collection is not None:
            if wrapper_class is None:
                # Default case. The collection is already a list-type object.
                self.collection = collection
            else:
                # Special case. A custom wrapper class is used to access elements of the collection.
                self.collection = wrapper_class(collection)
        else:
            self.collection = []
    
        self.collection_type = type(collection)
    
        if url_maker is not None:
            self.url_maker = url_maker
        else:
            self.url_maker = self._default_url_maker
    
        # Assign kwargs to self
        self.kwargs = kwargs
    
        # The self.page is the number of the current page.
        # The first page has the number 1!
        try:
            self.page = int(page)  # make it int() if we get it as a string
        except (ValueError, TypeError):
            self.page = 1
        # normally page should be always at least 1 but the original maintainer
        # decided that for empty collection and empty page it can be...0? (based on tests)
        # preserving behavior for BW compat
        if self.page < 1:
            self.page = 1
    
        self.items_per_page = items_per_page
    
        # We subclassed "list" so we need to call its init() method
        # and fill the new list with the items to be displayed on the page.
        # We use list() so that the items on the current page are retrieved
        # only once. In an SQL context that could otherwise lead to running the
        # same SQL query every time items would be accessed.
        # We do this here, prior to calling len() on the collection so that a
        # wrapper class can execute a query with the knowledge of what the
        # slice will be (for efficiency) and, in the same query, ask for the
        # total number of items and only execute one query.
        try:
            first = (self.page - 1) * items_per_page
            last = first + items_per_page
>           self.items = list(self.collection[first:last])
E           KeyError: slice(0, 20, None)

.tox/py312/lib/python3.12/site-packages/paginate/__init__.py:261: KeyError
___________________________________________ TestCollectionTypes.test_unsliceable_sequence3 ____________________________________________

self = <test_paginate.TestCollectionTypes object at 0x7f84fa0c97f0>

    def test_unsliceable_sequence3(self):
        with pytest.raises(TypeError):
>           paginate.Page(dict(one=1))

tests/test_paginate.py:350: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[AttributeError("'Page' object has no attribute 'page_count'") raised in repr()] Page object at 0x7f84fa0b6d00>
collection = {'one': 1}, page = 1, items_per_page = 20, item_count = None, wrapper_class = None, url_maker = None, kwargs = {}
first = 0, last = 20

    def __init__(
        self,
        collection,
        page=1,
        items_per_page=20,
        item_count=None,
        wrapper_class=None,
        url_maker=None,
        **kwargs
    ):
        """Create a "Page" instance.
    
        Parameters:
    
        collection
            Sequence representing the collection of items to page through.
    
        page
            The requested page number - starts with 1. Default: 1.
    
        items_per_page
            The maximal number of items to be displayed per page.
            Default: 20.
    
        item_count (optional)
            The total number of items in the collection - if known.
            If this parameter is not given then the paginator will count
            the number of elements in the collection every time a "Page"
            is created. Giving this parameter will speed up things. In a busy
            real-life application you may want to cache the number of items.
    
        url_maker (optional)
            Callback to generate the URL of other pages, given its numbers.
            Must accept one int parameter and return a URI string.
        """
        if collection is not None:
            if wrapper_class is None:
                # Default case. The collection is already a list-type object.
                self.collection = collection
            else:
                # Special case. A custom wrapper class is used to access elements of the collection.
                self.collection = wrapper_class(collection)
        else:
            self.collection = []
    
        self.collection_type = type(collection)
    
        if url_maker is not None:
            self.url_maker = url_maker
        else:
            self.url_maker = self._default_url_maker
    
        # Assign kwargs to self
        self.kwargs = kwargs
    
        # The self.page is the number of the current page.
        # The first page has the number 1!
        try:
            self.page = int(page)  # make it int() if we get it as a string
        except (ValueError, TypeError):
            self.page = 1
        # normally page should be always at least 1 but the original maintainer
        # decided that for empty collection and empty page it can be...0? (based on tests)
        # preserving behavior for BW compat
        if self.page < 1:
            self.page = 1
    
        self.items_per_page = items_per_page
    
        # We subclassed "list" so we need to call its init() method
        # and fill the new list with the items to be displayed on the page.
        # We use list() so that the items on the current page are retrieved
        # only once. In an SQL context that could otherwise lead to running the
        # same SQL query every time items would be accessed.
        # We do this here, prior to calling len() on the collection so that a
        # wrapper class can execute a query with the knowledge of what the
        # slice will be (for efficiency) and, in the same query, ask for the
        # total number of items and only execute one query.
        try:
            first = (self.page - 1) * items_per_page
            last = first + items_per_page
>           self.items = list(self.collection[first:last])
E           KeyError: slice(0, 20, None)

.tox/py312/lib/python3.12/site-packages/paginate/__init__.py:261: KeyError
======================================================= short test summary info =======================================================
FAILED tests/test_paginate.py::test_wrong_collection - KeyError: slice(0, 20, None)
FAILED tests/test_paginate.py::TestCollectionTypes::test_unsliceable_sequence3 - KeyError: slice(0, 20, None)
==================================================== 2 failed, 17 passed in 0.19s =====================================================
py312: exit 1 (0.54 seconds) /tmp/paginate> pytest pid=169085
.pkg: _exit> python /usr/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
  py312: FAIL code 1 (13.61=setup[13.08]+cmd[0.54] seconds)
  evaluation failed :( (13.81 seconds)
@mgorny
Copy link
Author

mgorny commented Sep 14, 2023

Ping.

@Nowa-Ammerlaan
Copy link

Looks like the problem is that a dict is a valid slice in python3.12. So we get KeyError instead of the expected TypeError.

@mgorny
Copy link
Author

mgorny commented Nov 8, 2023

Ping.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this issue Mar 22, 2024
https://build.opensuse.org/request/show/1160541
by user dgarcia + anag+factory
- Add python312.patch and build for python 3.12
  gh#Pylons/paginate#19
@ergo ergo closed this as completed in 9c88317 Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants