'Tests showing pymongo datetime fields handling of microseconds.
Microseconds are rounded to the nearest millisecond and pre UTC
handling is wonky.
See: http://api.mongodb.org/python/current/api/bson/son.html#dt'

def test_datetime(self):

    class LogEntry(Document, ):
        date = DateTimeField()
    LogEntry.drop_collection()
    log = LogEntry()
    log.date = datetime.date.today()
    log.save()
    log.reload()
    self.assertEqual(log.date.date(), datetime.date.today())
    d1 = datetime.datetime(1970, 1, 1, 0, 0, 1, 999)
    d2 = datetime.datetime(1970, 1, 1, 0, 0, 1)
    log = LogEntry()
    log.date = d1
    log.save()
    log.reload()
    self.assertNotEqual(log.date, d1)
    self.assertEqual(log.date, d2)
    d1 = datetime.datetime(1970, 1, 1, 0, 0, 1, 9999)
    d2 = datetime.datetime(1970, 1, 1, 0, 0, 1, 9000)
    log.date = d1
    log.save()
    log.reload()
    self.assertNotEqual(log.date, d1)
    self.assertEqual(log.date, d2)
    if (not six.PY3):
        d1 = datetime.datetime(1969, 12, 31, 23, 59, 59, 999)
        d2 = datetime.datetime(1969, 12, 31, 23, 59, 59)
        log.date = d1
        log.save()
        log.reload()
        self.assertNotEqual(log.date, d1)
        self.assertEqual(log.date, d2)
