Skip to content

Commit b40748f

Browse files
mcfunleymdirolf
authored andcommitted
Changes Connection.paired to accept kwargs that are passed on to the connection constructor. Changes the deprecation warnings to Connection.paired to match those for the Connection constructor. Adds tests for those changes.
1 parent 15ab0a9 commit b40748f

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

pymongo/connection.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ def __pair_with(self, host, port):
276276
self.__find_master()
277277

278278
@classmethod
279-
def paired(cls, left, right=None,
280-
pool_size=None, auto_start_request=None):
279+
def paired(cls, left, right=None, **connection_args):
281280
"""Open a new paired connection to Mongo.
282281
283282
Raises :class:`TypeError` if either `left` or `right` is not a tuple of
@@ -288,20 +287,21 @@ def paired(cls, left, right=None,
288287
- `left`: ``(host, port)`` pair for the left MongoDB instance
289288
- `right` (optional): ``(host, port)`` pair for the right MongoDB
290289
instance
291-
- `pool_size` (optional): DEPRECATED
292-
- `auto_start_request` (optional): DEPRECATED
290+
291+
The remaining keyword arguments are the same as those accepted by
292+
the Connection class constructor.
293293
"""
294294
if right is None:
295295
right = (cls.HOST, cls.PORT)
296-
if pool_size is not None:
297-
warnings.warn("The pool_size parameter to Connection.paired is "
298-
"deprecated", DeprecationWarning)
299-
if auto_start_request is not None:
300-
warnings.warn("The auto_start_request parameter to "
301-
"Connection.paired is deprecated",
302-
DeprecationWarning)
303296

304-
connection = cls(left[0], left[1], _connect=False)
297+
for param in ('pool_size', 'auto_start_request', 'timeout'):
298+
if param in connection_args:
299+
warnings.warn("The %s parameter to Connection.paired is "
300+
"deprecated" % param, DeprecationWarning)
301+
302+
connection_args['_connect'] = False
303+
304+
connection = cls(left[0], left[1], **connection_args)
305305
connection.__pair_with(*right)
306306
return connection
307307

test/test_paired.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import logging
2626
import os
2727
import sys
28+
import warnings
2829
sys.path[0:0] = [""]
2930

3031
from pymongo.errors import ConnectionFailure, ConfigurationError
@@ -120,6 +121,27 @@ def test_end_request(self):
120121
self.assert_(db.test.find_one())
121122
connection.end_request()
122123

124+
125+
def test_deprecation_warnings_paired_connections(self):
126+
warnings.simplefilter("error")
127+
try:
128+
self.assertRaises(DeprecationWarning, Connection.paired,
129+
self.left, self.right, timeout=3)
130+
self.assertRaises(DeprecationWarning, Connection.paired,
131+
self.left, self.right, auto_start_request=True)
132+
self.assertRaises(DeprecationWarning, Connection.paired,
133+
self.left, self.right, pool_size=20)
134+
finally:
135+
warnings.resetwarnings()
136+
warnings.simplefilter('ignore')
137+
138+
139+
def test_paired_connections_pass_individual_connargs(self):
140+
c = Connection.paired(self.left, self.right, slave_okay=True)
141+
self.assertTrue(c.__slave_okay)
142+
143+
144+
123145
if __name__ == "__main__":
124146
skip_tests = False
125147
unittest.main()

0 commit comments

Comments
 (0)