Skip to content

Commit 3fb0931

Browse files
committed
Resolve new comments
Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
1 parent 1c1b300 commit 3fb0931

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ from tests.common.assertions import (
277277
assert_document_match(actual, expected, ignore_id=True)
278278

279279
# Compare lists of documents
280-
assert_documents_match(actual_list, expected_list, ignore_order=True)
280+
assert_documents_match(actual_list, expected_list, ignore_doc_order=True)
281281

282282
# Check field existence
283283
assert_field_exists(document, "user.name")

documentdb_tests/compatibility/tests/core/collections/capped_collections/test_capped_collections_create.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
import pytest
99

1010
from documentdb_tests.framework.executor import execute_command
11-
from documentdb_tests.framework.assertions import assertSuccess
11+
from documentdb_tests.framework.assertions import assertSuccessPartial
1212

1313

1414
@pytest.mark.collection_mgmt
1515
def test_create_capped_collection(collection):
1616
"""Test creating a capped collection."""
17-
db = collection.database
18-
result = execute_command(collection, {"create": "capped_test", "capped": True, "size": 100000})
19-
assertSuccess(result, {"ok": 1.0}, "Should create capped collection", raw_res=True, transform=lambda r: {"ok": r["ok"]})
20-
db.drop_collection("capped_test")
17+
result = execute_command(collection, {"create": collection.name + "_capped", "capped": True, "size": 100000})
18+
assertSuccessPartial(result, {"ok": 1.0}, "Should create capped collection")

documentdb_tests/compatibility/tests/core/operator/stages/group/test_group_stage.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ def test_group_with_count(collection):
2020
{"a": "B", "b": 80},
2121
{"a": "B", "b": 75},
2222
])
23-
result = execute_command(collection, {"aggregate": collection.name, "pipeline": [{"$group": {"_id": "$a", "count": {"$sum": 1}}}], "cursor": {}})
24-
23+
pipeline = [{"$group": {"_id": "$a", "count": {"$sum": 1}}}]
24+
result = execute_command(collection, {"aggregate": collection.name, "pipeline": pipeline, "cursor": {}})
25+
2526
expected = [
2627
{"_id": "A", "count": 2},
2728
{"_id": "B", "count": 2}
2829
]
29-
assertSuccess(result, expected, "Should group and count by department", ignore_order=True)
30+
assertSuccess(result, expected, "Should group and count by a", ignore_doc_order=True)
3031

3132

3233
@pytest.mark.aggregate
@@ -37,30 +38,32 @@ def test_group_with_sum(collection):
3738
{"a": "A", "b": 90},
3839
{"a": "B", "b": 80},
3940
])
40-
result = execute_command(collection, {"aggregate": collection.name, "pipeline": [{"$group": {"_id": "$a", "total": {"$sum": "$b"}}}], "cursor": {}})
41-
41+
pipeline = [{"$group": {"_id": "$a", "total": {"$sum": "$b"}}}]
42+
result = execute_command(collection, {"aggregate": collection.name, "pipeline": pipeline, "cursor": {}})
43+
4244
expected = [
4345
{"_id": "A", "total": 190},
4446
{"_id": "B", "total": 80}
4547
]
46-
assertSuccess(result, expected, "Should sum by group", ignore_order=True)
48+
assertSuccess(result, expected, "Should sum by group", ignore_doc_order=True)
4749

4850

4951
@pytest.mark.aggregate
5052
def test_group_with_avg(collection):
5153
"""Test $group stage with average aggregation."""
5254
collection.insert_many([
53-
{"a": "A", "b": 100},
55+
{"a": "B", "b": 100},
5456
{"a": "A", "b": 90},
5557
{"a": "B", "b": 80},
5658
])
57-
result = execute_command(collection, {"aggregate": collection.name, "pipeline": [{"$group": {"_id": "$a", "avg": {"$avg": "$b"}}}], "cursor": {}})
58-
59+
pipeline = [{"$group": {"_id": "$a", "avg": {"$avg": "$b"}}}]
60+
result = execute_command(collection, {"aggregate": collection.name, "pipeline": pipeline, "cursor": {}})
61+
5962
expected = [
6063
{"_id": "A", "avg": 95.0},
6164
{"_id": "B", "avg": 80.0}
6265
]
63-
assertSuccess(result, expected, "Should calculate average by group", ignore_order=True)
66+
assertSuccess(result, expected, "Should calculate average by group", ignore_doc_order=True)
6467

6568

