python 2.3 support

mostly not using unittest.assertTrue and assertFalse.
also not using decorator syntax, and some missing built-ins (sorted, etc.)
This commit is contained in:
Mike Dirolf 2009-02-20 14:35:21 -05:00
parent 75fb46a732
commit 7bbb4a5133
19 changed files with 135 additions and 119 deletions

View File

@ -110,13 +110,13 @@ class GridFile(object):
self.__collection.chunks.remove({"files_id": self.__id})
@property
def closed(self):
return self.__closed
closed = property(closed)
@property
def mode(self):
return self.__mode
mode = property(mode)
def __create_property(field_name, read_only=False):
def getter(self):

View File

@ -408,7 +408,6 @@ class BSON(str):
"""
return str.__new__(cls, bson)
@classmethod
def from_dict(cls, dict):
"""Create a new BSON object from a python mapping type (like dict).
@ -420,6 +419,7 @@ class BSON(str):
- `dict`: mapping type representing a Mongo document
"""
return cls(_dict_to_bson(dict))
from_dict = classmethod(from_dict)
def to_dict(self):
"""Get the dictionary representation of this data."""

View File

@ -14,10 +14,10 @@
"""Low level connection to Mongo."""
import sys
import socket
import struct
import types
import traceback
import logging
import threading
import random
@ -116,7 +116,6 @@ class Connection(object):
self.__find_master()
@classmethod
def paired(cls, left, right=("localhost", 27017),
pool_size=1, auto_start_request=True):
"""Open a new paired connection to Mongo.
@ -134,6 +133,7 @@ class Connection(object):
_connect=False)
connection.__pair_with(*right)
return connection
paired = classmethod(paired)
def __increment_id(self):
self.__id_lock.acquire()
@ -152,7 +152,7 @@ class Connection(object):
if result["ismaster"] == 1:
return True
else:
strings = result["remote"].rsplit(":", 1)
strings = result["remote"].split(":", 1)
if len(strings) == 1:
port = 27017
else:
@ -197,8 +197,9 @@ class Connection(object):
((host, port), master))
_logger.debug("not master, master is (%r, %r)" % master)
except socket.error:
_logger.debug("could not connect, got: %s" %
traceback.format_exc())
exctype, value = sys.exc_info()[:2]
_logger.debug("could not connect, got: %s %s" %
(exctype, value))
continue
finally:
sock.close()
@ -273,8 +274,8 @@ class Connection(object):
"""
choices = range(self.__pool_size)
random.shuffle(choices)
choices = sorted(choices, lambda x, y: cmp(self.__thread_count[x],
self.__thread_count[y]))
choices.sort(lambda x, y: cmp(self.__thread_count[x],
self.__thread_count[y]))
for choice in choices:
if self.__locks[choice].acquire(False):

View File

@ -72,7 +72,6 @@ class ObjectId(object):
"""
return self.__id.encode("hex")
@classmethod
def url_decode(cls, encoded_oid):
"""Create an ObjectId from an encoded hex string.
@ -83,6 +82,7 @@ class ObjectId(object):
by `url_encode()`)
"""
return cls(encoded_oid.decode("hex"))
url_decode = classmethod(url_decode)
def __str__(self):
return self.__id

View File

