Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
erp5
Commits
5b6d4788
Commit
5b6d4788
authored
Jan 18, 2023
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testDateUtils: test our DateTime pickle patches
parent
bc567885
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
15 deletions
+60
-15
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testDateUtils.py
...TemplateItem/portal_components/test.erp5.testDateUtils.py
+60
-0
product/ERP5Type/patches/DateTimePatch.py
product/ERP5Type/patches/DateTimePatch.py
+0
-15
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testDateUtils.py
View file @
5b6d4788
...
...
@@ -30,6 +30,7 @@
import
os
import
unittest
import
zodbpickle.fastpickle
as
pickle
from
DateTime
import
DateTime
from
erp5.component.module.DateUtils
import
addToDate
,
getIntervalListBetweenDates
,
\
atTheEndOfPeriod
,
getClosestDate
...
...
@@ -244,9 +245,68 @@ class TestTimeZoneContext(ERP5TypeTestCase):
self
.
assertEqual
(
os
.
environ
.
get
(
'TZ'
),
self
.
actual_environ_tz
)
class
TestDateTimePatch
(
ERP5TypeTestCase
):
"""Tests for monkey patches in Products.ERP5Type.patches.DateTimePatch
"""
def
_test_pickle
(
self
,
dt
,
data
):
"""Assert pickle `data` when loaded is equal to DateTime `dt`
"""
new
=
pickle
.
loads
(
data
)
if
hasattr
(
DateTime
,
'__slots__'
):
for
key
in
DateTime
.
__slots__
:
self
.
assertEqual
(
getattr
(
dt
,
key
),
getattr
(
new
,
key
))
else
:
# BBB DateTime 2
self
.
assertEqual
(
dt
.
__dict__
,
new
.
__dict__
)
# pickles from "current" ERP5
# around commit fcaa5dddbd (Zelenium: update html2canvas to version 1.4.1, 2022-04-18)
def
test_pickle_europe_paris
(
self
):
dt
=
DateTime
(
'2001/02/03 04:05:06 Europe/Paris'
)
data
=
b'(cDateTime.DateTime
\
n
DateTime
\
n
q
\
x01
Noq
\
x02
(GA
\
xcd
=
\
xba
\
xb1
\
x00
\
x00
\
x00
U
\
x0c
Europe/Parisq
\
x03
tb.'
self
.
_test_pickle
(
dt
,
data
)
def
test_pickle_UTC
(
self
):
dt
=
DateTime
(
'2001/02/03 04:05:06 UTC'
)
data
=
b'(cDateTime.DateTime
\
n
DateTime
\
n
q
\
x01
Noq
\
x02
(GA
\
xcd
=
\
xc1
\
xb9
\
x00
\
x00
\
x00
U
\
x03
UTCq
\
x03
tb.'
self
.
_test_pickle
(
dt
,
data
)
# "r15569" was an old patch to DateTime.__getstate__ that we keep compatibility with.
# It was a svn commit that was convert to git commit 7b89b86838 (Tweak DateTime pickle
# representation to avoid using 370 bytes per DateTime, but ~80 bytes instead.
# Retain backward compatibility with regular DateTime default serialisation., 2007-08-08)
def
test_pickle_europe_paris_r15569
(
self
):
dt
=
DateTime
(
'2001/02/03 04:05:06 Europe/Paris'
)
data
=
b'(cDateTime.DateTime
\
n
DateTime
\
n
q
\
x01
Noq
\
x02
}q
\
x03
U
\
x03
strq
\
x04
U 2001/02/03 04:05:06 Europe/Parissb.'
self
.
_test_pickle
(
dt
,
data
)
def
test_pickle_UTC_r15569
(
self
):
dt
=
DateTime
(
'2001/02/03 04:05:06 UTC'
)
data
=
b'(cDateTime.DateTime
\
n
DateTime
\
n
q
\
x01
Noq
\
x02
}q
\
x03
U
\
x03
strq
\
x04
U
\
x17
2001/02/03 04:05:06 UTCsb.'
self
.
_test_pickle
(
dt
,
data
)
def
test_pickle_protocol_3
(
self
):
dt
=
DateTime
()
data
=
pickle
.
dumps
(
dt
,
3
)
self
.
_test_pickle
(
dt
,
data
)
def
test_pickle_dumps_loads
(
self
):
for
i
in
(
'2007/01/02 12:34:56.789'
,
'2007/01/02 12:34:56.789 GMT+0200'
,
'2007/01/02 12:34:56.789 JST'
,
'2007/01/02 12:34:56.789 +0300'
,
'2007/01/02 12:34:56.789 +0430'
,
'2007/01/02 12:34:56.789 +1237'
,
):
dt
=
DateTime
(
i
)
self
.
_test_pickle
(
dt
,
pickle
.
dumps
(
dt
,
1
))
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestDateUtils
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestPinDateTime
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestTimeZoneContext
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestDateTimePatch
))
return
suite
product/ERP5Type/patches/DateTimePatch.py
View file @
5b6d4788
...
...
@@ -259,18 +259,3 @@ def DateTime_parse(self, st, datefmt=getDefaultDateFormat()):
DateTimeKlass
.
_parse
=
DateTime_parse
if
__name__
==
'__main__'
:
for
i
in
(
'2007/01/02 12:34:56.789'
,
'2007/01/02 12:34:56.789 GMT+0200'
,
'2007/01/02 12:34:56.789 JST'
,
'2007/01/02 12:34:56.789 +0300'
,
'2007/01/02 12:34:56.789 +0430'
,
'2007/01/02 12:34:56.789 +1237'
,
):
a
=
DateTimeKlass
(
i
)
b
=
DateTimeKlass
()
b
.
__setstate__
(
a
.
__getstate__
())
print
(
a
,
a
.
__dict__
==
b
.
__dict__
)
for
i
in
a
.
__dict__
.
keys
():
if
a
.
__dict__
[
i
]
!=
b
.
__dict__
[
i
]:
print
(
i
,
a
.
__dict__
[
i
],
b
.
__dict__
[
i
])
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