6669
@pytest.mark.aggregate
@@ -71,13 +74,14 @@ def test_group_with_min_max(collection):
7174
{"a": "A", "b": 90},
7275
{"a": "B", "b": 80},
7376
])
74-
result = execute_command(collection, {"aggregate": collection.name, "pipeline": [{"$group": {"_id": "$a", "min": {"$min": "$b"}, "max": {"$max": "$b"}}}], "cursor": {}})
75-
77+
pipeline = [{"$group": {"_id": "$a", "min": {"$min": "$b"}, "max": {"$max": "$b"}}}]
78+
result = execute_command(collection, {"aggregate": collection.name, "pipeline": pipeline, "cursor": {}})
79+
7680
expected = [
7781
{"_id": "A", "min": 90, "max": 100},
7882
{"_id": "B", "min": 80, "max": 80}
7983
]
80-
assertSuccess(result, expected, "Should find min and max by group", ignore_order=True)
84+
assertSuccess(result, expected, "Should find min and max by group", ignore_doc_order=True)
8185

8286

8387
@pytest.mark.aggregate
@@ -88,7 +92,8 @@ def test_group_all_documents(collection):
8892
{"a": "B", "b": 10},
8993
{"a": "A", "b": 3},
9094
])
91-
result = execute_command(collection, {"aggregate": collection.name, "pipeline": [{"$group": {"_id": None, "total": {"$sum": "$b"}}}], "cursor": {}})
92-
95+
pipeline = [{"$group": {"_id": None, "total": {"$sum": "$b"}}}]
96+
result = execute_command(collection, {"aggregate": collection.name, "pipeline": pipeline, "cursor": {}})
97+
9398
expected = [{"_id": None, "total": 18}]
9499
assertSuccess(result, expected, "Should sum across all documents")

documentdb_tests/compatibility/tests/core/operator/stages/match/test_match_stage.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ def test_match_multiple_conditions(collection):
5151
collection.insert_many([
5252
{"_id": 0, "a": "A", "b": 30, "c": "NYC"},
5353
{"_id": 1, "a": "B", "b": 25, "c": "SF"},
54-
{"_id": 2, "a": "C", "b": 35, "c": "NYC"},
54+
{"_id": 2, "a": "C", "b": 35, "c": "SF"},
5555
])
5656
result = execute_command(collection, {"aggregate": collection.name, "pipeline": [{"$match": {"c": "NYC", "b": {"$gte": 30}}}], "cursor": {}})
5757

5858
expected = [
59-
{"_id": 0, "a": "A", "b": 30, "c": "NYC"},
60-
{"_id": 2, "a": "C", "b": 35, "c": "NYC"}
59+
{"_id": 0, "a": "A", "b": 30, "c": "NYC"}
6160
]
6261
assertSuccess(result, expected, "Should match multiple conditions")
6362

documentdb_tests/framework/assertions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _format_exception_error(result: Exception) -> str:
2222
return f"[UNEXPECTED_ERROR] Expected success but got exception:\n{pprint.pformat({'code': code, 'msg': msg}, width=100)}\n"
2323

2424

25-
def assertSuccess(result: Union[Any, Exception], expected: Any, msg: str = None, raw_res: bool = False, transform: Optional[Callable] = None, ignore_order: bool = False):
25+
def assertSuccess(result: Union[Any, Exception], expected: Any, msg: str = None, raw_res: bool = False, transform: Optional[Callable] = None, ignore_doc_order: bool = False):
2626
"""
2727
Assert command succeeded and optionally check result.
2828
@@ -32,7 +32,7 @@ def assertSuccess(result: Union[Any, Exception], expected: Any, msg: str = None,
3232
msg: Custom assertion message (optional)
3333
raw_res: If asserting raw result. False by default, only compare content of ["cursor"]["firstBatch"]
3434
transform: Optional callback to transform result before comparison
35-
ignore_order: If True, compare lists as sets (order-independent)
35+
ignore_doc_order: If True, compare lists as sets (order-independent)
3636
"""
3737
if isinstance(result, Exception):
3838
if isinstance(result, _INFRA_TYPES):
@@ -51,7 +51,7 @@ def assertSuccess(result: Union[Any, Exception], expected: Any, msg: str = None,
5151
error_text += f"\n\nExpected:\n{pprint.pformat(expected, width=100)}"
5252
error_text += f"\n\nActual:\n{pprint.pformat(result, width=100)}\n"
5353

54-
if ignore_order and isinstance(result, list) and isinstance(expected, list):
54+
if ignore_doc_order and isinstance(result, list) and isinstance(expected, list):
5555
assert sorted(result, key=lambda x: str(x)) == sorted(expected, key=lambda x: str(x)), error_text
5656
else:
5757
assert result == expected, error_text

0 commit comments

Comments
 (0)