Commit f9785fea authored by Tres Seaver's avatar Tres Seaver

Coverage.

Zap fossil timestamp-manipulation functionss:  they now live in
'persistent.timestamp'.
parent d48634de
......@@ -12,7 +12,6 @@
#
##############################################################################
from copy_reg import __newobj__
import struct
import sys
from zope.interface import implements
......@@ -25,17 +24,12 @@ from persistent.interfaces import CHANGED
from persistent.interfaces import STICKY
from persistent.timestamp import TimeStamp
if sys.version_info < (2, 6,):
OID_TYPE = SERIAL_TYPE = str
else:
OID_TYPE = SERIAL_TYPE = bytes
OID_TYPE = SERIAL_TYPE = bytes
def _makeOctets(s):
if sys.version_info < (2, 6,):
return str(s)
if sys.version_info < (3,):
return bytes(s)
return bytes(s, 'ascii')
return bytes(s, 'ascii') #pragma NO COVER
_INITIAL_SERIAL = _makeOctets('\x00' * 8)
......@@ -55,24 +49,6 @@ SPECIAL_NAMES = ('__class__',
'__setstate__'
)
_SCONV = 60.0 / (1<<16) / (1<<16)
def makeTimestamp(year, month, day, hour, minute, second):
a = (((year - 1900) * 12 + month - 1) * 31 + day - 1)
a = (a * 24 + hour) * 60 + minute
b = int(second / _SCONV)
return struct.pack('>II', a, b)
def parseTimestamp(octets):
a, b = struct.unpack('>II', octets)
minute = a % 60
hour = a // 60 % 24
day = a // (60 * 24) % 31 + 1
month = a // (60 * 24 * 31) % 12 + 1
year = a // (60 * 24 * 31 * 12) + 1900
second = b * _SCONV
return (year, month, day, hour, minute, second)
class Persistent(object):
""" Pure Python implmentation of Persistent base class
......
......@@ -74,6 +74,12 @@ class _Persistent_Base(object):
inst._p_jar = new_jar
self.assertRaises(ValueError, _test)
def test_assign_p_jar_w_invalid_jar(self):
inst = self._makeOne()
def _test():
inst._p_jar = object()
self.assertRaises(ValueError, _test)
def test_assign_p_jar_w_valid_jar(self):
jar = self._makeJar()
inst = self._makeOne()
......@@ -474,11 +480,21 @@ class _Persistent_Base(object):
inst._p_estimated_size = -1
self.assertRaises(ValueError, _test)
def test_assign_p_estimated_size(self):
def test_assign_p_estimated_size_small(self):
inst = self._makeOne()
inst._p_estimated_size = 123
self.assertEqual(inst._p_estimated_size, 128)
def test_assign_p_estimated_size_just_over_threshold(self):
inst = self._makeOne()
inst._p_estimated_size = 1073741697
self.assertEqual(inst._p_estimated_size, 16777215 * 64)
def test_assign_p_estimated_size_bigger(self):
inst = self._makeOne()
inst._p_estimated_size = 1073741697 * 1024
self.assertEqual(inst._p_estimated_size, 16777215 * 64)
def test___getattribute___p__names(self):
NAMES = ['_p_jar',
'_p_oid',
......
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