@ -191,7 +191,6 @@ class SON(dict):
def __len__(self):
return len(self.keys())
@classmethod
def from_xml(cls, xml):
"""Create an instance of SON from an xml document.
"""
@ -215,7 +214,7 @@ class SON(dict):
return code.text is not None and Code(code.text) or Code("")
def make_binary(binary):
return binary.text is not None and Binary(base64.b64decode(binary.text)) or Binary("")
return binary.text is not None and Binary(base64.decodestring(binary.text)) or Binary("")
def make_boolean(bool):
return bool.text == "true"
@ -291,3 +290,4 @@ class SON(dict):
doc = tree[1]
return make_doc(doc)
from_xml = classmethod(from_xml)

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python
import sys
try:
from setuptools import setup
except ImportError:
@ -31,16 +33,27 @@ class custom_build_ext(build_ext):
The C extension speeds up BSON encoding, but is not essential.
"""
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except CCompilerError:
print ""
print ("*" * 62)
print """WARNING: The %s extension module could not
if sys.version_info[:3] >= (2, 4, 0):
try:
build_ext.build_extension(self, ext)
except CCompilerError:
print ""
print ("*" * 62)
print """WARNING: The %s extension module could not
be compiled. No C extensions are essential for PyMongo to run,
although they do result in significant speed improvements.
Above is the ouput showing how the compilation failed.""" % ext.name
print ("*" * 62 + "\n")
else:
print ""
print ("*" * 62)
print """WARNING: The %s extension module is not supported
for this version of Python. No C extensions are essential
for PyMongo to run, although they do result in significant
speed improvements.
Please use Python >= 2.4 to take advantage of the extension.""" % ext.name
print ("*" * 62 + "\n")
setup(

View File

@ -27,10 +27,10 @@ class TestBinary(unittest.TestCase):
def test_binary(self):
a_string = "hello world"
a_binary = Binary("hello world")
self.assertTrue(a_binary.startswith("hello"))
self.assertTrue(a_binary.endswith("world"))
self.assertTrue(isinstance(a_binary, Binary))
self.assertFalse(isinstance(a_string, Binary))
self.assert_(a_binary.startswith("hello"))
self.assert_(a_binary.endswith("world"))
self.assert_(isinstance(a_binary, Binary))
self.failIf(isinstance(a_string, Binary))
def test_exceptions(self):
self.assertRaises(TypeError, Binary, None)
@ -41,8 +41,8 @@ class TestBinary(unittest.TestCase):
self.assertRaises(TypeError, Binary, "hello", "100")
self.assertRaises(ValueError, Binary, "hello", -1)
self.assertRaises(ValueError, Binary, "hello", 256)
self.assertTrue(Binary("hello", 0))
self.assertTrue(Binary("hello", 255))
self.assert_(Binary("hello", 0))
self.assert_(Binary("hello", 255))
def test_subtype(self):
b = Binary("hello")

View File

@ -41,15 +41,15 @@ class TestBSON(unittest.TestCase):
self.assertRaises(TypeError, is_valid, u"test")
self.assertRaises(TypeError, is_valid, 10.4)
self.assertFalse(is_valid("test"))
self.failIf(is_valid("test"))
# the simplest valid BSON document
self.assertTrue(is_valid("\x05\x00\x00\x00\x00"))
self.assertTrue(is_valid(BSON("\x05\x00\x00\x00\x00")))
self.assertFalse(is_valid("\x04\x00\x00\x00\x00"))
self.assertFalse(is_valid("\x05\x00\x00\x00\x01"))
self.assertFalse(is_valid("\x05\x00\x00\x00"))
self.assertFalse(is_valid("\x05\x00\x00\x00\x00\x00"))
self.assert_(is_valid("\x05\x00\x00\x00\x00"))
self.assert_(is_valid(BSON("\x05\x00\x00\x00\x00")))
self.failIf(is_valid("\x04\x00\x00\x00\x00"))
self.failIf(is_valid("\x05\x00\x00\x00\x01"))
self.failIf(is_valid("\x05\x00\x00\x00"))
self.failIf(is_valid("\x05\x00\x00\x00\x00\x00"))
def test_random_data_is_not_bson(self):
qcheck.check_unittest(self, qcheck.isnt(is_valid), qcheck.gen_string(qcheck.gen_range(0, 40)))
@ -104,7 +104,7 @@ class TestBSON(unittest.TestCase):
self.assertEqual(dict, (BSON.from_dict(dict)).to_dict())
helper({})
helper({"test": u"hello"})
self.assertTrue(isinstance(BSON.from_dict({"hello": "world"}).to_dict()["hello"],
self.assert_(isinstance(BSON.from_dict({"hello": "world"}).to_dict()["hello"],
types.UnicodeType))
helper({"mike": -10120})
helper({"long": long(10)})

View File

@ -27,10 +27,10 @@ class TestCode(unittest.TestCase):
def test_code(self):
a_string = "hello world"
a_code = Code("hello world")
self.assertTrue(a_code.startswith("hello"))
self.assertTrue(a_code.endswith("world"))
self.assertTrue(isinstance(a_code, Code))
self.assertFalse(isinstance(a_string, Code))
self.assert_(a_code.startswith("hello"))
self.assert_(a_code.endswith("world"))
self.assert_(isinstance(a_code, Code))
self.failIf(isinstance(a_string, Code))
def test_repr(self):
c = Code("hello world")

View File

@ -48,7 +48,7 @@ class TestCollection(unittest.TestCase):
self.assertRaises(InvalidName, make_col, self.db.test, "test.")
self.assertRaises(InvalidName, make_col, self.db.test, "tes..t")
self.assertTrue(isinstance(self.db.test, Collection))
self.assert_(isinstance(self.db.test, Collection))
self.assertEqual(self.db.test, self.db["test"])
self.assertEqual(self.db.test, Collection(self.db, "test"))
self.assertEqual(self.db.test.mike, self.db["test.mike"])
@ -65,7 +65,7 @@ class TestCollection(unittest.TestCase):
self.assertRaises(TypeError, db.test.create_index, "hello", "world")
db.test.drop_indexes()
self.assertFalse(db.system.indexes.find_one({"ns": u"pymongo_test.test"}))
self.failIf(db.system.indexes.find_one({"ns": u"pymongo_test.test"}))
db.test.create_index("hello", ASCENDING)
db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)])
@ -76,7 +76,7 @@ class TestCollection(unittest.TestCase):
self.assertEqual(count, 2)
db.test.drop_indexes()
self.assertFalse(db.system.indexes.find_one({"ns": u"pymongo_test.test"}))
self.failIf(db.system.indexes.find_one({"ns": u"pymongo_test.test"}))
db.test.create_index("hello", ASCENDING)
self.assertEqual(db.system.indexes.find_one({"ns": u"pymongo_test.test"}),
SON([(u"name", u"hello_1"),
@ -84,7 +84,7 @@ class TestCollection(unittest.TestCase):
(u"key", SON([(u"hello", 1)]))]))
db.test.drop_indexes()
self.assertFalse(db.system.indexes.find_one({"ns": u"pymongo_test.test"}))
self.failIf(db.system.indexes.find_one({"ns": u"pymongo_test.test"}))
db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)])
self.assertEqual(db.system.indexes.find_one({"ns": u"pymongo_test.test"}),
SON([(u"name", u"hello_-1_world_1"),
@ -145,9 +145,9 @@ class TestCollection(unittest.TestCase):
db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)])
self.assertEqual(db.test.index_information()["hello_1"], [("hello", ASCENDING)])
self.assertEqual(len(db.test.index_information()), 2)
self.assertTrue(("hello", DESCENDING) in db.test.index_information()["hello_-1_world_1"])
self.assertTrue(("world", ASCENDING) in db.test.index_information()["hello_-1_world_1"])
self.assertTrue(len(db.test.index_information()["hello_-1_world_1"]) == 2)
self.assert_(("hello", DESCENDING) in db.test.index_information()["hello_-1_world_1"])
self.assert_(("world", ASCENDING) in db.test.index_information()["hello_-1_world_1"])
self.assert_(len(db.test.index_information()["hello_-1_world_1"]) == 2)
def test_options(self):
db = self.db
@ -184,15 +184,15 @@ class TestCollection(unittest.TestCase):
db.test.insert({"x": 1, "mike": "awesome", "extra thing": "abcdefghijklmnopqrstuvwxyz"})
self.assertEqual(1, db.test.count())
self.assertTrue("x" in db.test.find({}).next())
self.assertTrue("mike" in db.test.find({}).next())
self.assertTrue("extra thing" in db.test.find({}).next())
self.assertTrue("x" in db.test.find({}, ["x", "mike"]).next())
self.assertTrue("mike" in db.test.find({}, ["x", "mike"]).next())
self.assertFalse("extra thing" in db.test.find({}, ["x", "mike"]).next())
self.assertFalse("x" in db.test.find({}, ["mike"]).next())
self.assertTrue("mike" in db.test.find({}, ["mike"]).next())
self.assertFalse("extra thing" in db.test.find({}, ["mike"]).next())
self.assert_("x" in db.test.find({}).next())
self.assert_("mike" in db.test.find({}).next())
self.assert_("extra thing" in db.test.find({}).next())
self.assert_("x" in db.test.find({}, ["x", "mike"]).next())
self.assert_("mike" in db.test.find({}, ["x", "mike"]).next())
self.failIf("extra thing" in db.test.find({}, ["x", "mike"]).next())
self.failIf("x" in db.test.find({}, ["mike"]).next())
self.assert_("mike" in db.test.find({}, ["mike"]).next())
self.failIf("extra thing" in db.test.find({}, ["mike"]).next())
def test_find_w_regex(self):
db = self.db
@ -215,7 +215,7 @@ class TestCollection(unittest.TestCase):
db.test.remove({})
auto_id = {"hello": "world"}
db.test.insert(auto_id)
self.assertTrue(isinstance(auto_id["_id"], ObjectId))
self.assert_(isinstance(auto_id["_id"], ObjectId))
numeric = {"_id": 240, "hello": "world"}
db.test.insert(numeric)
@ -227,7 +227,7 @@ class TestCollection(unittest.TestCase):
for x in db.test.find():
self.assertEqual(x["hello"], u"world")
self.assertTrue("_id" in x)
self.assert_("_id" in x)
def test_iteration(self):
db = self.db

View File

@ -47,7 +47,7 @@ class TestConnection(unittest.TestCase):
self.assertRaises(ConnectionFailure, Connection, "somedomainthatdoesntexist.org")
self.assertRaises(ConnectionFailure, Connection, self.host, 123456789)
self.assertTrue(Connection(self.host, self.port))
self.assert_(Connection(self.host, self.port))
def test_repr(self):
self.assertEqual(repr(Connection(self.host, self.port)),
@ -69,7 +69,7 @@ class TestConnection(unittest.TestCase):
self.assertRaises(InvalidName, make_db, connection, "te/t")
self.assertRaises(InvalidName, make_db, connection, "te st")
self.assertTrue(isinstance(connection.test, Database))
self.assert_(isinstance(connection.test, Database))
self.assertEqual(connection.test, connection["test"])
self.assertEqual(connection.test, Database(connection, "test"))
@ -80,8 +80,8 @@ class TestConnection(unittest.TestCase):
connection.pymongo_test_mike.test.save({"dummy": u"object"})
dbs = connection.database_names()
self.assertTrue("pymongo_test" in dbs)
self.assertTrue("pymongo_test_mike" in dbs)
self.assert_("pymongo_test" in dbs)
self.assert_("pymongo_test_mike" in dbs)
def test_drop_database(self):
connection = Connection(self.host, self.port)
@ -91,17 +91,17 @@ class TestConnection(unittest.TestCase):
connection.pymongo_test.test.save({"dummy": u"object"})
dbs = connection.database_names()
self.assertTrue("pymongo_test" in dbs)
self.assert_("pymongo_test" in dbs)
connection.drop_database("pymongo_test")
dbs = connection.database_names()
self.assertTrue("pymongo_test" not in dbs)
self.assert_("pymongo_test" not in dbs)
connection.pymongo_test.test.save({"dummy": u"object"})
dbs = connection.database_names()
self.assertTrue("pymongo_test" in dbs)
self.assert_("pymongo_test" in dbs)
connection.drop_database(connection.pymongo_test)
dbs = connection.database_names()
self.assertTrue("pymongo_test" not in dbs)
self.assert_("pymongo_test" not in dbs)
def test_iteration(self):
connection = Connection(self.host, self.port)

View File

@ -38,7 +38,7 @@ class TestCursor(unittest.TestCase):
del b["millis"]
del c["millis"]
self.assertEqual(b, c)
self.assertTrue("cursor" in b)
self.assert_("cursor" in b)
def test_hint(self):
db = self.db
@ -230,7 +230,7 @@ class TestCursor(unittest.TestCase):
db.test.save({"x": i})
self.assertEqual(10, db.test.find().count())
self.assertTrue(isinstance(db.test.find().count(), types.IntType))
self.assert_(isinstance(db.test.find().count(), types.IntType))
self.assertEqual(10, db.test.find().limit(5).count())
self.assertEqual(10, db.test.find().skip(5).count())

View File

@ -71,11 +71,11 @@ class TestDatabase(unittest.TestCase):
test = db.create_collection("test")
test.save({"hello": u"world"})
self.assertEqual(db.test.find_one()["hello"], "world")
self.assertTrue(u"test" in db.collection_names())
self.assert_(u"test" in db.collection_names())
db.drop_collection("test.foo")
db.create_collection("test.foo")
self.assertTrue(u"test.foo" in db.collection_names())
self.assert_(u"test.foo" in db.collection_names())
self.assertEqual(db.test.foo.options(), {})
self.assertRaises(CollectionInvalid, db.create_collection, "test.foo")
@ -85,10 +85,10 @@ class TestDatabase(unittest.TestCase):
db.test.mike.save({"dummy": u"object"})
colls = db.collection_names()
self.assertTrue("test" in colls)
self.assertTrue("test.mike" in colls)
self.assert_("test" in colls)
self.assert_("test.mike" in colls)
for coll in colls:
self.assertTrue("$" not in coll)
self.assert_("$" not in coll)
def test_drop_collection(self):
db = Database(self.connection, "pymongo_test")
@ -97,19 +97,19 @@ class TestDatabase(unittest.TestCase):
self.assertRaises(TypeError, db.drop_collection, None)
db.test.save({"dummy": u"object"})
self.assertTrue("test" in db.collection_names())
self.assert_("test" in db.collection_names())
db.drop_collection("test")
self.assertFalse("test" in db.collection_names())
self.failIf("test" in db.collection_names())
db.test.save({"dummy": u"object"})
self.assertTrue("test" in db.collection_names())
self.assert_("test" in db.collection_names())
db.drop_collection(u"test")
self.assertFalse("test" in db.collection_names())
self.failIf("test" in db.collection_names())
db.test.save({"dummy": u"object"})
self.assertTrue("test" in db.collection_names())
self.assert_("test" in db.collection_names())
db.drop_collection(db.test)
self.assertFalse("test" in db.collection_names())
self.failIf("test" in db.collection_names())
db.drop_collection(db.test.doesnotexist)
@ -124,8 +124,8 @@ class TestDatabase(unittest.TestCase):
self.assertRaises(OperationFailure, db.validate_collection, "test.doesnotexist")
self.assertRaises(OperationFailure, db.validate_collection, db.test.doesnotexist)
self.assertTrue(db.validate_collection("test"))
self.assertTrue(db.validate_collection(db.test))
self.assert_(db.validate_collection("test"))
self.assert_(db.validate_collection(db.test))
def test_profiling_levels(self):
db = self.connection.pymongo_test
@ -152,11 +152,11 @@ class TestDatabase(unittest.TestCase):
db.set_profiling_level(OFF)
info = db.profiling_info()
self.assertTrue(isinstance(info, types.ListType))
self.assertTrue(len(info) >= 1)
self.assertTrue(isinstance(info[0]["info"], types.StringTypes))
self.assertTrue(isinstance(info[0]["ts"], datetime.datetime))
self.assertTrue(isinstance(info[0]["millis"], types.FloatType))
self.assert_(isinstance(info, types.ListType))
self.assert_(len(info) >= 1)
self.assert_(isinstance(info[0]["info"], types.StringTypes))
self.assert_(isinstance(info[0]["ts"], datetime.datetime))
self.assert_(isinstance(info[0]["millis"], types.FloatType))
def test_iteration(self):
db = self.connection.pymongo_test
@ -174,11 +174,11 @@ class TestDatabase(unittest.TestCase):
self.assertEqual(None, db.previous_error())
db._command({"forceerror": 1}, check=False)
self.assertTrue(db.error())
self.assertTrue(db.previous_error())
self.assert_(db.error())
self.assert_(db.previous_error())
db._command({"forceerror": 1}, check=False)
self.assertTrue(db.error())
self.assert_(db.error())
prev_error = db.previous_error()
self.assertEqual(prev_error["nPrev"], 1)
del prev_error["nPrev"]
@ -186,7 +186,7 @@ class TestDatabase(unittest.TestCase):
db.test.find_one()
self.assertEqual(None, db.error())
self.assertTrue(db.previous_error())
self.assert_(db.previous_error())
self.assertEqual(db.previous_error()["nPrev"], 2)
db.reset_error_history()
@ -200,7 +200,7 @@ class TestDatabase(unittest.TestCase):
self.assertRaises(TypeError, db._password_digest, True)
self.assertRaises(TypeError, db._password_digest, None)
self.assertTrue(isinstance(db._password_digest("mike", "password"), types.UnicodeType))
self.assert_(isinstance(db._password_digest("mike", "password"), types.UnicodeType))
self.assertEqual(db._password_digest("mike", "password"), u"cd7e45b3b2767dc2fa9b6b548457ed00")
self.assertEqual(db._password_digest("mike", "password"), db._password_digest(u"mike", u"password"))
@ -212,10 +212,10 @@ class TestDatabase(unittest.TestCase):
self.assertRaises(TypeError, db.authenticate, 5, "password")
self.assertRaises(TypeError, db.authenticate, "mike", 5)
self.assertFalse(db.authenticate("mike", "not a real password"))
self.assertFalse(db.authenticate("faker", "password"))
self.assertTrue(db.authenticate("mike", "password"))
self.assertTrue(db.authenticate(u"mike", u"password"))
self.failIf(db.authenticate("mike", "not a real password"))
self.failIf(db.authenticate("faker", "password"))
self.assert_(db.authenticate("mike", "password"))
self.assert_(db.authenticate(u"mike", u"password"))
# just make sure there are no exceptions here
db.logout()
@ -274,7 +274,7 @@ class TestDatabase(unittest.TestCase):
a_doc = SON({"hello": u"world"})
a_key = db.test.save(a_doc)
self.assertTrue(isinstance(a_doc["_id"], ObjectId))
self.assert_(isinstance(a_doc["_id"], ObjectId))
self.assertEqual(a_doc["_id"], a_key)
self.assertEqual(a_doc, db.test.find_one({"_id": a_doc["_id"]}))
self.assertEqual(a_doc, db.test.find_one(a_key))
@ -325,13 +325,13 @@ class TestDatabase(unittest.TestCase):
db.test.save({"x": 2})
db.test.save({"x": 3})
self.assertTrue(db.test.find_one({"x": 2}))
self.assert_(db.test.find_one({"x": 2}))
db.test.remove({"x": 2})
self.assertFalse(db.test.find_one({"x": 2}))
self.failIf(db.test.find_one({"x": 2}))
self.assertTrue(db.test.find_one())
self.assert_(db.test.find_one())
db.test.remove({})
self.assertFalse(db.test.find_one())
self.failIf(db.test.find_one())
def test_save_a_bunch(self):
db = self.connection.pymongo_test

View File

@ -36,8 +36,8 @@ class TestDBRef(unittest.TestCase):
self.assertRaises(TypeError, DBRef, 1.5, a)
self.assertRaises(TypeError, DBRef, a, a)
self.assertRaises(TypeError, DBRef, None, a)
self.assertTrue(DBRef("coll", a))
self.assertTrue(DBRef(u"coll", a))
self.assert_(DBRef("coll", a))
self.assert_(DBRef(u"coll", a))
def test_repr(self):
self.assertEqual(repr(DBRef("coll", ObjectId("123456789012"))), "DBRef(u'coll', ObjectId('123456789012'))")

View File

@ -119,24 +119,24 @@ class TestGridFile(unittest.TestCase):
self.assertRaises(TypeError, GridFile, {}, "hello")
self.assertRaises(TypeError, GridFile, {}, None)
self.assertRaises(TypeError, GridFile, {}, 5)
self.assertTrue(GridFile({}, self.db))
self.assert_(GridFile({}, self.db))
self.assertRaises(TypeError, GridFile, {}, self.db, None)
self.assertRaises(TypeError, GridFile, {}, self.db, 5)
self.assertRaises(TypeError, GridFile, {}, self.db, [])
self.assertRaises(ValueError, GridFile, {}, self.db, "m")
self.assertRaises(ValueError, GridFile, {}, self.db, u"m")
self.assertTrue(GridFile({}, self.db, "r"))
self.assertTrue(GridFile({}, self.db, u"r"))
self.assertTrue(GridFile({}, self.db, "w"))
self.assertTrue(GridFile({}, self.db, u"w"))
self.assert_(GridFile({}, self.db, "r"))
self.assert_(GridFile({}, self.db, u"r"))
self.assert_(GridFile({}, self.db, "w"))
self.assert_(GridFile({}, self.db, u"w"))
self.assertRaises(TypeError, GridFile, {}, self.db, "r", None)
self.assertRaises(TypeError, GridFile, {}, self.db, "r", 5)
self.assertRaises(TypeError, GridFile, {}, self.db, "r", [])
self.assertRaises(IOError, GridFile, {"filename": "mike"}, self.db)
self.assertTrue(GridFile({"filename": "test"}, self.db))
self.assert_(GridFile({"filename": "test"}, self.db))
def test_properties(self):
self.db.fs.files.remove({})
@ -144,21 +144,21 @@ class TestGridFile(unittest.TestCase):
file = GridFile({"filename": "test"}, self.db, "w")
self.assertEqual(file.mode, "w")
self.assertFalse(file.closed)
self.failIf(file.closed)
file.close()
self.assertTrue(file.closed)
self.assert_(file.closed)
self.assertRaises(IOError, GridFile, {"filename": "mike"}, self.db)
a = GridFile({"filename": "test"}, self.db)
self.assertEqual(a.mode, "r")
self.assertFalse(a.closed)
self.failIf(a.closed)
self.assertEqual(a.length, 0)
self.assertEqual(a.content_type, None)
self.assertEqual(a.name, "test")
self.assertEqual(a.chunk_size, 256000)
self.assertTrue(isinstance(a.upload_date, datetime.datetime))
self.assert_(isinstance(a.upload_date, datetime.datetime))
self.assertEqual(a.aliases, None)
self.assertEqual(a.metadata, None)
self.assertEqual(a.md5, "d41d8cd98f00b204e9800998ecf8427e")

View File

@ -34,10 +34,10 @@ class TestObjectId(unittest.TestCase):
self.assertRaises(InvalidId, ObjectId, "")
self.assertRaises(InvalidId, ObjectId, "12345678901")
self.assertRaises(InvalidId, ObjectId, "1234567890123")
self.assertTrue(ObjectId())
self.assertTrue(ObjectId("123456789012"))
self.assert_(ObjectId())
self.assert_(ObjectId("123456789012"))
a = ObjectId()
self.assertTrue(ObjectId(a))
self.assert_(ObjectId(a))
def test_repr_str(self):
self.assertEqual(repr(ObjectId("123456789012")), "ObjectId('123456789012')")

View File

@ -69,13 +69,13 @@ class TestPaired(unittest.TestCase):
self.assertRaises(ConnectionFailure, Connection.paired, self.bad, self.bad)
connection = Connection.paired(self.left, self.right)
self.assertTrue(connection)
self.assert_(connection)
host = connection.host()
port = connection.port()
connection = Connection.paired(self.right, self.left)
self.assertTrue(connection)
self.assert_(connection)
self.assertEqual(host, connection.host())
self.assertEqual(port, connection.port())
@ -116,7 +116,7 @@ class TestPaired(unittest.TestCase):
connection.start_request()
db.test.remove({})
db.test.insert({})
self.assertTrue(db.test.find_one())
self.assert_(db.test.find_one())
connection.end_request()
if __name__ == "__main__":

View File

@ -18,6 +18,8 @@ import unittest
import threading
import os
import random
import sys
sys.path[0:0] = [""]
from pymongo.connection import Connection

View File

@ -73,10 +73,10 @@ class TestSONManipulator(unittest.TestCase):
break
return son_in == son
self.assertTrue(incoming_moves_id({}))
self.assertTrue(incoming_moves_id({"_id": 12}))
self.assertTrue(incoming_moves_id({"hello": "world", "_id": 12}))
self.assertTrue(incoming_moves_id(SON([("hello", "world"),
self.assert_(incoming_moves_id({}))
self.assert_(incoming_moves_id({"_id": 12}))
self.assert_(incoming_moves_id({"hello": "world", "_id": 12}))
self.assert_(incoming_moves_id(SON([("hello", "world"),
("_id", 12)])))
def outgoing_is_identity(son):