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
5efcab76
Commit
5efcab76
authored
Apr 08, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests covering the AttributeError cases of the comparison functions.
parent
374604aa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
6 deletions
+49
-6
persistent/tests/test_timestamp.py
persistent/tests/test_timestamp.py
+43
-0
persistent/timestamp.py
persistent/timestamp.py
+6
-6
No files found.
persistent/tests/test_timestamp.py
View file @
5efcab76
...
...
@@ -11,6 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import
operator
import
unittest
class
Test__UTC
(
unittest
.
TestCase
):
...
...
@@ -152,12 +153,54 @@ class pyTimeStampTests(unittest.TestCase):
ts
=
self
.
_makeOne
(
SERIAL
)
self
.
assertEqual
(
repr
(
ts
),
repr
(
SERIAL
))
def
test_comparisons_to_non_timestamps
(
self
):
from
persistent._compat
import
PYTHON2
# Check the corner cases when comparing non-comparable types
ts
=
self
.
_makeOne
(
2011
,
2
,
16
,
14
,
37
,
22.0
)
if
PYTHON2
:
def
check
(
op
,
passes
):
if
passes
==
'neither'
:
self
.
assertFalse
(
op
(
ts
,
None
))
self
.
assertFalse
(
op
(
None
,
ts
))
elif
passes
==
'both'
:
self
.
assertTrue
(
op
(
ts
,
None
))
self
.
assertTrue
(
op
(
None
,
ts
))
elif
passes
==
'first'
:
self
.
assertTrue
(
op
(
ts
,
None
))
self
.
assertFalse
(
op
(
None
,
ts
))
else
:
self
.
assertFalse
(
op
(
ts
,
None
))
self
.
assertTrue
(
op
(
None
,
ts
))
else
:
def
check
(
op
,
passes
):
if
passes
==
'neither'
:
self
.
assertFalse
(
op
(
ts
,
None
))
self
.
assertFalse
(
op
(
None
,
ts
))
elif
passes
==
'both'
:
self
.
assertTrue
(
op
(
ts
,
None
))
self
.
assertTrue
(
op
(
None
,
ts
))
else
:
self
.
assertRaises
(
TypeError
,
op
,
ts
,
None
)
self
.
assertRaises
(
TypeError
,
op
,
None
,
ts
)
for
op_name
,
passes
in
((
'lt'
,
'second'
),
(
'gt'
,
'first'
),
(
'le'
,
'second'
),
(
'ge'
,
'first'
),
(
'eq'
,
'neither'
),
(
'ne'
,
'both'
)):
op
=
getattr
(
operator
,
op_name
)
check
(
op
,
passes
)
class
TimeStampTests
(
pyTimeStampTests
):
def
_getTargetClass
(
self
):
from
persistent.timestamp
import
TimeStamp
return
TimeStamp
class
PyAndCComparisonTests
(
unittest
.
TestCase
):
"""
Compares C and Python implementations.
...
...
persistent/timestamp.py
View file @
5efcab76
...
...
@@ -139,13 +139,13 @@ class pyTimeStamp(object):
def
__eq__
(
self
,
other
):
try
:
return
self
.
raw
()
==
other
.
raw
()
except
AttributeError
:
#pragma: no cover
except
AttributeError
:
return
NotImplemented
def
__ne__
(
self
,
other
):
try
:
return
self
.
raw
()
!=
other
.
raw
()
except
AttributeError
:
#pragma: no cover
except
AttributeError
:
return
NotImplemented
def
__hash__
(
self
):
...
...
@@ -172,25 +172,25 @@ class pyTimeStamp(object):
def
__lt__
(
self
,
other
):
try
:
return
self
.
raw
()
<
other
.
raw
()
except
AttributeError
:
#pragma: no cover
except
AttributeError
:
return
NotImplemented
def
__gt__
(
self
,
other
):
try
:
return
self
.
raw
()
>
other
.
raw
()
except
AttributeError
:
#pragma: no cover
except
AttributeError
:
return
NotImplemented
def
__le__
(
self
,
other
):
try
:
return
self
.
raw
()
<=
other
.
raw
()
except
AttributeError
:
#pragma: no cover
except
AttributeError
:
return
NotImplemented
def
__ge__
(
self
,
other
):
try
:
return
self
.
raw
()
>=
other
.
raw
()
except
AttributeError
:
#pragma: no cover
except
AttributeError
:
return
NotImplemented
...
...
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