python-makefun icon indicating copy to clipboard operation
python-makefun copied to clipboard

Tests fail with python3.13b2

Open keszybz opened this issue 1 year ago • 2 comments

This seems to be just a very trivial formatting difference:

=================================== FAILURES ===================================
___________________________________ test_doc ___________________________________

    def test_doc():
        def foo(x, y):
            """
            a `foo` function
    
            :param x:
            :param y:
            :return:
            """
            return x + y
    
        ref_bar = functools.partial(foo, x=12)
    
        ref_sig_str = "(x=12, y)" if PY2 else "(*, x=12, y)"
        assert str(signature(ref_bar)) == ref_sig_str
    
        bar = makefun.partial(foo, x=12)
    
        # same behaviour - except in python 2 where our "KW_ONLY_ARG!" appear
        assert str(signature(bar)).replace("=KW_ONLY_ARG!", "") == str(signature(ref_bar))
    
        bar.__name__ = 'bar'
        help(bar)
        with pytest.raises(TypeError):
            bar(1)
        assert bar(y=1) == 13
    
        sig_actual_call = ref_sig_str.replace("*, ", "")
    
>       assert bar.__doc__ \
               == """<This function is equivalent to 'foo%s', see original 'foo' doc below.>
    
            a `foo` function
    
            :param x:
            :param y:
            :return:
            """ % sig_actual_call
E       assert "<This function is equivalent to 'foo(x=12, y)', see original 'foo' doc below.>\n\na `foo` function\n\n:param x:\n:param y:\n:return:\n" == "<This function is equivalent to 'foo(x=12, y)', see original 'foo' doc below.>\n\n        a `foo` function\n\n        :param x:\n        :param y:\n        :return:\n        "
E           <This function is equivalent to 'foo(x=12, y)', see original 'foo' doc below.>
E           
E         -         a `foo` function
E         ? --------
E         + a `foo` function
E           
E         + :param x:
E         + :param y:
E         + :return:
E         -         :param x:
E         -         :param y:
E         -         :return:
E         -

tests/test_partial_and_macros.py:44: AssertionError
----------------------------- Captured stdout call -----------------------------
Help on function bar in module tests.test_partial_and_macros:

bar(*, x=12, y)
    <This function is equivalent to 'foo(x=12, y)', see original 'foo' doc below.>

    a `foo` function

    :param x:
    :param y:
    :return:

_________________________________ test_partial _________________________________

    def test_partial():
        """Tests that `with_partial` works"""
    
        @makefun.with_partial(y='hello')
        def foo(x, y, a):
            """
            a `foo` function
    
            :param x:
            :param y:
            :param a:
            :return:
            """
            print(a)
            print(x, y)
    
        if not PY2:
            # true keyword-only
            with pytest.raises(TypeError):
                foo(1, 2)
    
        foo(1, a=2)
        help(foo)
    
        sig_actual_call = "(x, y='hello', a)"  # if PY2 else "(x, *, y='hello', a)"
    
>       assert foo.__doc__.replace("=KW_ONLY_ARG!", "") \
               == """<This function is equivalent to 'foo%s', see original 'foo' doc below.>
    
            a `foo` function
    
            :param x:
            :param y:
            :param a:
            :return:
            """ % sig_actual_call
E       assert "<This function is equivalent to 'foo(x, y='hello', a)', see original 'foo' doc below.>\n\na `foo` function\n\n:param x:\n:param y:\n:param a:\n:return:\n" == "<This function is equivalent to 'foo(x, y='hello', a)', see original 'foo' doc below.>\n\n        a `foo` function\n\n        :param x:\n        :param y:\n        :param a:\n        :return:\n        "
E           <This function is equivalent to 'foo(x, y='hello', a)', see original 'foo' doc below.>
E           
E         -         a `foo` function
E         ? --------
E         + a `foo` function
E           
E         + :param x:
E         + :param y:
E         + :param a:
E         + :return:
E         -         :param x:
E         -         :param y:
E         -         :param a:
E         -         :return:
E         -

tests/test_partial_and_macros.py:81: AssertionError
----------------------------- Captured stdout call -----------------------------

This is with python3-3.13.0~b2-3.fc41.x86_64. Downstream bug report: https://bugzilla.redhat.com/show_bug.cgi?id=2245884. That also has replication instructions for the environment.

keszybz avatar Jun 10 '24 10:06 keszybz

And some more…

___________________________ test_create_with_partial ___________________________

    def test_create_with_partial():
        def f(b=0):
            """hey"""
            return b
    
        f.i = 1
    
        m = makefun.create_function("(b=-1)", functools.partial(f, b=2), **f.__dict__)
        assert str(signature(m)) == "(b=-1)"
        assert m() == -1
        assert m.i == 1
        # the doc remains untouched in create_function as opposed to wraps, this is normal
>       assert m.__doc__ == """partial(func, *args, **keywords) - new function with partial application
        of the given arguments and keywords.
    """
E       AssertionError: assert 'Create a new function with partial application of the given arguments\nand keywords.' == 'partial(func, *args, **keywords) - new function with partial application\n    of the given arguments and keywords.\n'
E         - partial(func, *args, **keywords) - new function with partial application
E         -     of the given arguments and keywords.
E         + Create a new function with partial application of the given arguments
E         + and keywords.

tests/test_partial_and_macros.py:130: AssertionError
___________________________ test_args_order_and_kind ___________________________

    def test_args_order_and_kind():
        """Make sure that the order remains ok"""
    
        def f(a, b, c, **d):
            return a + b + c + sum(d)
    
        # reference: functools.partial
        fp_ref = functools.partial(f, b=0)
    
        # except in python 2, all kwargs following the predefined arg become kw-only
        if sys.version_info < (3,):
            assert str(signature(fp_ref)) == "(a, b=0, c, **d)"
        else:
            assert str(signature(fp_ref)) == "(a, *, b=0, c, **d)"
    
        # our makefun.partial
        fp = makefun.partial(f, b=0)
    
        # same behaviour - except in python 2 where our "KW_ONLY_ARG!" appear
        assert str(signature(fp_ref)) == str(signature(fp)).replace("=KW_ONLY_ARG!", "")
    
        # positional-only behaviour
        if sys.version_info >= (3, 8):
            from ._test_py38 import make_pos_only_f
            f = make_pos_only_f()
    
            # it is possible to keyword-partialize a positional-only argument...
            fp_ref = functools.partial(f, b=0)
    
            # but 'signature' does not support it !
>           with pytest.raises(ValueError):
E           Failed: DID NOT RAISE <class 'ValueError'>

tests/test_partial_and_macros.py:165: Failed

keszybz avatar Jun 10 '24 10:06 keszybz

And now also on Python 3.12.4.

mweinelt avatar Jun 17 '24 10:06 mweinelt

Thank you!

mgorny avatar Jul 12 '24 12:07 mgorny