23
23
try :
24
24
import uuid
25
25
should_test_uuid = True
26
+ uuid_has_bytes_le = hasattr (uuid .UUID , "bytes_le" )
26
27
except ImportError :
27
28
should_test_uuid = False
29
+ uuid_has_bytes_le = False
28
30
29
31
sys .path [0 :0 ] = ["" ]
30
32
41
43
from test .test_client import get_client
42
44
from test .utils import catch_warnings
43
45
44
-
45
46
setUpModule = skip_restricted_localhost
46
47
47
48
@@ -142,9 +143,10 @@ def test_legacy_java_uuid(self):
142
143
for d in docs :
143
144
self .assertNotEqual (d ['newguid' ], uuid .UUID (d ['newguidstring' ]))
144
145
145
- docs = bson .decode_all (data , SON , False , CSHARP_LEGACY )
146
- for d in docs :
147
- self .assertNotEqual (d ['newguid' ], uuid .UUID (d ['newguidstring' ]))
146
+ if uuid_has_bytes_le :
147
+ docs = bson .decode_all (data , SON , False , CSHARP_LEGACY )
148
+ for d in docs :
149
+ self .assertNotEqual (d ['newguid' ], uuid .UUID (d ['newguidstring' ]))
148
150
149
151
docs = bson .decode_all (data , SON , False , JAVA_LEGACY )
150
152
for d in docs :
@@ -160,9 +162,10 @@ def test_legacy_java_uuid(self):
160
162
for doc in docs ])
161
163
self .assertNotEqual (data , encoded )
162
164
163
- encoded = b ('' ).join ([bson .BSON .encode (doc , uuid_subtype = CSHARP_LEGACY )
164
- for doc in docs ])
165
- self .assertNotEqual (data , encoded )
165
+ if uuid_has_bytes_le :
166
+ encoded = b ('' ).join ([bson .BSON .encode (doc , uuid_subtype = CSHARP_LEGACY )
167
+ for doc in docs ])
168
+ self .assertNotEqual (data , encoded )
166
169
167
170
encoded = b ('' ).join ([bson .BSON .encode (doc , uuid_subtype = JAVA_LEGACY )
168
171
for doc in docs ])
@@ -187,6 +190,9 @@ def test_legacy_java_uuid(self):
187
190
def test_legacy_csharp_uuid (self ):
188
191
if not should_test_uuid :
189
192
raise SkipTest ("No uuid module" )
193
+ if not uuid_has_bytes_le :
194
+ raise SkipTest (
195
+ "The uuid module from pypi doesn't support bytes_le" )
190
196
191
197
# Generated by the .net driver
192
198
from_csharp = b ('ZAAAABBfaWQAAAAAAAVuZXdndWlkABAAAAAD+MkoCd/Jy0iYJ7Vhl'
0 commit comments