2323try :
2424 import uuid
2525 should_test_uuid = True
26+ uuid_has_bytes_le = hasattr (uuid .UUID , "bytes_le" )
2627except ImportError :
2728 should_test_uuid = False
29+ uuid_has_bytes_le = False
2830
2931sys .path [0 :0 ] = ["" ]
3032
4143from test .test_client import get_client
4244from test .utils import catch_warnings
4345
44-
4546setUpModule = skip_restricted_localhost
4647
4748
@@ -142,9 +143,10 @@ def test_legacy_java_uuid(self):
142143 for d in docs :
143144 self .assertNotEqual (d ['newguid' ], uuid .UUID (d ['newguidstring' ]))
144145
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' ]))
148150
149151 docs = bson .decode_all (data , SON , False , JAVA_LEGACY )
150152 for d in docs :
@@ -160,9 +162,10 @@ def test_legacy_java_uuid(self):
160162 for doc in docs ])
161163 self .assertNotEqual (data , encoded )
162164
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 )
166169
167170 encoded = b ('' ).join ([bson .BSON .encode (doc , uuid_subtype = JAVA_LEGACY )
168171 for doc in docs ])
@@ -187,6 +190,9 @@ def test_legacy_java_uuid(self):
187190 def test_legacy_csharp_uuid (self ):
188191 if not should_test_uuid :
189192 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" )
190196
191197 # Generated by the .net driver
192198 from_csharp = b ('ZAAAABBfaWQAAAAAAAVuZXdndWlkABAAAAAD+MkoCd/Jy0iYJ7Vhl'
0 commit comments