Commit 93e2f065 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/fs1tools: test: Normalize dumpOk from py3 to py2 syntax

Because else, py3_pickle3 tests fail e.g. as

        --- FAIL: TestFsDump/py3_pickle3/db=1 (0.00s)
            dump_test.go:70: fsdump: dump different:
                 Trans #00000 tid=0285cbac70a3d733 size=211 time=1979-01-03 21:00:26.400001 offset=117
                -    status='p' user=b'user0.12' description=b'step 0.12'
                +    status='p' user='user0.12' description='step 0.12'

        --- FAIL: TestFsDumpv/py3_pickle3/db=1 (0.00s)
            dump_test.go:70: fsdumpv: dump different:
                 ************************************************************
                -file identifier: b'FS30'
                +file identifier: 'FS30'

        ...

fs1tools/go sticks to py2 syntax because in my view it is more user
friendly. The preference of py2 or py3 syntax needs to be made anyway
because for fs1tools/go it is not possible to know beforehand to which
py kind its output will be compared against.

I think it is not very good for fstools/py output to be dependent on
python version. For the reference on this topic: output of zodbtools/py
is designed to be the same on both py2 and py3.
parent 117172cf
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"strings"
"testing" "testing"
"lab.nexedi.com/kirr/neo/go/internal/xtesting" "lab.nexedi.com/kirr/neo/go/internal/xtesting"
...@@ -53,9 +54,6 @@ func testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper) { ...@@ -53,9 +54,6 @@ func testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper) {
} }
func _testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper, z *ZTestData) { func _testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper, z *ZTestData) {
if z.Kind == "py3_pickle3" {
t.Skip("xfail")
}
testv := []string{"1", "empty", "whiteout"} testv := []string{"1", "empty", "whiteout"}
for _, tt := range testv { for _, tt := range testv {
t.Run("db=" + tt, func(t *testing.T) { t.Run("db=" + tt, func(t *testing.T) {
...@@ -69,6 +67,18 @@ func _testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper, z *ZTestData) ...@@ -69,6 +67,18 @@ func _testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper, z *ZTestData)
dumpOk := loadFile(t, z.Path(fmt.Sprintf("/%s.%s.ok", tt, d.DumperName()))) dumpOk := loadFile(t, z.Path(fmt.Sprintf("/%s.%s.ok", tt, d.DumperName())))
// normalize dumpOk from py3 to py2 and go outputs:
// bytestrings come as '...' on py2 and b'...' on py3
if strings.HasPrefix(z.Kind, "py3") {
sub := func(old, new string) {
dumpOk = strings.ReplaceAll(dumpOk, old, new)
}
sub(`: b'`, `: '`)
sub(`: b"`, `: "`)
sub(`=b'`, `='`)
sub(`=b"`, `="`)
}
if dumpOk != buf.String() { if dumpOk != buf.String() {
t.Errorf("%s: dump different:\n%v", d.DumperName(), diff.Diff(dumpOk, buf.String())) t.Errorf("%s: dump different:\n%v", d.DumperName(), diff.Diff(dumpOk, buf.String()))
} }
......
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