File: test_callback_prototypes.py

package info (click to toggle)
python-backcall 0.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 168 kB
  • sloc: python: 717; makefile: 145; sh: 8
file content (38 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
from backcall import callback_prototype

@callback_prototype
def msg_callback(a, b, c, d=None, e=None, f=None):
    pass

def test_all_args():
    @msg_callback.adapt
    def thingy1(q, w, s, d, e, f):
        return q, w, s, d, e, f
    
    assert not getattr(thingy1, '__wrapped__', None)
    assert thingy1('A', 'B', 'C', d='D', e='E', f='F') == tuple('ABCDEF')

if sys.version_info[0] >= 3:
    exec("@msg_callback.adapt\n"
         "def thingy2(t, *, d=None):\n"
         "    return t, d")
    def test_some_args_kwonly():    
        assert getattr(thingy2, '__wrapped__', None)
        assert thingy2('A', 'B', 'C', d='D', e='E', f='F') == ('A', 'D')

def test_some_args_defaults():
    @msg_callback.adapt
    def thingy2b(t, d=None):
        return t, d
    
    assert getattr(thingy2b, '__wrapped__', None)
    assert thingy2b('A', 'B', 'C', d='D', e='E', f='F') == ('A', 'D')

def test_no_args():
    @msg_callback.adapt
    def thingy3():
        return 'Success'
    
    assert getattr(thingy3, '__wrapped__', None)
    assert thingy3('A', 'B', 'C', d='D', e='E', f='F') == 'Success'