Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
persistent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
persistent
Commits
c64792ae
Commit
c64792ae
authored
May 14, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coverage.
Ensure that Python reference impl. of Timestamp gets tested even if C impl. builds.
parent
00d3d9f8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
7 deletions
+44
-7
persistent/tests/test_timestamp.py
persistent/tests/test_timestamp.py
+40
-3
persistent/timestamp.py
persistent/timestamp.py
+4
-4
No files found.
persistent/tests/test_timestamp.py
View file @
c64792ae
...
...
@@ -41,11 +41,11 @@ class Test__UTC(unittest.TestCase):
self
.
assertTrue
(
utc
.
fromutc
(
source
)
is
source
)
class
TimeStampTests
(
unittest
.
TestCase
):
class
py
TimeStampTests
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
from
persistent.timestamp
import
TimeStamp
return
TimeStamp
from
persistent.timestamp
import
py
TimeStamp
return
py
TimeStamp
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
),
))
persistent/timestamp.py
View file @
c64792ae
...
...
@@ -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
py
TimeStamp
(
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment