Skip to content

Commit a8197a7

Browse files
authored
PYTHON-5308 Remove SON from doc examples (#2280)
1 parent 7ec9c07 commit a8197a7

File tree

2 files changed

+36
-52
lines changed

2 files changed

+36
-52
lines changed

test/asynchronous/test_examples.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -182,54 +182,50 @@ async def test_query_embedded_documents(self):
182182
db = self.db
183183

184184
# Start Example 14
185-
# Subdocument key order matters in a few of these examples so we have
186-
# to use bson.son.SON instead of a Python dict.
187-
from bson.son import SON
188-
189185
await db.inventory.insert_many(
190186
[
191187
{
192188
"item": "journal",
193189
"qty": 25,
194-
"size": SON([("h", 14), ("w", 21), ("uom", "cm")]),
190+
"size": {"h": 14, "w": 21, "uom": "cm"},
195191
"status": "A",
196192
},
197193
{
198194
"item": "notebook",
199195
"qty": 50,
200-
"size": SON([("h", 8.5), ("w", 11), ("uom", "in")]),
196+
"size": {"h": 8.5, "w": 11, "uom": "in"},
201197
"status": "A",
202198
},
203199
{
204200
"item": "paper",
205201
"qty": 100,
206-
"size": SON([("h", 8.5), ("w", 11), ("uom", "in")]),
202+
"size": {"h": 8.5, "w": 11, "uom": "in"},
207203
"status": "D",
208204
},
209205
{
210206
"item": "planner",
211207
"qty": 75,
212-
"size": SON([("h", 22.85), ("w", 30), ("uom", "cm")]),
208+
"size": {"h": 22.85, "w": 30, "uom": "cm"},
213209
"status": "D",
214210
},
215211
{
216212
"item": "postcard",
217213
"qty": 45,
218-
"size": SON([("h", 10), ("w", 15.25), ("uom", "cm")]),
214+
"size": {"h": 10, "w": 15.25, "uom": "cm"},
219215
"status": "A",
220216
},
221217
]
222218
)
223219
# End Example 14
224220

225221
# Start Example 15
226-
cursor = db.inventory.find({"size": SON([("h", 14), ("w", 21), ("uom", "cm")])})
222+
cursor = db.inventory.find({"size": {"h": 14, "w": 21, "uom": "cm"}})
227223
# End Example 15
228224

229225
self.assertEqual(len(await cursor.to_list()), 1)
230226

231227
# Start Example 16
232-
cursor = db.inventory.find({"size": SON([("w", 21), ("h", 14), ("uom", "cm")])})
228+
cursor = db.inventory.find({"size": {"w": 21, "h": 14, "uom": "cm"}})
233229
# End Example 16
234230

235231
self.assertEqual(len(await cursor.to_list()), 0)
@@ -324,53 +320,49 @@ async def test_query_array_of_documents(self):
324320
db = self.db
325321

326322
# Start Example 29
327-
# Subdocument key order matters in a few of these examples so we have
328-
# to use bson.son.SON instead of a Python dict.
329-
from bson.son import SON
330-
331323
await db.inventory.insert_many(
332324
[
333325
{
334326
"item": "journal",
335327
"instock": [
336-
SON([("warehouse", "A"), ("qty", 5)]),
337-
SON([("warehouse", "C"), ("qty", 15)]),
328+
{"warehouse": "A", "qty": 5},
329+
{"warehouse": "C", "qty": 15},
338330
],
339331
},
340-
{"item": "notebook", "instock": [SON([("warehouse", "C"), ("qty", 5)])]},
332+
{"item": "notebook", "instock": [{"warehouse": "C", "qty": 5}]},
341333
{
342334
"item": "paper",
343335
"instock": [
344-
SON([("warehouse", "A"), ("qty", 60)]),
345-
SON([("warehouse", "B"), ("qty", 15)]),
336+
{"warehouse": "A", "qty": 60},
337+
{"warehouse": "B", "qty": 15},
346338
],
347339
},
348340
{
349341
"item": "planner",
350342
"instock": [
351-
SON([("warehouse", "A"), ("qty", 40)]),
352-
SON([("warehouse", "B"), ("qty", 5)]),
343+
{"warehouse": "A", "qty": 40},
344+
{"warehouse": "B", "qty": 5},
353345
],
354346
},
355347
{
356348
"item": "postcard",
357349
"instock": [
358-
SON([("warehouse", "B"), ("qty", 15)]),
359-
SON([("warehouse", "C"), ("qty", 35)]),
350+
{"warehouse": "B", "qty": 15},
351+
{"warehouse": "C", "qty": 35},
360352
],
361353
},
362354
]
363355
)
364356
# End Example 29
365357

366358
# Start Example 30
367-
cursor = db.inventory.find({"instock": SON([("warehouse", "A"), ("qty", 5)])})
359+
cursor = db.inventory.find({"instock": {"warehouse": "A", "qty": 5}})
368360
# End Example 30
369361

370362
self.assertEqual(len(await cursor.to_list()), 1)
371363

372364
# Start Example 31
373-
cursor = db.inventory.find({"instock": SON([("qty", 5), ("warehouse", "A")])})
365+
cursor = db.inventory.find({"instock": {"qty": 5, "warehouse": "A"}})
374366
# End Example 31
375367

376368
self.assertEqual(len(await cursor.to_list()), 0)

test/test_examples.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -182,54 +182,50 @@ def test_query_embedded_documents(self):
182182
db = self.db
183183

184184
# Start Example 14
185-
# Subdocument key order matters in a few of these examples so we have
186-
# to use bson.son.SON instead of a Python dict.
187-
from bson.son import SON
188-
189185
db.inventory.insert_many(
190186
[
191187
{
192188
"item": "journal",
193189
"qty": 25,
194-
"size": SON([("h", 14), ("w", 21), ("uom", "cm")]),
190+
"size": {"h": 14, "w": 21, "uom": "cm"},
195191
"status": "A",
196192
},
197193
{
198194
"item": "notebook",
199195
"qty": 50,
200-
"size": SON([("h", 8.5), ("w", 11), ("uom", "in")]),
196+
"size": {"h": 8.5, "w": 11, "uom": "in"},
201197
"status": "A",
202198
},
203199
{
204200
"item": "paper",
205201
"qty": 100,
206-
"size": SON([("h", 8.5), ("w", 11), ("uom", "in")]),
202+
"size": {"h": 8.5, "w": 11, "uom": "in"},
207203
"status": "D",
208204
},
209205
{
210206
"item": "planner",
211207
"qty": 75,
212-
"size": SON([("h", 22.85), ("w", 30), ("uom", "cm")]),
208+
"size": {"h": 22.85, "w": 30, "uom": "cm"},
213209
"status": "D",
214210
},
215211
{
216212
"item": "postcard",
217213
"qty": 45,
218-
"size": SON([("h", 10), ("w", 15.25), ("uom", "cm")]),
214+
"size": {"h": 10, "w": 15.25, "uom": "cm"},
219215
"status": "A",
220216
},
221217
]
222218
)
223219
# End Example 14
224220

225221
# Start Example 15
226-
cursor = db.inventory.find({"size": SON([("h", 14), ("w", 21), ("uom", "cm")])})
222+
cursor = db.inventory.find({"size": {"h": 14, "w": 21, "uom": "cm"}})
227223
# End Example 15
228224

229225
self.assertEqual(len(cursor.to_list()), 1)
230226

231227
# Start Example 16
232-
cursor = db.inventory.find({"size": SON([("w", 21), ("h", 14), ("uom", "cm")])})
228+
cursor = db.inventory.find({"size": {"w": 21, "h": 14, "uom": "cm"}})
233229
# End Example 16
234230

235231
self.assertEqual(len(cursor.to_list()), 0)
@@ -324,53 +320,49 @@ def test_query_array_of_documents(self):
324320
db = self.db
325321

326322
# Start Example 29
327-
# Subdocument key order matters in a few of these examples so we have
328-
# to use bson.son.SON instead of a Python dict.
329-
from bson.son import SON
330-
331323
db.inventory.insert_many(
332324
[
333325
{
334326
"item": "journal",
335327
"instock": [
336-
SON([("warehouse", "A"), ("qty", 5)]),
337-
SON([("warehouse", "C"), ("qty", 15)]),
328+
{"warehouse": "A", "qty": 5},
329+
{"warehouse": "C", "qty": 15},
338330
],
339331
},
340-
{"item": "notebook", "instock": [SON([("warehouse", "C"), ("qty", 5)])]},
332+
{"item": "notebook", "instock": [{"warehouse": "C", "qty": 5}]},
341333
{
342334
"item": "paper",
343335
"instock": [
344-
SON([("warehouse", "A"), ("qty", 60)]),
345-
SON([("warehouse", "B"), ("qty", 15)]),
336+
{"warehouse": "A", "qty": 60},
337+
{"warehouse": "B", "qty": 15},
346338
],
347339
},
348340
{
349341
"item": "planner",
350342
"instock": [
351-
SON([("warehouse", "A"), ("qty", 40)]),
352-
SON([("warehouse", "B"), ("qty", 5)]),
343+
{"warehouse": "A", "qty": 40},
344+
{"warehouse": "B", "qty": 5},
353345
],
354346
},
355347
{
356348
"item": "postcard",
357349
"instock": [
358-
SON([("warehouse", "B"), ("qty", 15)]),
359-
SON([("warehouse", "C"), ("qty", 35)]),
350+
{"warehouse": "B", "qty": 15},
351+
{"warehouse": "C", "qty": 35},
360352
],
361353
},
362354
]
363355
)
364356
# End Example 29
365357

366358
# Start Example 30
367-
cursor = db.inventory.find({"instock": SON([("warehouse", "A"), ("qty", 5)])})
359+
cursor = db.inventory.find({"instock": {"warehouse": "A", "qty": 5}})
368360
# End Example 30
369361

370362
self.assertEqual(len(cursor.to_list()), 1)
371363

372364
# Start Example 31
373-
cursor = db.inventory.find({"instock": SON([("qty", 5), ("warehouse", "A")])})
365+
cursor = db.inventory.find({"instock": {"qty": 5, "warehouse": "A"}})
374366
# End Example 31
375367

376368
self.assertEqual(len(cursor.to_list()), 0)

0 commit comments

Comments
 (0)