-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathdecorators.py
More file actions
126 lines (95 loc) · 4.86 KB
/
Copy pathdecorators.py
File metadata and controls
126 lines (95 loc) · 4.86 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from .testutils import VerminTest
class VerminDecoratorMemberTests(VerminTest):
def test_abstractclassmethod_of_abc(self):
self.assertOnlyIn((3, 2), self.detect("from abc import abstractclassmethod"))
def test_abstractstaticmethod_of_abc(self):
self.assertOnlyIn((3, 2), self.detect("from abc import abstractstaticmethod"))
def test_asynccontextmanager_of_contextlib(self):
self.assertOnlyIn((3, 7), self.detect("from contextlib import asynccontextmanager"))
def test_global_enum_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import global_enum"))
def test_member_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import member"))
def test_nonmember_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import nonmember"))
def test_property_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import property"))
def test_verify_of_enum(self):
self.assertOnlyIn((3, 11), self.detect("from enum import verify"))
def test_cached_property_of_functools(self):
self.assertOnlyIn((3, 8), self.detect("from functools import cached_property"))
def test_lru_cache_of_functools(self):
self.assertOnlyIn((3, 2), self.detect("from functools import lru_cache"))
def test_partial_method_of_functools(self):
self.assertOnlyIn((3, 4), self.detect("from functools import partial_method"))
def test_singledispatch_of_functools(self):
self.assertOnlyIn((3, 4), self.detect("from functools import singledispatch"))
def test_singledispatchmethod_of_functools(self):
self.assertOnlyIn((3, 8), self.detect("from functools import singledispatchmethod"))
def test_total_ordering_of_functools(self):
self.assertOnlyIn(((2, 7), (3, 2)), self.detect("from functools import total_ordering"))
def test_cache_of_functools(self):
self.assertOnlyIn((3, 9), self.detect("from functools import cache"))
# As user function.
# NOTE: It is not supported to use `functools.cache` without being a user function!
visitor = self.visit("""
from functools import cache
@cache
def foo(): pass""")
self.assertEqual(["functools.cache"], visitor.user_function_decorators())
self.assertOnlyIn((3, 9), visitor.minimum_versions())
def test_recursive_repr_of_reprlib(self):
self.assertOnlyIn((3, 2), self.detect("from reprlib import recursive_repr"))
def test_dataclass_transform_of_typing(self):
self.assertOnlyIn((3, 11), self.detect("from typing import dataclass_transform"))
def test_final_of_typing(self):
self.assertOnlyIn((3, 8), self.detect("from typing import final"))
self.assertTrue(self.config.add_backport("typing"))
self.assertOnlyIn(((2, 7), (3, 8)), self.detect("from typing import final"))
def test_runtime_checkable_of_typing(self):
self.assertOnlyIn((3, 8), self.detect("from typing import runtime_checkable"))
self.assertTrue(self.config.add_backport("typing"))
self.assertOnlyIn(((2, 7), (3, 8)), self.detect("from typing import runtime_checkable"))
def test_override_of_typing(self):
self.assertOnlyIn((3, 12), self.detect("from typing import override"))
def test_expectedFailure_of_unittest(self):
self.assertOnlyIn(((2, 7), (3, 1)), self.detect("from unittest import expectedFailure"))
def test_skip_of_unittest(self):
self.assertOnlyIn(((2, 7), (3, 1)), self.detect("from unittest import skip"))
def test_skipIf_of_unittest(self):
self.assertOnlyIn(((2, 7), (3, 1)), self.detect("from unittest import skipIf"))
def test_skipUnless_of_unittest(self):
self.assertOnlyIn(((2, 7), (3, 1)), self.detect("from unittest import skipUnless"))
def test_user_function_lru_cache_of_functools(self):
# As user function.
visitor = self.visit("""
from functools import lru_cache
@lru_cache
def foo(): pass""")
self.assertEqual(["functools.lru_cache"], visitor.user_function_decorators())
self.assertOnlyIn((3, 8), visitor.minimum_versions())
# User function as-name.
visitor = self.visit("""
from functools import lru_cache as lc
@lc
def foo(): pass""")
self.assertEqual(["functools.lru_cache"], visitor.user_function_decorators())
self.assertOnlyIn((3, 8), visitor.minimum_versions())
# User function FQN.
visitor = self.visit("""
import functools
@functools.lru_cache
def foo(): pass""")
self.assertEqual(["functools.lru_cache"], visitor.user_function_decorators())
self.assertOnlyIn((3, 8), visitor.minimum_versions())
# Not as user function.
visitor = self.visit("""
from functools import lru_cache
@lru_cache()
def foo(): pass""")
self.assertEmpty(visitor.user_function_decorators())
self.assertOnlyIn((3, 2), visitor.minimum_versions())
def test_deprecated_of_warnings(self):
self.assertOnlyIn((3, 13), self.detect("from warnings import deprecated"))
def test_disjoint_base_of_typing(self):
self.assertOnlyIn((3, 15), self.detect("from typing import disjoint_base"))