File: test_module_callables.py

package info (click to toggle)
sip6 6.15.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,608 kB
  • sloc: ansic: 192,441; python: 20,668; makefile: 25; cpp: 8
file content (72 lines) | stat: -rw-r--r-- 2,070 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# SPDX-License-Identifier: BSD-2-Clause

# Copyright (c) 2025 Phil Thompson <phil@riverbankcomputing.com>


import pytest


def test_module_void_ret_no_args(module):
    module.reset_module_procedure_called()
    module.module_void_ret_no_args()
    assert module.was_module_procedure_called()

def test_module_int_ret_int_arg(module):
    assert module.module_doubler(3) == 6

def test_module_int_int_ret_int_int_args(module):
    # Testing a module int(int, int, int *) function.
    res = module.module_sum_diff(3, 1)

    assert isinstance(res, tuple)
    assert len(res) == 2
    assert res[0] == 4
    assert res[1] == 2

def test_module_var_args(module):
    res = module.module_var_args(0, 1, 2)

    assert isinstance(res, tuple)
    assert len(res) == 2
    assert res[0] == 1
    assert res[1] == 2

def test_insufficient_args(module):
    with pytest.raises(TypeError):
        module.module_doubler()

def test_excessive_args(module):
    with pytest.raises(TypeError):
        module.module_doubler(1, 1)

def test_wrong_type_args(module):
    with pytest.raises(TypeError):
        module.module_doubler('1')

def test_no_kwd_args_support(module):
    with pytest.raises(TypeError):
        module.module_doubler(value=3)

def test_bad_kwd_args(module):
    with pytest.raises(TypeError):
        module.incr_optional_kwd_args(1, bad=3)

    with pytest.raises(TypeError):
        module.incr_optional_kwd_args(1, 2, incr=3)

def test_optional_kwd_args_support(module):
    assert module.incr_optional_kwd_args(1) == 2
    assert module.incr_optional_kwd_args(1, 2) == 3
    assert module.incr_optional_kwd_args(1, incr=3) == 4

def test_all_kwd_args_support(module):
    assert module.incr_all_kwd_args(1) == 2
    assert module.incr_all_kwd_args(1, 2) == 3
    assert module.incr_all_kwd_args(1, incr=3) == 4

    assert module.incr_all_kwd_args(value=1) == 2
    assert module.incr_all_kwd_args(value=1, incr=2) == 3
    assert module.incr_all_kwd_args(incr=3, value=1) == 4

    with pytest.raises(TypeError):
        module.incr_all_kwd_args(incr=3)