@@ -31,14 +31,14 @@ def test_bounded_type():
31
31
BoundedInt (25 )
32
32
BoundedStr = typet .Bounded [str , 1 :5 , len ]
33
33
with pytest .raises (ValueError ):
34
- BoundedStr ('' )
35
- assert BoundedStr (' abc' ) == ' abc'
34
+ BoundedStr ("" )
35
+ assert BoundedStr (" abc" ) == " abc"
36
36
with pytest .raises (ValueError ):
37
- BoundedStr (' abcdef' )
38
- assert str (BoundedInt ) == ' typet.validation.Bounded[int, 10:20]'
37
+ BoundedStr (" abcdef" )
38
+ assert str (BoundedInt ) == " typet.validation.Bounded[int, 10:20]"
39
39
assert typet .Bounded [Any , 10 :20 ](15 ) == 15
40
- assert typet .Bounded [' int' , 20 ](15 ) == 15
41
- assert typet .Bounded [' int' , 10 :](15 ) == 15
40
+ assert typet .Bounded [" int" , 20 ](15 ) == 15
41
+ assert typet .Bounded [" int" , 10 :](15 ) == 15
42
42
43
43
44
44
def test_length_type ():
@@ -49,20 +49,20 @@ def test_length_type():
49
49
LengthBoundedStr = typet .Length [str , 10 :20 , lambda x : x ]
50
50
LengthBoundedStr = typet .Length [str , 1 :5 ]
51
51
with pytest .raises (ValueError ):
52
- LengthBoundedStr ('' )
53
- assert LengthBoundedStr ('a' ) == 'a'
54
- assert LengthBoundedStr (' abcde' ) == ' abcde'
52
+ LengthBoundedStr ("" )
53
+ assert LengthBoundedStr ("a" ) == "a"
54
+ assert LengthBoundedStr (" abcde" ) == " abcde"
55
55
with pytest .raises (ValueError ):
56
- LengthBoundedStr (' abcdef' )
56
+ LengthBoundedStr (" abcdef" )
57
57
LengthBoundedList = typet .Length [list , 1 :1 ]
58
58
with pytest .raises (ValueError ):
59
59
LengthBoundedList ([])
60
60
assert LengthBoundedList ([1 ]) == [1 ]
61
61
with pytest .raises (ValueError ):
62
62
LengthBoundedList ([1 , 2 ])
63
- assert str (LengthBoundedStr ) == ' typet.validation.Length[str, 1:5]'
64
- assert typet .Length [Any , 1 :5 ](' abc' ) == ' abc'
65
- assert typet .Length [' str' , 20 ](' abc' ) == ' abc'
63
+ assert str (LengthBoundedStr ) == " typet.validation.Length[str, 1:5]"
64
+ assert typet .Length [Any , 1 :5 ](" abc" ) == " abc"
65
+ assert typet .Length [" str" , 20 ](" abc" ) == " abc"
66
66
67
67
68
68
def test_string_type ():
@@ -71,13 +71,13 @@ def test_string_type():
71
71
BoundedStr = typet .String [10 :20 , lambda x : x ]
72
72
BoundedStr = typet .String [1 :5 ]
73
73
with pytest .raises (ValueError ):
74
- BoundedStr ('' )
75
- assert BoundedStr ('a' ) == 'a'
76
- assert BoundedStr (' abcde' ) == ' abcde'
74
+ BoundedStr ("" )
75
+ assert BoundedStr ("a" ) == "a"
76
+ assert BoundedStr (" abcde" ) == " abcde"
77
77
with pytest .raises (ValueError ):
78
- BoundedStr (' abcdef' )
79
- assert str (BoundedStr ) == ' typet.validation.String[1:5]'
80
- assert typet .String (' hello' ) == ' hello'
78
+ BoundedStr (" abcdef" )
79
+ assert str (BoundedStr ) == " typet.validation.String[1:5]"
80
+ assert typet .String (" hello" ) == " hello"
81
81
82
82
83
83
def test_validation_type ():
@@ -90,16 +90,18 @@ def test_validation_type():
90
90
91
91
def test_path_types ():
92
92
"""Test that the supplied path validation paths work."""
93
- assert str (typet .File (__file__ ))== __file__
93
+ assert str (typet .File (__file__ )) == __file__
94
94
with pytest .raises (ValueError ):
95
95
typet .File (str (uuid .uuid4 ()))
96
96
assert str (typet .Dir (os .path .dirname (__file__ ))) == os .path .dirname (
97
- __file__ )
97
+ __file__
98
+ )
98
99
with pytest .raises (ValueError ):
99
100
typet .Dir (str (uuid .uuid4 ()))
100
101
assert str (typet .ExistingPath (__file__ )) == __file__
101
- assert str (typet .ExistingPath (
102
- os .path .dirname (__file__ ))) == os .path .dirname (__file__ )
102
+ assert str (
103
+ typet .ExistingPath (os .path .dirname (__file__ ))
104
+ ) == os .path .dirname (__file__ )
103
105
with pytest .raises (ValueError ):
104
106
typet .ExistingPath (str (uuid .uuid4 ()))
105
107
@@ -111,6 +113,7 @@ def test_none_type():
111
113
112
114
def test_singleton ():
113
115
"""Test that a singleton only allows a single instance of a class."""
116
+
114
117
@six .add_metaclass (typet .Singleton )
115
118
class TestClass (object ):
116
119
pass
@@ -120,6 +123,7 @@ class TestClass(object):
120
123
121
124
def test_uninstantiable ():
122
125
"""Test that an uninstantiable class cannot be instantiated."""
126
+
123
127
@six .add_metaclass (typet .Uninstantiable )
124
128
class TestClass (object ):
125
129
pass
@@ -134,47 +138,55 @@ def test_isinstance():
134
138
assert isinstance (25 , Age ) is True
135
139
assert isinstance (- 5 , Age ) is False
136
140
assert isinstance (200 , Age ) is False
137
- assert isinstance (' not an int' , Age ) is False
141
+ assert isinstance (" not an int" , Age ) is False
138
142
139
143
140
144
def test_strict_object ():
141
145
"""Simple test to verify basic StrictObject functionality."""
146
+
142
147
class X (typet .StrictObject ):
143
148
x = None # type: str
144
- x = X ('initial' )
145
- x .x = 'hello'
149
+
150
+ x = X ("initial" )
151
+ x .x = "hello"
146
152
assert is_instance (x .x , str )
147
- assert x .x == ' hello'
153
+ assert x .x == " hello"
148
154
with pytest .raises (TypeError ):
149
155
x .x = 5
150
156
151
157
152
158
def test_object ():
153
159
"""Simple test to verify basic Object functionality."""
160
+
154
161
class X (typet .Object ):
155
162
x = None # type: Optional[str]
163
+
156
164
x = X ()
157
165
x .x = 5
158
166
assert is_instance (x .x , str )
159
- assert x .x == '5'
167
+ assert x .x == "5"
160
168
161
169
162
170
def test_object_comments ():
163
171
"""Simple test to verify basic Object functionality with comment hints."""
172
+
164
173
class X (typet .Object ):
165
174
x = None # type: str
175
+
166
176
with pytest .raises (TypeError ):
167
177
X ()
168
178
x = X (5 )
169
179
assert is_instance (x .x , str )
170
- assert x .x == '5'
180
+ assert x .x == "5"
171
181
172
182
173
183
def test_object_failure ():
174
184
"""Simple test to verify basic Object failure functionality."""
185
+
175
186
class X (typet .Object ):
176
187
x = None # type: Optional[int]
188
+
177
189
x = X ()
178
190
x .x = None
179
191
with pytest .raises (TypeError ):
180
- x .x = ' not an integer'
192
+ x .x = " not an integer"
0 commit comments