File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1474,10 +1474,15 @@ def __ne__(self, other):
14741474 return not self == other
14751475
14761476 def __repr__ (self ):
1477- if len (self .__nodes ) == 1 :
1478- return "MongoClient(%r, %r)" % self .address
1477+ nodes = self .__nodes .copy ()
1478+ if not nodes :
1479+ # We haven't connected yet.
1480+ nodes = self .__seeds .copy ()
1481+ if len (nodes ) == 1 :
1482+ address = iter (nodes ).next ()
1483+ return "MongoClient(%r, %r)" % address
14791484 else :
1480- return "MongoClient(%r)" % ["%s:%d" % n for n in self . __nodes ]
1485+ return "MongoClient(%r)" % ["%s:%d" % n for n in nodes ]
14811486
14821487 def __getattr__ (self , name ):
14831488 """Get a database by name.
Original file line number Diff line number Diff line change @@ -214,7 +214,14 @@ def test_host_w_port(self):
214214 def test_repr (self ):
215215 # Making host a str avoids the 'u' prefix in Python 2, so the repr is
216216 # the same in Python 2 and 3.
217- self .assertEqual (repr (MongoClient (str (host ), port )),
217+ c = MongoClient (str (host ), port )
218+ self .assertEqual (repr (c ),
219+ "MongoClient('%s', %d)" % (host , port ))
220+ c .close ()
221+ self .assertEqual (repr (c ),
222+ "MongoClient('%s', %d)" % (host , port ))
223+ c = MongoClient (str (host ), port , connect = False )
224+ self .assertEqual (repr (c ),
218225 "MongoClient('%s', %d)" % (host , port ))
219226
220227 def test_getters (self ):
You can’t perform that action at this time.
0 commit comments