Пример #1
0
    def test_generic_object_and_type(self) -> None:
        def f(thing: object, detector_kind: Type[SmokeDetector]):
            ''' post: True '''
            if isinstance(thing, detector_kind):
                return thing._is_plugged_in
            return False

        self.assertEqual(*check_ok(f))
Пример #2
0
 def test_simple_compare_ok(self) -> None:
     def f(i: List[int]) -> bool:
         '''
         pre: 10 < len(i)
         post: _
         '''
         return 9 < len(i[1:])
     self.assertEqual(*check_ok(f))
Пример #3
0
 def test_implicit_conversion_for_keys(self) -> None:
     def f(m: Dict[float, float], b: bool, i: int):
         '''
         post: len(m) >= len(__old__.m)
         '''
         m[b] = 2.0
         m[i] = 3.0
     self.assertEqual(*check_ok(f))
Пример #4
0
    def test_typevar_bounds_ok(self) -> None:
        B = TypeVar("B", bound=int)

        def f(x: B) -> int:
            """ post:True """
            return x + 1

        self.assertEqual(*check_ok(f))
Пример #5
0
    def test_generic_object(self) -> None:
        def f(thing: object):
            """ post: True """
            if isinstance(thing, SmokeDetector):
                return thing._is_plugged_in
            return False

        self.assertEqual(*check_ok(f))
Пример #6
0
 def TODO_test_print_ok(self) -> None:
     def f(x: int) -> bool:
         '''
         post: _ == True
         '''
         print(x)
         return True
     self.assertEqual(*check_ok(f))
Пример #7
0
    def test_proxy_alone(self) -> None:
        def f(pokeable: Pokeable) -> None:
            """
            post[pokeable]: pokeable.x > 0
            """
            pokeable.poke()

        self.assertEqual(*check_ok(f))
Пример #8
0
    def test_typevar_bounds_ok(self) -> None:
        B = TypeVar('B', bound=int)

        def f(x: B) -> int:
            ''' post:True '''
            return x + 1

        self.assertEqual(*check_ok(f))
Пример #9
0
 def test_implicit_heapref_conversions(self) -> None:
     def f(foo: List[List]) -> None:
         '''
         pre: len(foo) > 0
         post: True
         '''
         foo[0].append(42)
     self.assertEqual(*check_ok(f))
Пример #10
0
    def test_dict_basic_ok(self) -> None:
        def f(a: Dict[int, str], k: int, v: str) -> None:
            '''
            post[a]: a[k] == v
            '''
            a[k] = v

        self.assertEqual(*check_ok(f))
Пример #11
0
    def test_dict_over_objects(self) -> None:
        def f(a: Dict[object, object]) -> int:
            '''
            post: _ >= 0
            '''
            return len(a)

        self.assertEqual(*check_ok(f))
Пример #12
0
    def test_doubling_ok(self) -> None:
        def f(a: List[int]) -> List[int]:
            '''
            post: len(_) > len(a) or not a
            '''
            return a + a

        self.assertEqual(*check_ok(f))
Пример #13
0
    def test_isinstance_check(self) -> None:
        def f(uniform_tuple: Tuple[List, ...],
              basic_tuple: tuple) -> Tuple[bool, bool]:
            ''' post: _ == (True, True)'''
            return (isinstance(uniform_tuple,
                               tuple), isinstance(basic_tuple, tuple))

        self.assertEqual(*check_ok(f))
Пример #14
0
    def TODO_test_nonlinear(self) -> None:
        def make_bigger(n: float) -> float:
            '''
            post: __return__ > 1
            '''
            return (n + 333333) * (n + 333333) + 1

        self.assertEqual(*check_ok(make_bigger))
Пример #15
0
 def test_bare_type(self) -> None:
     def f(a: List) -> bool:
         '''
         pre: a
         post: _
         '''
         return bool(a)
     self.assertEqual(*check_ok(f))
Пример #16
0
 def test_new_style_type_hints(self):
     def f(l: list[int]) -> int:
         '''
         pre: len(l) == 2
         post: _[0] != 'a'
         '''
         return l
     self.assertEqual(*check_ok(f))
Пример #17
0
 def test_numbers_as_bool(self) -> None:
     def f(x: float, y: float):
         '''
         pre: math.isfinite(x) and math.isfinite(y)
         post: _ == x or _ == y
         '''
         return x or y
     self.assertEqual(*check_ok(f))
Пример #18
0
 def test_sets_eq(self) -> None:
     def f(a: Set[FrozenSet[int]]) -> object:
         '''
         pre: a == {frozenset({7}), frozenset({42})}
         post: _ in ('{frozenset({7}), frozenset({42})}', '{frozenset({42}), frozenset({7})}')
         '''
         return repr(a)
     self.assertEqual(*check_ok(f, AnalysisOptions(per_condition_timeout=5.0)))
Пример #19
0
    def test_basic_ok(self) -> None:
        def f(a: Set[int], k: int) -> None:
            '''
            post[a]: k in a
            '''
            a.add(k)

        self.assertEqual(*check_ok(f))
Пример #20
0
 def test_dict_items_ok(self) -> None:
     def f(a: Dict[int, str]) -> Iterable[Tuple[int, str]]:
         '''
         pre: len(a) < 5
         post[a]: (10,'ten') in _
         '''
         a[10] = 'ten'
         return a.items()
     self.assertEqual(*check_ok(f))
Пример #21
0
 def test_set_numeric_promotion(self) -> None:
     def f(i: int, s: Set[float]) -> bool:
         '''
         pre: i == 2
         pre: s == {2.0}
         post: _
         '''
         return i in s
     self.assertEqual(*check_ok(f))
Пример #22
0
 def test_reverse_ok(self) -> None:
     def f(l: List[int]) -> None:
         '''
         pre: len(l) == 2
         post[l]: l[0] == 42
         '''
         l.append(42)
         l.reverse()
     self.assertEqual(*check_ok(f))
Пример #23
0
 def test_dict_iter_ok(self) -> None:
     def f(a: Dict[int, str]) -> List[int]:
         '''
         pre: len(a) < 4
         post[a]: 10 in _
         '''
         a[10] = 'ten'
         return list(a.__iter__())
     self.assertEqual(*check_ok(f))
Пример #24
0
 def test_numeric_promotions(self) -> None:
     def f(b: bool, i: int) -> Tuple[int, float, float]:
         '''
         #post: 100 <= _[0] <= 101
         #post: 3.14 <= _[1] <= 4.14
         post: isinstance(_[2], float)
         '''
         return ((b + 100), (b + 3.14), (i + 3.14))
     self.assertEqual(*check_ok(f))
Пример #25
0
 def test_int_bitwise_ok(self) -> None:
     def f(a: int, b: int) -> int:
         '''
         pre: 0 <= a <= 3
         pre: 0 <= b <= 3
         post: _ <= 7
         '''
         return (a << 1) ^ b
     self.assertEqual(*check_ok(f))
Пример #26
0
 def test_promotion_compare_ok(self) -> None:
     def f(i: int, f: float) -> bool:
         '''
         pre: i == 7
         pre: f == 7.0
         post: _
         '''
         return i == f and f >= i and i >= f
     self.assertEqual(*check_ok(f))
    def test_out_of_range_byte(self) -> None:
        def f(b: bytes) -> bytes:
            """
            pre: len(b) == 1
            post: _[0] != 256
            """
            return b

        self.assertEqual(*check_ok(f))
    def test_deque_len_ok(self) -> None:
        def f(l: Deque[int]) -> Deque[int]:
            """
            post: len(_) == len(__old__.l) + 1
            """
            l.append(42)
            return l

        self.assertEqual(*check_ok(f))
Пример #29
0
    def test_fullmatch_matches_whole_string(self) -> None:
        def f(s: str) -> Optional[re.Match]:
            """
            pre: len(s) == 3
            post: implies(_, s[-1] == 'b')
            """
            return re.compile("a+b+").fullmatch(s)

        self.assertEqual(*check_ok(f))
Пример #30
0
    def test_fullmatch_basic_ok(self) -> None:
        def f(s: str) -> Optional[re.Match]:
            """
            pre: s == 'a'
            post: _
            """
            return re.compile("a").fullmatch(s)

        self.assertEqual(*check_ok(f))