generated from roboflow/template-python
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
test_internal.py
193 lines (171 loc) Β· 4.38 KB
/
test_internal.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from contextlib import ExitStack as DoesNotRaise
from dataclasses import dataclass, field
from typing import Any, Set
import numpy as np
import pytest
from supervision.detection.core import Detections
from supervision.utils.internal import get_instance_variables
class MockClass:
def __init__(self):
self.public = 0
self._protected = 1
self.__private = 2
def public_method(self):
pass
def _protected_method(self):
pass
def __private_method(self):
pass
@property
def public_property(self):
return 0
@property
def _protected_property(self):
return 1
@property
def __private_property(self):
return 2
@dataclass
class MockDataclass:
public: int = 0
_protected: int = 1
__private: int = 2
public_field: int = field(default=0)
_protected_field: int = field(default=1)
__private_field: int = field(default=2)
public_field_with_factory: dict = field(default_factory=dict)
_protected_field_with_factory: dict = field(default_factory=dict)
__private_field_with_factory: dict = field(default_factory=dict)
def public_method(self):
pass
def _protected_method(self):
pass
def __private_method(self):
pass
@property
def public_property(self):
return 0
@property
def _protected_property(self):
return 1
@property
def __private_property(self):
return 2
@pytest.mark.parametrize(
"input_instance, include_properties, expected, exception",
[
(
MockClass,
False,
None,
pytest.raises(ValueError),
),
(
MockClass(),
False,
{"public"},
DoesNotRaise(),
),
(
MockClass(),
True,
{"public", "public_property"},
DoesNotRaise(),
),
(
MockDataclass(),
False,
{"public", "public_field", "public_field_with_factory"},
DoesNotRaise(),
),
(
MockDataclass(),
True,
{"public", "public_field", "public_field_with_factory", "public_property"},
DoesNotRaise(),
),
(
Detections,
False,
None,
pytest.raises(ValueError),
),
(
Detections,
True,
None,
pytest.raises(ValueError),
),
(
Detections.empty(),
False,
{"xyxy", "class_id", "confidence", "mask", "tracker_id", "data"},
DoesNotRaise(),
),
(
Detections.empty(),
True,
{
"xyxy",
"class_id",
"confidence",
"mask",
"tracker_id",
"data",
"area",
"box_area",
},
DoesNotRaise(),
),
(
Detections(xyxy=np.array([[1, 2, 3, 4]])),
False,
{
"xyxy",
"class_id",
"confidence",
"mask",
"tracker_id",
"data",
},
DoesNotRaise(),
),
(
Detections(
xyxy=np.array([[1, 2, 3, 4], [5, 6, 7, 8]]),
class_id=np.array([1, 2]),
confidence=np.array([0.1, 0.2]),
mask=np.array([[[1]], [[2]]]),
tracker_id=np.array([1, 2]),
data={"key_1": [1, 2], "key_2": [3, 4]},
),
False,
{
"xyxy",
"class_id",
"confidence",
"mask",
"tracker_id",
"data",
},
DoesNotRaise(),
),
(
Detections.empty(),
False,
{"xyxy", "class_id", "confidence", "mask", "tracker_id", "data"},
DoesNotRaise(),
),
],
)
def test_get_instance_variables(
input_instance: Any,
include_properties: bool,
expected: Set[str],
exception: Exception,
) -> None:
with exception:
result = get_instance_variables(
input_instance, include_properties=include_properties
)
assert result == expected