Skip to content

Commit

Permalink
More Py3 porting.
Browse files Browse the repository at this point in the history
  • Loading branch information
alga committed Mar 13, 2013
1 parent 366414a commit 320e4d7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/ZEO/scripts/zeopack.py
Expand Up @@ -85,7 +85,7 @@ def error(message):

packt = time.time()
if options.time:
time_ = map(int, options.time.split(':'))
time_ = list(map(int, options.time.split(':')))
if len(time_) == 1:
time_ += (0, 0)
elif len(time_) == 2:
Expand Down
18 changes: 9 additions & 9 deletions src/ZEO/scripts/zeopack.test
Expand Up @@ -14,25 +14,25 @@ for our test:
... logging.getLogger('test.ClientStorage').error(
... "I hate this address, %r", args[0])
... raise ValueError("Bad address")
... print "ClientStorage(%s %s)" % (
... print("ClientStorage(%s %s)" % (
... repr(args)[1:-1],
... ', '.join("%s=%r" % i for i in sorted(kw.items())),
... )
... ))
... def pack(self, t=None, *args, **kw):
... now = time.localtime(time.time())
... local_midnight = time.mktime(now[:3]+(0, 0, 0)+now[6:])
... t -= local_midnight # adjust for tz
... t += 86400*7 # add a week to make sure we're positive
... print "pack(%r,%s %s)" % (
... print("pack(%r,%s %s)" % (
... t, repr(args)[1:-1],
... ', '.join("%s=%r" % i for i in sorted(kw.items())),
... )
... ))
... def is_connected(self):
... self.connect_wait -= 1
... print 'is_connected', self.connect_wait < 0
... print('is_connected', self.connect_wait < 0)
... return self.connect_wait < 0
... def close(self):
... print "close()"
... print("close()")

>>> import ZEO
>>> ClientStorage_orig = ZEO.ClientStorage.ClientStorage
Expand Down Expand Up @@ -83,7 +83,7 @@ value is timezone dependent.
>>> time.time = lambda : time.mktime((2009, 3, 24, 10, 55, 17, 1, 83, -1))
>>> sleep_orig = time.sleep
>>> def sleep(t):
... print 'sleep(%r)' % t
... print('sleep(%r)' % t)
>>> time.sleep = sleep

Normally, we pass one or more TCP server specifications:
Expand Down Expand Up @@ -178,8 +178,8 @@ seconds of waiting for a connect.
... try:
... try:
... main(args)
... except SystemExit, v:
... print "Exited", v
... except SystemExit as v:
... print("Exited", v)
... finally:
... sys.stderr = old_stderr

Expand Down
2 changes: 1 addition & 1 deletion src/ZEO/tests/dynamic_server_ports.test
Expand Up @@ -82,7 +82,7 @@ dynamic port using ZConfig, you'd use a hostname by itself. In this
case, ZConfig passes None as the port.

