Skip to content

Commit 82a2ccb

Browse files
author
Mike Dirolf
committed
selectively run CodeWScope group cmd tests based on db version
1 parent 9c59d23 commit 82a2ccb

File tree

2 files changed

+60
-15
lines changed

2 files changed

+60
-15
lines changed

test/test_collection.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import qcheck
2323
from test_connection import get_connection
24+
import version
2425
from pymongo.objectid import ObjectId
2526
from pymongo.code import Code
2627
from pymongo.binary import Binary
@@ -582,29 +583,29 @@ def test_group_with_scope(self):
582583
self.assertEqual(2, db.test.group([], {}, {"count": 0},
583584
Code(reduce_function,
584585
{"inc_value": 1}))[0]['count'])
585-
586-
587-
self.assertEqual(2, db.test.group([], {}, {"count": 0},
588-
Code(reduce_function,
589-
{"inc_value": 1}),
590-
command=True)[0]['count'])
591-
592586
self.assertEqual(4, db.test.group([], {}, {"count": 0},
593587
Code(reduce_function,
594588
{"inc_value": 2}))[0]['count'])
595-
self.assertEqual(4, db.test.group([], {}, {"count": 0},
596-
Code(reduce_function,
597-
{"inc_value": 2}),
598-
command=True)[0]['count'])
599589

600590
self.assertEqual(1, db.test.group([], {}, {"count": 0},
601591
Code(reduce_function,
602592
{"inc_value": 0.5}))[0]['count'])
603-
self.assertEqual(1, db.test.group([], {}, {"count": 0},
604-
Code(reduce_function,
605-
{"inc_value": 0.5}),
606-
command=True)[0]['count'])
607593

594+
if version.at_least(db.connection(), (1, 1)):
595+
self.assertEqual(2, db.test.group([], {}, {"count": 0},
596+
Code(reduce_function,
597+
{"inc_value": 1}),
598+
command=True)[0]['count'])
599+
600+
self.assertEqual(4, db.test.group([], {}, {"count": 0},
601+
Code(reduce_function,
602+
{"inc_value": 2}),
603+
command=True)[0]['count'])
604+
605+
self.assertEqual(1, db.test.group([], {}, {"count": 0},
606+
Code(reduce_function,
607+
{"inc_value": 0.5}),
608+
command=True)[0]['count'])
608609

609610
def test_large_limit(self):
610611
db = self.db

test/version.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2009 10gen, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Some tools for running tests based on MongoDB server version."""
16+
17+
def _padded(iter, length, padding=0):
18+
l = list(iter)
19+
if len(l) < length:
20+
for _ in range(length - len(l)):
21+
l.append(0)
22+
return l
23+
24+
def _parse_version_string(version_string):
25+
mod = 0
26+
if version_string.endswith("+"):
27+
version_string = version_string[0:-1]
28+
mod = 1
29+
elif version_string.endswith("-"):
30+
version_string = version_string[0:-1]
31+
mod = -1
32+
33+
version = [int(part) for part in version_string.split(".")]
34+
version = _padded(version, 3)
35+
version.append(mod)
36+
37+
return tuple(version)
38+
39+
# Note this is probably broken for very old versions of the database...
40+
def version(connection):
41+
return _parse_version_string(connection.server_info()["version"])
42+
43+
def at_least(connection, min_version):
44+
return version(connection) >= tuple(_padded(min_version, 4))

0 commit comments

Comments
 (0)