Commit c64792ae authored by Tres Seaver's avatar Tres Seaver

Coverage.

Ensure that Python reference impl. of Timestamp gets tested even if C
impl. builds.
parent 00d3d9f8
......@@ -41,11 +41,11 @@ class Test__UTC(unittest.TestCase):
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 @@ class TimeStampTests(unittest.TestCase):
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 @@ class TimeStampTests(unittest.TestCase):
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 @@ class TimeStampTests(unittest.TestCase):
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),
))
......@@ -52,7 +52,7 @@ _SCONV = 60.0 / (1<<16) / (1<<16)
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 @@ def _parseRaw(octets):
return (year, month, day, hour, minute, second)
class TimeStamp(object):
class pyTimeStamp(object):
__slots__ = ('_raw', '_elements')
def __init__(self, *args):
......@@ -132,5 +132,5 @@ class TimeStamp(object):
try:
from persistent.TimeStamp import TimeStamp
except ImportError:
pass
except ImportError: #pragma NO COVER
TimeStamp = pyTimeStamp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment