Skip to content

Commit

Permalink
Fix fstest tests on Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Feb 20, 2013
1 parent 37c20b5 commit 57e8924
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
19 changes: 8 additions & 11 deletions src/ZODB/scripts/fstest.py
Expand Up @@ -36,7 +36,7 @@
# ZODB.FileStorage. If anything about the FileStorage layout changes,
# this file will need to be udpated.

import string
import binascii
import struct
import sys

Expand All @@ -55,16 +55,13 @@ class Status:
VERBOSE = 0

def hexify(s):
"""Format an 8-bit string as hex"""
l = []
for c in s:
h = hex(ord(c))
if h[:2] == '0x':
h = h[2:]
if len(h) == 1:
l.append("0")
l.append(h)
return "0x" + ''.join(l)
r"""Format an 8-bit string as hex
>>> hexify(b'\x00\xff\xaa\xcc')
'0x00ffaacc'
"""
return '0x' + binascii.hexlify(s).decode()

def chatter(msg, level=1):
if VERBOSE >= level:
Expand Down
17 changes: 14 additions & 3 deletions src/ZODB/scripts/tests/test_fstest.py
Expand Up @@ -11,9 +11,13 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from zope.testing import setupstack
import doctest
import re
import unittest

import ZODB
from zope.testing import setupstack
from zope.testing.renormalizing import RENormalizing

def test_fstest_verbose():
r"""
Expand All @@ -39,6 +43,13 @@ def test_fstest_verbose():


def test_suite():
return doctest.DocTestSuite(
setUp=setupstack.setUpDirectory, tearDown=setupstack.tearDown)
checker = RENormalizing([
# Python 3 drops the u'' prefix on unicode strings
(re.compile(r"u('[^']*')"), r"\1"),
])
return unittest.TestSuite([
doctest.DocTestSuite('ZODB.scripts.fstest', checker=checker),
doctest.DocTestSuite(setUp=setupstack.setUpDirectory,
tearDown=setupstack.tearDown),
])

0 comments on commit 57e8924

Please sign in to comment.