[Checkins] SVN: persistent/trunk/persistent/t Coverage.
Tres Seaver
cvs-admin at zope.org
Mon May 14 23:23:00 UTC 2012
Log message for revision 125884:
Coverage.
Ensure that Python reference impl. of Timestamp gets tested even if C
impl. builds.
Changed:
U persistent/trunk/persistent/tests/test_timestamp.py
U persistent/trunk/persistent/timestamp.py
-=-
Modified: persistent/trunk/persistent/tests/test_timestamp.py
===================================================================
--- persistent/trunk/persistent/tests/test_timestamp.py 2012-05-14 23:22:53 UTC (rev 125883)
+++ persistent/trunk/persistent/tests/test_timestamp.py 2012-05-14 23:22:57 UTC (rev 125884)
@@ -41,11 +41,11 @@
self.assertTrue(utc.fromutc(source) is source)
-class TimeStampTests(unittest.TestCase):
+class pyTimeStampTests(unittest.TestCase):
def _getTargetClass(self):
- from persistent.timestamp import TimeStamp
- return TimeStamp
+ from persistent.timestamp import pyTimeStamp
+ return pyTimeStamp
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
@@ -63,6 +63,18 @@
for args in BAD_ARGS:
self.assertRaises((TypeError, ValueError), self._makeOne, *args)
+ def test_ctor_from_invalid_strings(self):
+ BAD_ARGS = [''
+ '\x00',
+ '\x00' * 2,
+ '\x00' * 3,
+ '\x00' * 4,
+ '\x00' * 5,
+ '\x00' * 7,
+ ]
+ for args in BAD_ARGS:
+ self.assertRaises((TypeError, ValueError), self._makeOne, *args)
+
def test_ctor_from_string(self):
from persistent.timestamp import _makeOctets
from persistent.timestamp import _makeUTC
@@ -104,6 +116,17 @@
self.assertEqual(ts.second(), 0.0)
self.assertEqual(ts.timeTime(), DELTA_SECS)
+ def test_laterThan_invalid(self):
+ from persistent.timestamp import _makeOctets
+ SERIAL = _makeOctets('\x01' * 8)
+ ts = self._makeOne(SERIAL)
+ self.assertRaises(ValueError, ts.laterThan, None)
+ self.assertRaises(ValueError, ts.laterThan, '')
+ self.assertRaises(ValueError, ts.laterThan, ())
+ self.assertRaises(ValueError, ts.laterThan, [])
+ self.assertRaises(ValueError, ts.laterThan, {})
+ self.assertRaises(ValueError, ts.laterThan, object())
+
def test_laterThan_self_is_earlier(self):
from persistent.timestamp import _makeOctets
SERIAL1 = _makeOctets('\x01' * 8)
@@ -127,3 +150,17 @@
SERIAL = _makeOctets('\x01' * 8)
ts = self._makeOne(SERIAL)
self.assertEqual(SERIAL, repr(ts))
+
+class TimeStampTests(unittest.TestCase):
+
+ def _getTargetClass(self):
+ from persistent.timestamp import TimeStamp
+ return TimeStamp
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(Test__UTC),
+ unittest.makeSuite(pyTimeStampTests),
+ unittest.makeSuite(TimeStampTests),
+ ))
Modified: persistent/trunk/persistent/timestamp.py
===================================================================
--- persistent/trunk/persistent/timestamp.py 2012-05-14 23:22:53 UTC (rev 125883)
+++ persistent/trunk/persistent/timestamp.py 2012-05-14 23:22:57 UTC (rev 125884)
@@ -52,7 +52,7 @@
def _makeRaw(year, month, day, hour, minute, second):
a = (((year - 1900) * 12 + month - 1) * 31 + day - 1)
a = (a * 24 + hour) * 60 + minute
- b = round(second / _SCONV)
+ b = int(round(second / _SCONV))
return struct.pack('>II', a, b)
def _parseRaw(octets):
@@ -66,7 +66,7 @@
return (year, month, day, hour, minute, second)
-class TimeStamp(object):
+class pyTimeStamp(object):
__slots__ = ('_raw', '_elements')
def __init__(self, *args):
@@ -132,5 +132,5 @@
try:
from persistent.TimeStamp import TimeStamp
-except ImportError:
- pass
+except ImportError: #pragma NO COVER
+ TimeStamp = pyTimeStamp
More information about the checkins
mailing list