>>> import ZEO.runzeo
>>> open('conf', 'w').write("""
>>> r = open('conf', 'w').write("""
... <zeo>
... address 127.0.0.1
... </zeo>
Expand Down
13 changes: 10 additions & 3 deletions src/ZEO/tests/testZEO.py
Expand Up @@ -13,6 +13,7 @@
##############################################################################
"""Test suite for ZEO based on ZODB.tests."""
from __future__ import print_function
import re

from ZEO.ClientStorage import ClientStorage
from ZEO.tests.forker import get_port
Expand Down Expand Up @@ -1453,7 +1454,7 @@ def generate_script(name, src):
def runzeo_logrotate_on_sigusr2():
"""
>>> port = get_port()
>>> open('c', 'w').write('''
>>> r = open('c', 'w').write('''
... <zeo>
... address %s
... </zeo>
Expand Down Expand Up @@ -1756,8 +1757,14 @@ def test_suite():
(re.compile(r"'start': '[^\n]+'"), 'start'),
]),
))
zeo.addTest(doctest.DocTestSuite(ZEO.tests.IterationTests,
setUp=forker.setUp, tearDown=zope.testing.setupstack.tearDown))
zeo.addTest(doctest.DocTestSuite(
ZEO.tests.IterationTests,
setUp=forker.setUp, tearDown=zope.testing.setupstack.tearDown,
checker=renormalizing.RENormalizing((
(re.compile("ZEO.Exceptions.ClientDisconnected"),
"ClientDisconnected"),
)),
))
zeo.addTest(doctest.DocFileSuite('registerDB.test'))
zeo.addTest(
doctest.DocFileSuite(
Expand Down
6 changes: 3 additions & 3 deletions src/ZEO/tests/testZEO2.py
Expand Up @@ -231,7 +231,7 @@ def some_basic_locking_tests():
ZEO.StorageServer DEBUG
(test-addr-1) ('1') lock: transactions waiting: 0
ZEO.StorageServer BLATHER
(test-addr-1) Preparing to commit transaction: 1 objects, 36 bytes
(test-addr-1) Preparing to commit transaction: 1 objects, ... bytes
1 callAsync serialnos ...
If another client tried to vote, it's lock request will be queued and
Expand All @@ -253,7 +253,7 @@ def some_basic_locking_tests():
ZEO.StorageServer DEBUG
(test-addr-2) ('1') lock: transactions waiting: 0
ZEO.StorageServer BLATHER
(test-addr-2) Preparing to commit transaction: 1 objects, 36 bytes
(test-addr-2) Preparing to commit transaction: 1 objects, ... bytes
2 callAsync serialnos ...
Let's try again with the first client. The vote will be queued:
Expand Down Expand Up @@ -328,7 +328,7 @@ def some_basic_locking_tests():
ZEO.StorageServer WARNING
(test-addr-1) ('1') lock: transactions waiting: 9
ZEO.StorageServer BLATHER
(test-addr-1) Preparing to commit transaction: 1 objects, 36 bytes
(test-addr-1) Preparing to commit transaction: 1 objects, ... bytes
1 callAsync serialnos ...
(In practice, waiting clients won't necessarily get the lock in order.)
Expand Down
12 changes: 6 additions & 6 deletions src/ZEO/tests/zeo_blob_cache.test
Expand Up @@ -52,7 +52,7 @@ Now, let's write some data:
>>> conn = db.open()
>>> for i in range(1, 101):
... conn.root()[i] = ZODB.blob.Blob()
... conn.root()[i].open('w').write(chr(i)*100)
... w = conn.root()[i].open('w').write((chr(i)*100).encode('ascii'))
>>> transaction.commit()

We've committed 10000 bytes of data, but our target size is 3000. We
Expand Down Expand Up @@ -86,19 +86,19 @@ target:

>>> for i in range(1, 101):
... data = conn.root()[i].open().read()
... if data != chr(i)*100:
... if data != (chr(i)*100).encode('ascii'):
... print('bad data', repr(chr(i)), repr(data))

>>> wait_until("size is reduced", check, 99, onfail)

>>> for i in range(1, 101):
... data = conn.root()[i].open().read()
... if data != chr(i)*100:
... if data != (chr(i)*100).encode('ascii'):
... print('bad data', repr(chr(i)), repr(data))

>>> for i in range(1, 101):
... data = conn.root()[i].open('c').read()
... if data != chr(i)*100:
... if data != (chr(i)*100).encode('ascii'):
... print('bad data', repr(chr(i)), repr(data))

>>> wait_until("size is reduced", check, 99, onfail)
Expand All @@ -115,11 +115,11 @@ provoke problems:
... time.sleep(0)
... i = random.randint(1, 100)
... data = conn.root()[i].open().read()
... if data != chr(i)*100:
... if data != (chr(i)*100).encode('ascii'):
... print('bad data', repr(chr(i)), repr(data))
... i = random.randint(1, 100)
... data = conn.root()[i].open('c').read()
... if data != chr(i)*100:
... if data != (chr(i)*100).encode('ascii'):
... print('bad data', repr(chr(i)), repr(data))
... db.close()

Expand Down

0 comments on commit 320e4d7

Please sign in to comment.