[Zope-Checkins] CVS: StandaloneZODB/ZODB/tests - testTimeStamp.py:1.1.6.1 testfsIndex.py:1.1.6.1 StorageTestBase.py:1.9.18.1 testPersistentMapping.py:1.2.4.1 testTransaction.py:1.2.52.1

Jeremy Hylton jeremy@zope.com
Tue, 18 Dec 2001 12:04:20 -0500


Update of /cvs-repository/StandaloneZODB/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv28929/ZODB/tests

Modified Files:
      Tag: Standby-branch
	StorageTestBase.py testPersistentMapping.py testTransaction.py 
Added Files:
      Tag: Standby-branch
	testTimeStamp.py testfsIndex.py 
Log Message:
Merge StandaloneZODB-1_0-branch into Standby-branch


=== Added File StandaloneZODB/ZODB/tests/testTimeStamp.py ===
"""Test the TimeStamp utility type"""

import time
import unittest

from ZODB.TimeStamp import TimeStamp

EPSILON = 0.000001

class TimeStampTests(unittest.TestCase):

    def checkYMDTimeStamp(self):
        self._check_ymd(2001, 6, 3)

    def _check_ymd(self, yr, mo, dy):
        ts = TimeStamp(yr, mo, dy)
        self.assertEqual(ts.year(), yr)
        self.assertEqual(ts.month(), mo)
        self.assertEqual(ts.day(), dy)

        self.assertEquals(ts.hour(), 0)
        self.assertEquals(ts.minute(), 0)
        self.assertEquals(ts.second(), 0)

        t = time.gmtime(ts.timeTime())
        self.assertEquals(yr, t[0])
        self.assertEquals(mo, t[1])
        self.assertEquals(dy, t[2])

    def checkFullTimeStamp(self):
        t = time.gmtime()
        ts = TimeStamp(*t[:6])

        # XXX floating point comparison
        self.assertEquals(ts.timeTime() + time.timezone, time.mktime(t))

        self.assertEqual(ts.year(), t[0])
        self.assertEqual(ts.month(), t[1])
        self.assertEqual(ts.day(), t[2])

        self.assertEquals(ts.hour(), t[3])
        self.assertEquals(ts.minute(), t[4])
        self.assert_(abs(ts.second() - t[5]) < EPSILON)

    def checkRawTimestamp(self):
        t = time.gmtime()
        ts1 = TimeStamp(*t[:6])
        ts2 = TimeStamp(`ts1`)

        self.assertEquals(ts1, ts2)
        self.assertEquals(ts1.timeTime(), ts2.timeTime())
        self.assertEqual(ts1.year(), ts2.year())
        self.assertEqual(ts1.month(), ts2.month())
        self.assertEqual(ts1.day(), ts2.day())
        self.assertEquals(ts1.hour(), ts2.hour())
        self.assertEquals(ts1.minute(), ts2.minute())
        self.assert_(abs(ts1.second() - ts2.second()) < EPSILON)

    def checkDictKey(self):
        t = time.gmtime()
        ts1 = TimeStamp(*t[:6])
        ts2 = TimeStamp(2000, *t[1:6])

        d = {}
        d[ts1] = 1
        d[ts2] = 2

        self.assertEquals(len(d), 2)

    def checkCompare(self):
        ts1 = TimeStamp(1972, 6, 27)
        ts2 = TimeStamp(1971, 12, 12)
        self.assert_(ts1 > ts2)
        self.assert_(ts2 <= ts1)

    def checkLaterThan(self):
        # XXX what does laterThan() do?
        t = time.gmtime()
        ts = TimeStamp(*t[:6])
        ts2 = ts.laterThan(ts)
        self.assert_(ts2 > ts)

    # XXX should test for bogus inputs to TimeStamp constructor

def test_suite():
    return unittest.makeSuite(TimeStampTests, 'check')


=== Added File StandaloneZODB/ZODB/tests/testfsIndex.py ===

import unittest, sys
from ZODB.fsIndex import fsIndex
from ZODB.utils import p64


class Test(unittest.TestCase):

    def testInserts(self):
        index=fsIndex()

        for i in range(200):
            index[p64(i*1000)]=(i*1000L+1)

        for i in range(0,200):
            self.assertEqual((i,index[p64(i*1000)]), (i,(i*1000L+1)))
            
        self.assertEqual(len(index), 200)

        key=p64(2000)

        self.assertEqual(index.get(key), 2001)

        key=p64(2001)
        self.assertEqual(index.get(key), None)
        self.assertEqual(index.get(key, ''), '')

        # self.failUnless(len(index._data) > 1)

    def testUpdate(self):
        index=fsIndex()
        d={}

        for i in range(200):
            d[p64(i*1000)]=(i*1000L+1)

        index.update(d)

        for i in range(400,600):
            d[p64(i*1000)]=(i*1000L+1)
        
        index.update(d)

        for i in range(100, 500):
            d[p64(i*1000)]=(i*1000L+2)
            
        index.update(d)

        self.assertEqual(index.get(p64(2000)), 2001)
        self.assertEqual(index.get(p64(599000)), 599001)
        self.assertEqual(index.get(p64(399000)), 399002)
        self.assertEqual(len(index), 600)


def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())


=== StandaloneZODB/ZODB/tests/StorageTestBase.py 1.9 => 1.9.18.1 ===
 def import_helper(name):
     mod = __import__(name)
-    for part in string.split(name, ".")[1:]:
-        mod = getattr(mod, part)
-    return mod
+    return sys.modules[name]
 
 
 class StorageTestBase(unittest.TestCase):


=== StandaloneZODB/ZODB/tests/testPersistentMapping.py 1.2 => 1.2.4.1 ===
     """Helper for this test suite to get special PersistentMapping"""
 
-    #print modulename, classname
     if classname == "PersistentMapping":
         class PersistentMapping:
             def __setstate__(self, state):


=== StandaloneZODB/ZODB/tests/testTransaction.py 1.2 => 1.2.52.1 ===
         meth = getattr(obj, meth_name)
         meth(1)
-        get_transaction().commit()
-
+        get_transaction().commit() 
+                            
     checkSubSingleCommit = lambda self:\
                            self.wrap_test(BasicTests, "checkSingleCommit")