PYTHON-928 - Fix tests around client __repr__ to expect original seed list instead of discovered nodes.
This commit is contained in:
parent
5f14e1b9bf
commit
43683041fe
@ -780,7 +780,7 @@ class MongoClient(common.BaseObject):
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __repr__(self):
|
||||
def _repr_helper(self):
|
||||
def option_repr(option, value):
|
||||
"""Fix options whose __repr__ isn't usable in a constructor."""
|
||||
if option == 'document_class':
|
||||
@ -804,7 +804,10 @@ class MongoClient(common.BaseObject):
|
||||
option_repr(key, self.__options._options[key])
|
||||
for key in self.__options._options
|
||||
if key not in set(self._constructor_args))
|
||||
return ("MongoClient(%s)" % ', '.join(options))
|
||||
return ', '.join(options)
|
||||
|
||||
def __repr__(self):
|
||||
return ("MongoClient(%s)" % (self._repr_helper(),))
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""Get a database by name.
|
||||
|
||||
@ -45,6 +45,4 @@ class MongoReplicaSetClient(mongo_client.MongoClient):
|
||||
super(MongoReplicaSetClient, self).__init__(*args, **kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
sds = self._topology.description.server_descriptions()
|
||||
return "MongoReplicaSetClient(%r)" % (["%s:%d" % s.address
|
||||
for s in sds.values()],)
|
||||
return "MongoReplicaSetClient(%s)" % (self._repr_helper(),)
|
||||
|
||||
@ -258,8 +258,8 @@ class TestClient(IntegrationTest):
|
||||
connect=False, document_class=SON)
|
||||
|
||||
the_repr = repr(client)
|
||||
self.assertIn('MongoClient(host=', the_repr)
|
||||
self.assertIn(
|
||||
"MongoClient(host=['localhost:27017', 'localhost:27018'], "
|
||||
"document_class=bson.son.SON, "
|
||||
"tz_aware=False, "
|
||||
"connect=False, ",
|
||||
@ -271,10 +271,8 @@ class TestClient(IntegrationTest):
|
||||
|
||||
@client_context.require_replica_set
|
||||
def test_repr_replica_set(self):
|
||||
# Like MongoClient(["localhost:27017", "localhost:27018"]).
|
||||
self.assertIn("MongoClient([", repr(self.client))
|
||||
for node in client_context.nodes:
|
||||
self.assertIn("%s:%d" % node, repr(self.client))
|
||||
self.assertIn("MongoClient(host=[", repr(self.client))
|
||||
self.assertIn(pair, repr(self.client))
|
||||
|
||||
def test_getters(self):
|
||||
self.assertEqual(client_context.client.address, (host, port))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user