-
Notifications
You must be signed in to change notification settings - Fork 575
/
test_compat.py
70 lines (52 loc) · 1.59 KB
/
test_compat.py
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
# This file is part of Hypothesis, which may be found at
# https://github.com/HypothesisWorks/hypothesis/
#
# Copyright the Hypothesis Authors.
# Individual contributors are listed in AUTHORS.rst and the git log.
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.
import math
from dataclasses import dataclass
from inspect import Parameter, Signature, signature
from typing import ForwardRef
import pytest
from hypothesis.internal.compat import ceil, floor, get_type_hints
floor_ceil_values = [
-10.7,
-10.3,
-0.5,
-0.0,
0,
0.5,
10.3,
10.7,
]
@pytest.mark.parametrize("value", floor_ceil_values)
def test_our_floor_agrees_with_math_floor(value):
assert floor(value) == math.floor(value)
@pytest.mark.parametrize("value", floor_ceil_values)
def test_our_ceil_agrees_with_math_ceil(value):
assert ceil(value) == math.ceil(value)
class WeirdSig:
__signature__ = Signature(
parameters=[Parameter(name="args", kind=Parameter.VAR_POSITIONAL)]
)
def test_no_type_hints():
assert get_type_hints(WeirdSig) == {}
@dataclass
class Foo:
x: "Foo"
Foo.__signature__ = signature(Foo).replace( # type: ignore
parameters=[
Parameter(
"x",
Parameter.POSITIONAL_OR_KEYWORD,
annotation=ForwardRef("Foo"),
)
]
)
def test_resolve_fwd_refs():
# See: https://github.com/HypothesisWorks/hypothesis/issues/3519
assert get_type_hints(Foo)["x"] is Foo