@@ -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
5052def 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" )
0 commit comments