File: tests.py

package info (click to toggle)
legacy-api-wrap 1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 140 kB
  • sloc: python: 94; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 887 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
import warnings
from inspect import signature

import pytest

from legacy_api_wrap import legacy_api


# def old(a, b=None, d=1, c=2):
# 	pass
@legacy_api("d", "c")
def new(a, b=None, *, c=2, d=1, e=3):
    return dict(a=a, b=b, c=c, d=d, e=e)


def test_inspection_correct():
    assert str(signature(new)) == "(a, b=None, *, c=2, d=1, e=3)"


def test_new_param_available():
    new(12, e=13)


def test_old_positional_order():
    with pytest.deprecated_call():
        res = new(12, 13, 14)
    assert res["d"] == 14


def test_warning_stack():
    with pytest.deprecated_call() as record:
        new(12, 13, 14)
    w = record.pop()  # type: warnings.WarningMessage
    assert w.filename == __file__


def test_too_many_args():
    from pytest import raises

    with raises(TypeError, match=r"new\(\) takes from 1 to 4 parameters, but 5 were given\."):
        new(1, 2, 3, 4, 5)