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

fix tests on pypy #3

Open
nixjdm opened this issue Jan 13, 2023 · 0 comments
Open

fix tests on pypy #3

nixjdm opened this issue Jan 13, 2023 · 0 comments

Comments

@nixjdm
Copy link
Member

nixjdm commented Jan 13, 2023

Currently there are two failing tests on pypy, shown below.

I didn't notice them because I also apparently have tox misconfigured, so I don't think I actually was using pypy in my local tests. In my branch to test github actions I have pypy running, where I noticed the failure. https://github.com/terminal-labs/deep_collections/actions/runs/3914234772 That's commented out for now. I'd like to add that back in when these tests are fixed.

2 pypy test failures:
____________________________ TestTuple.test_getitem ____________________________

self = <tests.test_builtins.TestTuple object at 0x0000000003bd5590>
dc = DeepCollection(('nested', ('thing', 'spam')))

    def test_getitem(self, dc):
        assert dc[0] == "nested"
        assert dc[1, 1] == "spam"
    
>       assert isinstance(dc[1], self._type)

tests/conftest.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
deep_collections/__init__.py:720: in __getitem__
    return DeepCollection(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'deep_collections.DeepCollection'>, args = ()
kwargs = {'match_args': (), 'match_kwargs': {}, 'match_with': 'glob', 'recursive_match_all': True}
obj = ('thing', 'spam'), dynamic_parent_cls = <class 'tuple'>
new_cls = <class 'deep_collections.DeepCollection_tuple'>

    def __call__(cls, *args, **kwargs):
        if args:
            obj = args[0]
            args = args[1:]
        else:
            obj = {}
    
        # If a DC is given, we must use the original type as the parent_cls. We don't
        # want or need to nest DC types, and we if we don't flattten the inheritence
        # we get a metaclass conflict can't produce a consistent method resolution.
        if hasattr(obj, "_obj") and isinstance(obj, DeepCollection):
            dynamic_parent_cls = type(obj._obj)
        else:
            dynamic_parent_cls = type(obj)
    
        # Make a new_cls that inherits from the dynamic_parent_cls, and resolve any
        # potential metaclass conflicts, like when the object has its own metaclass
        # already, as when it's an ABC.
        try:
            # Resultant type is deep_collections.DeepCollection_[type]
            new_cls = type(
                f"{cls.__name__}_{dynamic_parent_cls.__name__}",
                (cls, dynamic_parent_cls),
                {},
            )
        except TypeError:
            # Resolve metaclass conflict.
            # Create a new metaclass on the fly, merging the two we have.
            mcls = type(cls)
            cls.__class__ = type(
                f"{mcls.__name__}_{dynamic_parent_cls.__name__}",
                (mcls, type(dynamic_parent_cls)),
                {},
            )
            # Resultant type is likely abc.DeepCollection_[type]
            new_cls = type(
                f"{cls.__name__}_{dynamic_parent_cls.__name__}",
                (cls, dynamic_parent_cls),
                {},
            )
    
        # Create the instance and initialize it with the given object.
        # Sets obj in instance for immutables like tuple
        # instance = new_cls.__new__(new_cls, obj, *args, **kwargs)
>       instance = new_cls.__new__(new_cls, obj, *args, **kwargs)
E       TypeError: __new__() got 4 unexpected keyword arguments

deep_collections/__init__.py:557: TypeError
_____________________________ TestTuple.test_slice _____________________________

self = <tests.test_builtins.TestTuple object at 0x0000000003bd5050>

    def test_slice(self):
        dc = DeepCollection(self._type([*range(10)]))
>       assert dc[2:8] == self._type([2, 3, 4, 5, 6, 7])

tests/conftest.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
deep_collections/__init__.py:720: in __getitem__
    return DeepCollection(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'deep_collections.DeepCollection'>, args = ()
kwargs = {'match_args': (), 'match_kwargs': {}, 'match_with': 'glob', 'recursive_match_all': True}
obj = (2, 3, 4, 5, 6, 7), dynamic_parent_cls = <class 'tuple'>
new_cls = <class 'deep_collections.DeepCollection_tuple'>

    def __call__(cls, *args, **kwargs):
        if args:
            obj = args[0]
            args = args[1:]
        else:
            obj = {}
    
        # If a DC is given, we must use the original type as the parent_cls. We don't
        # want or need to nest DC types, and we if we don't flattten the inheritence
        # we get a metaclass conflict can't produce a consistent method resolution.
        if hasattr(obj, "_obj") and isinstance(obj, DeepCollection):
            dynamic_parent_cls = type(obj._obj)
        else:
            dynamic_parent_cls = type(obj)
    
        # Make a new_cls that inherits from the dynamic_parent_cls, and resolve any
        # potential metaclass conflicts, like when the object has its own metaclass
        # already, as when it's an ABC.
        try:
            # Resultant type is deep_collections.DeepCollection_[type]
            new_cls = type(
                f"{cls.__name__}_{dynamic_parent_cls.__name__}",
                (cls, dynamic_parent_cls),
                {},
            )
        except TypeError:
            # Resolve metaclass conflict.
            # Create a new metaclass on the fly, merging the two we have.
            mcls = type(cls)
            cls.__class__ = type(
                f"{mcls.__name__}_{dynamic_parent_cls.__name__}",
                (mcls, type(dynamic_parent_cls)),
                {},
            )
            # Resultant type is likely abc.DeepCollection_[type]
            new_cls = type(
                f"{cls.__name__}_{dynamic_parent_cls.__name__}",
                (cls, dynamic_parent_cls),
                {},
            )
    
        # Create the instance and initialize it with the given object.
        # Sets obj in instance for immutables like tuple
        # instance = new_cls.__new__(new_cls, obj, *args, **kwargs)
>       instance = new_cls.__new__(new_cls, obj, *args, **kwargs)
E       TypeError: __new__() got 4 unexpected keyword arguments
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

1 participant