Allow MongoClients to be GC'ed after test runs.

Work around http://bugs.python.org/issue11798 to reduce max connection count during tests.
This commit is contained in:
A. Jesse Jiryu Davis 2013-08-27 09:00:50 -04:00
parent f47f8d69d0
commit f1f7b14bf6
17 changed files with 26 additions and 32 deletions

View File

@ -217,6 +217,7 @@ class TestAuthURIOptions(unittest.TestCase):
self.client.pymongo_test.system.users.remove()
self.client.admin.system.users.remove()
self.client.admin.logout()
self.client = None
def test_uri_options(self):
# Test default to admin
@ -289,6 +290,7 @@ class TestDelegatedAuth(unittest.TestCase):
self.client.pymongo_test2.foo.remove()
self.client.admin.system.users.remove()
self.client.admin.logout()
self.client = None
def test_delegated_auth(self):
self.client.admin.authenticate('admin', 'pass')

View File

@ -37,10 +37,6 @@ from test.test_client import get_client
class TestBinary(unittest.TestCase):
def setUp(self):
pass
def test_binary(self):
a_string = "hello world"
a_binary = Binary(b("hello world"))

View File

@ -53,10 +53,6 @@ PY3 = sys.version_info[0] == 3
class TestBSON(unittest.TestCase):
def setUp(self):
pass
def test_basic_validation(self):
self.assertRaises(TypeError, is_valid, 100)
self.assertRaises(TypeError, is_valid, u"test")

View File

@ -22,10 +22,6 @@ from bson.code import Code
class TestCode(unittest.TestCase):
def setUp(self):
pass
def test_types(self):
self.assertRaises(TypeError, Code, 5)
self.assertRaises(TypeError, Code, None)

View File

@ -40,6 +40,9 @@ class TestCursor(unittest.TestCase):
def setUp(self):
self.db = Database(get_client(), "pymongo_test")
def tearDown(self):
self.db = None
def test_explain(self):
a = self.db.test.find()
b = a.explain()

View File

@ -50,6 +50,9 @@ class TestDatabase(unittest.TestCase):
def setUp(self):
self.client = get_client()
def tearDown(self):
self.client = None
def test_name(self):
self.assertRaises(TypeError, Database, self.client, 4)
self.assertRaises(InvalidName, Database, self.client, "my db")

View File

@ -28,10 +28,6 @@ from copy import deepcopy
class TestDBRef(unittest.TestCase):
def setUp(self):
pass
def test_creation(self):
a = ObjectId()
self.assertRaises(TypeError, DBRef)

View File

@ -46,6 +46,9 @@ class TestGridFile(unittest.TestCase):
self.db.fs.files.remove({})
self.db.fs.chunks.remove({})
def tearDown(self):
self.db = None
def test_basic(self):
f = GridIn(self.db.fs, filename="test")
f.write(b("hello world"))

View File

@ -80,6 +80,9 @@ class TestGridfs(unittest.TestCase):
self.fs = gridfs.GridFS(self.db)
self.alt = gridfs.GridFS(self.db, "alt")
def tearDown(self):
self.db = self.fs = self.alt = None
def test_gridfs(self):
self.assertRaises(TypeError, gridfs.GridFS, "foo")
self.assertRaises(TypeError, gridfs.GridFS, self.db, 5)

View File

@ -48,6 +48,9 @@ class TestJsonUtil(unittest.TestCase):
self.db = get_client().pymongo_test
def tearDown(self):
self.db = None
def round_tripped(self, doc):
return json_util.loads(json_util.dumps(doc))

View File

@ -69,6 +69,7 @@ class TestMasterSlaveConnection(unittest.TestCase, TestRequestMixin):
# that make this fail
pass
self.master = self.slaves = self.db = self.client = None
super(TestMasterSlaveConnection, self).tearDown()
def test_types(self):

View File

@ -38,10 +38,6 @@ def oid(x):
class TestObjectId(unittest.TestCase):
def setUp(self):
pass
def test_creation(self):
self.assertRaises(TypeError, ObjectId, 4)
self.assertRaises(TypeError, ObjectId, 175.0)

View File

@ -337,6 +337,7 @@ class _TestPoolingBase(object):
def tearDown(self):
self.c.close()
self.c = None
if self.use_greenlets:
# Undo patch
reload(socket)

View File

@ -212,11 +212,11 @@ class TestCommandAndReadPreference(TestReplicaSetClientBase):
secondary_acceptable_latency_ms=1000*1000)
def tearDown(self):
self.c.close()
# We create a lot of collections and indexes in these tests, so drop
# the database
self._get_client().drop_database('pymongo_test')
# the database.
self.c.drop_database('pymongo_test')
self.c.close()
self.c = None
super(TestCommandAndReadPreference, self).tearDown()
def executed_on_which_member(self, client, fn, *args, **kwargs):

View File

@ -28,10 +28,6 @@ from bson.son import SON
class TestSON(unittest.TestCase):
def setUp(self):
pass
def test_ordered_dict(self):
a1 = SON()
a1["hello"] = "world"

View File

@ -35,6 +35,9 @@ class TestSONManipulator(unittest.TestCase):
def setUp(self):
self.db = Database(get_client(), "pymongo_test")
def tearDown(self):
self.db = None
def test_basic(self):
manip = SONManipulator()
collection = self.db.test

View File

@ -26,10 +26,6 @@ from bson.tz_util import utc
class TestTimestamp(unittest.TestCase):
def setUp(self):
pass
def test_timestamp(self):
t = Timestamp(123, 456)
self.assertEqual(t.time, 123)