@@ -38,8 +38,7 @@ def get_option(self, option):
38
38
def set_option (self , option , value ):
39
39
raise NotImplementedError ()
40
40
41
- def _check_option (self , option , value , expected = SENTINEL ,
42
- nonevalue = None ):
41
+ def _check_option (self , option , value , expected = SENTINEL ):
43
42
old = self .get_option (option )
44
43
try :
45
44
self .set_option (option , value )
@@ -49,10 +48,7 @@ def _check_option(self, option, value, expected=SENTINEL,
49
48
else :
50
49
self .assertEqual (new , expected )
51
50
finally :
52
- self .set_option (
53
- option ,
54
- old if old is not None else nonevalue
55
- )
51
+ self .set_option (option , old )
56
52
self .assertEqual (self .get_option (option ), old )
57
53
58
54
def test_invalid (self ):
@@ -62,12 +58,20 @@ def test_invalid(self):
62
58
self .set_option (- 1 , '' )
63
59
64
60
def _test_timeout (self , option ):
65
- self ._check_option (option , 10.5 , nonevalue = - 1 )
66
- self ._check_option (option , 0 , nonevalue = - 1 )
61
+ self ._check_option (option , 10.5 )
62
+ self ._check_option (option , 0 )
67
63
with self .assertRaises (ValueError ):
68
- self ._check_option (option , - 5 , nonevalue = - 1 )
64
+ self ._check_option (option , - 5 )
69
65
with self .assertRaises (TypeError ):
70
66
self .set_option (option , object )
67
+ old = self .get_option (option )
68
+ try :
69
+ self .set_option (option , None )
70
+ self .assertEqual (self .get_option (option ), None )
71
+ self .set_option (option , - 1 )
72
+ self .assertEqual (self .get_option (option ), None )
73
+ finally :
74
+ self .set_option (option , old )
71
75
72
76
def test_timeout (self ):
73
77
self ._test_timeout (ldap .OPT_TIMEOUT )
@@ -149,6 +153,30 @@ def get_option(self, option):
149
153
def set_option (self , option , value ):
150
154
return self .conn .set_option (option , value )
151
155
156
+ def test_network_timeout_attribute (self ):
157
+ option = ldap .OPT_NETWORK_TIMEOUT
158
+ old = self .get_option (option )
159
+ try :
160
+ self .assertEqual (self .conn .network_timeout , old )
161
+
162
+ self .conn .network_timeout = 5
163
+ self .assertEqual (self .conn .network_timeout , 5 )
164
+ self .assertEqual (self .get_option (option ), 5 )
165
+
166
+ self .conn .network_timeout = - 1
167
+ self .assertEqual (self .conn .network_timeout , None )
168
+ self .assertEqual (self .get_option (option ), None )
169
+
170
+ self .conn .network_timeout = 10.5
171
+ self .assertEqual (self .conn .network_timeout , 10.5 )
172
+ self .assertEqual (self .get_option (option ), 10.5 )
173
+
174
+ self .conn .network_timeout = None
175
+ self .assertEqual (self .conn .network_timeout , None )
176
+ self .assertEqual (self .get_option (option ), None )
177
+ finally :
178
+ self .set_option (option , old )
179
+
152
180
# test is failing with:
153
181
# pyasn1.error.SubstrateUnderrunError: Short octet stream on tag decoding
154
182
@unittest .expectedFailure
0 commit comments