Skip to content

Commit d5ccdb4

Browse files
committed
Fix UUID tests with the pypi uuid module
This change skips tests of CSHARP_LEGACY when the third party uuid module from pypi is installed (or any other uuid module that doesn't support bytes_le).
1 parent c6b1c28 commit d5ccdb4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

test/test_binary.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
try:
2424
import uuid
2525
should_test_uuid = True
26+
uuid_has_bytes_le = hasattr(uuid.UUID, "bytes_le")
2627
except ImportError:
2728
should_test_uuid = False
29+
uuid_has_bytes_le = False
2830

2931
sys.path[0:0] = [""]
3032

@@ -41,7 +43,6 @@
4143
from test.test_client import get_client
4244
from test.utils import catch_warnings
4345

44-
4546
setUpModule = 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'

test/test_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,12 +2058,12 @@ def do_insert(args):
20582058
if have_uuid:
20592059
doc = {'_id': 2, 'uuid': uuid.uuid4()}
20602060
uuid_sub_args = (name, [doc],
2061-
True, True, {'w': 1}, True, 6)
2061+
True, True, {'w': 1}, True, 5)
20622062
do_insert(uuid_sub_args)
20632063
coll = self.db.test
20642064
self.assertNotEqual(doc, coll.find_one({'_id': 2}))
20652065
coll = self.db.get_collection('test',
2066-
CodecOptions(uuid_representation=6))
2066+
CodecOptions(uuid_representation=5))
20672067
self.assertEqual(doc, coll.find_one({'_id': 2}))
20682068

20692069
def test_message_backport_codec_options(self):

0 commit comments

Comments
 (0)