Skip to content

Commit

Permalink
moving the data to a different class, hopefully this will prevent bin…
Browse files Browse the repository at this point in the history
…ary tests from running on import in test client
  • Loading branch information
sleepyStick committed Sep 25, 2024
1 parent b80ec9a commit 06f6929
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
unittest,
)
from test.asynchronous.pymongo_mocks import AsyncMockClient
from test.test_binary import TestBinary as BinaryBase
from test.test_binary import BinaryData
from test.utils import (
NTHREADS,
CMAPListener,
Expand Down Expand Up @@ -2025,7 +2025,7 @@ async def test_dict_hints_create_index(self):
await self.db.t.create_index({"x": pymongo.ASCENDING})

async def test_legacy_java_uuid_roundtrip(self):
data = BinaryBase.java_data
data = BinaryData.java_data
docs = bson.decode_all(data, CodecOptions(SON[str, Any], False, JAVA_LEGACY))

await async_client_context.client.pymongo_test.drop_collection("java_uuid")
Expand All @@ -2043,7 +2043,7 @@ async def test_legacy_java_uuid_roundtrip(self):
await async_client_context.client.pymongo_test.drop_collection("java_uuid")

async def test_legacy_csharp_uuid_roundtrip(self):
data = BinaryBase.csharp_data
data = BinaryData.csharp_data
docs = bson.decode_all(data, CodecOptions(SON[str, Any], False, CSHARP_LEGACY))

await async_client_context.client.pymongo_test.drop_collection("csharp_uuid")
Expand Down
9 changes: 5 additions & 4 deletions test/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@
from pymongo.write_concern import WriteConcern


class TestBinary(unittest.TestCase):
class BinaryData:
csharp_data: bytes
java_data: bytes

@classmethod
def setUpClass(cls):
# Generated by the Java driver
from_java = (
b"bAAAAAdfaWQAUCBQxkVm+XdxJ9tOBW5ld2d1aWQAEAAAAAMIQkfACFu"
b"Z/0RustLOU/G6Am5ld2d1aWRzdHJpbmcAJQAAAGZmOTk1YjA4LWMwND"
Expand Down Expand Up @@ -80,6 +79,8 @@ def setUpClass(cls):
)
cls.csharp_data = base64.b64decode(from_csharp)


class TestBinary(unittest.TestCase):
def test_binary(self):
a_string = "hello world"
a_binary = Binary(b"hello world")
Expand Down Expand Up @@ -158,7 +159,7 @@ def test_uuid_subtype_4(self):

def test_legacy_java_uuid(self):
# Test decoding
data = self.java_data
data = BinaryData.java_data
docs = bson.decode_all(data, CodecOptions(SON[str, Any], False, PYTHON_LEGACY))
for d in docs:
self.assertNotEqual(d["newguid"], uuid.UUID(d["newguidstring"]))
Expand Down Expand Up @@ -197,7 +198,7 @@ def test_legacy_java_uuid(self):
self.assertEqual(data, encoded)

def test_legacy_csharp_uuid(self):
data = self.csharp_data
data = BinaryData.csharp_data

# Test decoding
docs = bson.decode_all(data, CodecOptions(SON[str, Any], False, PYTHON_LEGACY))
Expand Down
6 changes: 3 additions & 3 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
unittest,
)
from test.pymongo_mocks import MockClient
from test.test_binary import TestBinary as BinaryBase
from test.test_binary import BinaryData
from test.utils import (
NTHREADS,
CMAPListener,
Expand Down Expand Up @@ -1983,7 +1983,7 @@ def test_dict_hints_create_index(self):
self.db.t.create_index({"x": pymongo.ASCENDING})

def test_legacy_java_uuid_roundtrip(self):
data = BinaryBase.java_data
data = BinaryData.java_data
docs = bson.decode_all(data, CodecOptions(SON[str, Any], False, JAVA_LEGACY))

client_context.client.pymongo_test.drop_collection("java_uuid")
Expand All @@ -2001,7 +2001,7 @@ def test_legacy_java_uuid_roundtrip(self):
client_context.client.pymongo_test.drop_collection("java_uuid")

def test_legacy_csharp_uuid_roundtrip(self):
data = BinaryBase.csharp_data
data = BinaryData.csharp_data
docs = bson.decode_all(data, CodecOptions(SON[str, Any], False, CSHARP_LEGACY))

client_context.client.pymongo_test.drop_collection("csharp_uuid")
Expand Down

0 comments on commit 06f6929

Please sign in to comment.