Skip to content

Commit 4368304

Browse files
author
Luke Lovett
committed
PYTHON-928 - Fix tests around client __repr__ to expect original seed list instead of discovered nodes.
1 parent 5f14e1b commit 4368304

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

pymongo/mongo_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ def __eq__(self, other):
780780
def __ne__(self, other):
781781
return not self == other
782782

783-
def __repr__(self):
783+
def _repr_helper(self):
784784
def option_repr(option, value):
785785
"""Fix options whose __repr__ isn't usable in a constructor."""
786786
if option == 'document_class':
@@ -804,7 +804,10 @@ def option_repr(option, value):
804804
option_repr(key, self.__options._options[key])
805805
for key in self.__options._options
806806
if key not in set(self._constructor_args))
807-
return ("MongoClient(%s)" % ', '.join(options))
807+
return ', '.join(options)
808+
809+
def __repr__(self):
810+
return ("MongoClient(%s)" % (self._repr_helper(),))
808811

809812
def __getattr__(self, name):
810813
"""Get a database by name.

pymongo/mongo_replica_set_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,4 @@ def __init__(self, *args, **kwargs):
4545
super(MongoReplicaSetClient, self).__init__(*args, **kwargs)
4646

4747
def __repr__(self):
48-
sds = self._topology.description.server_descriptions()
49-
return "MongoReplicaSetClient(%r)" % (["%s:%d" % s.address
50-
for s in sds.values()],)
48+
return "MongoReplicaSetClient(%s)" % (self._repr_helper(),)

test/test_client.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ def test_repr(self):
258258
connect=False, document_class=SON)
259259

260260
the_repr = repr(client)
261+
self.assertIn('MongoClient(host=', the_repr)
261262
self.assertIn(
262-
"MongoClient(host=['localhost:27017', 'localhost:27018'], "
263263
"document_class=bson.son.SON, "
264264
"tz_aware=False, "
265265
"connect=False, ",
@@ -271,10 +271,8 @@ def test_repr(self):
271271

272272
@client_context.require_replica_set
273273
def test_repr_replica_set(self):
274-
# Like MongoClient(["localhost:27017", "localhost:27018"]).
275-
self.assertIn("MongoClient([", repr(self.client))
276-
for node in client_context.nodes:
277-
self.assertIn("%s:%d" % node, repr(self.client))
274+
self.assertIn("MongoClient(host=[", repr(self.client))
275+
self.assertIn(pair, repr(self.client))
278276

279277
def test_getters(self):
280278
self.assertEqual(client_context.client.address, (host, port))

0 commit comments

Comments
 (0)