summaryrefslogtreecommitdiff
path: root/tests/run/contains_T455.pyx
blob: 8bb087acf1a09feea245546fbec4bf3ce5814161 (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# ticket: t455

def in_sequence(x, seq):
    """
    >>> in_sequence(1, [])
    False
    >>> in_sequence(1, ())
    False
    >>> in_sequence(1, {})
    False
    >>> in_sequence(1, [1])
    True
    >>> in_sequence(1, (1,))
    True
    >>> in_sequence(1, {1:None})
    True

    >>> in_sequence(1, None)    # doctest: +ELLIPSIS
    Traceback (most recent call last):
    TypeError: ...iterable...

    >>> in_sequence(1, 1)       # doctest: +ELLIPSIS
    Traceback (most recent call last):
    TypeError: ...iterable...
    """
    return x in seq

def not_in_sequence(x, seq):
    """
    >>> not_in_sequence(1, [])
    True
    >>> not_in_sequence(1, ())
    True
    >>> not_in_sequence(1, {})
    True
    >>> not_in_sequence(1, [1])
    False
    >>> not_in_sequence(1, (1,))
    False
    >>> not_in_sequence(1, {1:None})
    False

    >>> not_in_sequence(1, None)    # doctest: +ELLIPSIS
    Traceback (most recent call last):
    TypeError: ...iterable...

    >>> not_in_sequence(1, 1)       # doctest: +ELLIPSIS
    Traceback (most recent call last):
    TypeError: ...iterable...
    """
    return x not in seq


def in_dict(k, dict dct):
    """
    >>> in_dict(1, {})
    False
    >>> in_dict(1, {1:None})
    True

    >>> in_dict(1, None)
    Traceback (most recent call last):
    ...
    TypeError: 'NoneType' object is not iterable
    """
    return k in dct

def not_in_dict(k, dict dct):
    """
    >>> not_in_dict(1, {})
    True
    >>> not_in_dict(1, {1:None})
    False

    >>> not_in_dict(1, None)
    Traceback (most recent call last):
    ...
    TypeError: 'NoneType' object is not iterable
    """
    return k not in dct

def cascaded(a, b, c):
    """
    >>> cascaded(1, 2, 3)    # doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    TypeError: ...iterable...
    >>> cascaded(-1, (1,2), (1,3))
    True
    >>> cascaded(1, (1,2), (1,3))
    False
    >>> cascaded(-1, (1,2), (1,0))
    False
    """
    return a not in b < c