Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
3529459c
Commit
3529459c
authored
Jul 26, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X PyData.ClassName() tested
parent
b242e07f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
9 deletions
+78
-9
go/zodb/py/pyserialize-gen-testdata
go/zodb/py/pyserialize-gen-testdata
+38
-3
go/zodb/pyserialize.go
go/zodb/pyserialize.go
+2
-3
go/zodb/pyserialize_test.go
go/zodb/pyserialize_test.go
+13
-1
go/zodb/storage/fs1/fs1tools/dump.go
go/zodb/storage/fs1/fs1tools/dump.go
+1
-1
go/zodb/storage/fs1/py/gen-testdata
go/zodb/storage/fs1/py/gen-testdata
+2
-1
go/zodb/ztestdata_pyserialize_test.go
go/zodb/ztestdata_pyserialize_test.go
+22
-0
No files found.
go/zodb/py/pyserialize-gen-testdata
View file @
3529459c
...
...
@@ -20,15 +20,50 @@
# See https://www.nexedi.com/licensing for rationale and options.
"""generate reference pickle objects encoding for tests"""
from
ZODB.tests.testSerialize
import
SerializerTestCase
as
t
from
ZODB.tests
import
testSerialize
from
ZODB
import
serialize
# escape string into valid "..." string
# XXX dup in fs1/py/pyserialize-gen-testdata
def
escapeqq
(
s
):
outv
=
[]
# we don't want ' to be escaped
for
_
in
s
.
split
(
"'"
):
# this escape almost everything except " character
# NOTE string_escape does not do smartquotes and always uses ' for quoting
# (repr(str) is the same except it does smartquoting picking ' or " automatically)
q
=
_
.
encode
(
"string_escape"
)
q
=
q
.
replace
(
'"'
,
r'\"'
)
outv
.
append
(
q
)
return
'"'
+
"'"
.
join
(
outv
)
+
'"'
def
main
():
# dump to go what to expect
with
open
(
"ztestdata_pyserialize.go"
,
"w"
)
as
f
:
with
open
(
"ztestdata_pyserialize
_test
.go"
,
"w"
)
as
f
:
def
emit
(
v
):
print
>>
f
,
v
emit
(
"// Code generated by %s; DO NOT EDIT."
%
__file__
)
emit
(
"%r"
%
ft
.
old_style_without_newargs
)
emit
(
"package zodb"
)
# [] of pickle
t
=
testSerialize
.
SerializerTestCase
testv
=
[
t
.
old_style_without_newargs
,
t
.
old_style_with_newargs
,
t
.
new_style_without_newargs
,
t
.
new_style_with_newargs
,
]
r
=
serialize
.
ObjectReader
(
factory
=
testSerialize
.
_factory
)
emit
(
"
\
n
var _PyData_ClassName_Testv = [...]_PyDataClassName_TestEntry{"
)
for
test
in
testv
:
emit
(
"
\
t
{"
)
emit
(
"
\
t
\
t
%s,"
%
escapeqq
(
test
))
emit
(
"
\
t
\
t
%s,"
%
escapeqq
(
r
.
getClassName
(
test
)))
emit
(
"
\
t
},"
)
emit
(
'
\
t
{"aaa", "?.?"},'
)
# invalid
emit
(
"}"
)
if
__name__
==
'__main__'
:
main
()
go/zodb/pyserialize.go
View file @
3529459c
...
...
@@ -37,11 +37,10 @@ import (
// for format description.
type
PyData
[]
byte
// Class
String
returns fully-qualified python class name used for object type.
// Class
Name
returns fully-qualified python class name used for object type.
// The format is "module.class".
// If pickle decoding fails "?.?" is returned.
// TODO tests
func
(
d
PyData
)
ClassString
()
string
{
func
(
d
PyData
)
ClassName
()
string
{
// see ObjectReader.getClassName & get_pickle_metadata in zodb/py
p
:=
pickle
.
NewDecoder
(
bytes
.
NewReader
([]
byte
(
d
)))
xklass
,
err
:=
p
.
Decode
()
...
...
go/zodb/pyserialize_test.go
View file @
3529459c
...
...
@@ -25,5 +25,17 @@ import (
"testing"
)
func
TestPyClassString
(
t
*
testing
.
T
)
{
type
_PyDataClassName_TestEntry
struct
{
pydata
string
className
string
}
func
TestPyClassName
(
t
*
testing
.
T
)
{
for
_
,
tt
:=
range
_PyData_ClassName_Testv
{
className
:=
PyData
(
tt
.
pydata
)
.
ClassName
()
if
className
!=
tt
.
className
{
t
.
Errorf
(
"class name for %q:
\n
have: %q
\n
want: %q"
,
tt
.
pydata
,
className
,
tt
.
className
)
}
}
}
go/zodb/storage/fs1/fs1tools/dump.go
View file @
3529459c
...
...
@@ -188,7 +188,7 @@ func (d *DumperFsDump) DumpTxn(buf *xfmt.Buffer, it *fs1.Iter) error {
if
data
==
nil
{
buf
.
S
(
" class=undo or abort of object creation"
)
}
else
{
fullclass
:=
zodb
.
PyData
(
data
)
.
Class
String
()
fullclass
:=
zodb
.
PyData
(
data
)
.
Class
Name
()
buf
.
S
(
" size="
)
.
D64
(
d
.
dhLoading
.
DataLen
)
buf
.
S
(
" class="
)
.
S
(
fullclass
)
...
...
go/zodb/storage/fs1/py/gen-testdata
View file @
3529459c
...
...
@@ -45,6 +45,7 @@ def hex64(packed):
return
'0x%016x'
%
unpack64
(
packed
)
# escape string into valid "..." string
# XXX dup in zodb/py/pyserialize-gen-testdata
def
escapeqq
(
s
):
outv
=
[]
# we don't want ' to be escaped
...
...
@@ -197,7 +198,7 @@ def main():
with
open
(
"ztestdata_expect_test.go"
,
"w"
)
as
f
:
def
emit
(
v
):
print
>>
f
,
v
emit
(
"// Code generated by
py/gen-testdata; DO NOT EDIT."
)
emit
(
"// Code generated by
%s; DO NOT EDIT."
%
__name__
)
emit
(
"package fs1
\
n
"
)
emit
(
"import
\
"
lab.nexedi.com/kirr/neo/go/zodb
\
"
\
n
"
)
...
...
go/zodb/ztestdata_pyserialize_test.go
0 → 100644
View file @
3529459c
// Code generated by ./py/pyserialize-gen-testdata; DO NOT EDIT.
package
zodb
var
_PyData_ClassName_Testv
=
[
...
]
_PyDataClassName_TestEntry
{
{
"((U
\x18
ZODB.tests.testSerializeq
\x01
U
\x13
ClassWithoutNewargsq
\x02
tNtq
\x03
."
,
"ZODB.tests.testSerialize.ClassWithoutNewargs"
,
},
{
"((U
\x18
ZODB.tests.testSerializeq
\x01
U
\x10
ClassWithNewargsq
\x02
t(K
\x01
tq
\x03
tq
\x04
."
,
"ZODB.tests.testSerialize.ClassWithNewargs"
,
},
{
"cZODB.tests.testSerialize
\n
ClassWithoutNewargs
\n
q
\x01
."
,
"ZODB.tests.testSerialize.ClassWithoutNewargs"
,
},
{
"(cZODB.tests.testSerialize
\n
ClassWithNewargs
\n
q
\x01
(K
\x01
tq
\x02
tq
\x03
."
,
"ZODB.tests.testSerialize.ClassWithNewargs"
,
},
{
"aaa"
,
"?.?"
},
}
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