Commit 320e4d78 authored by Albertas Agejevas's avatar Albertas Agejevas

More Py3 porting.

parent 366414ae
...@@ -85,7 +85,7 @@ def _main(args=None, prog=None): ...@@ -85,7 +85,7 @@ def _main(args=None, prog=None):
packt = time.time() packt = time.time()
if options.time: if options.time:
time_ = map(int, options.time.split(':')) time_ = list(map(int, options.time.split(':')))
if len(time_) == 1: if len(time_) == 1:
time_ += (0, 0) time_ += (0, 0)
elif len(time_) == 2: elif len(time_) == 2:
......
...@@ -14,25 +14,25 @@ for our test: ...@@ -14,25 +14,25 @@ for our test:
... logging.getLogger('test.ClientStorage').error( ... logging.getLogger('test.ClientStorage').error(
... "I hate this address, %r", args[0]) ... "I hate this address, %r", args[0])
... raise ValueError("Bad address") ... raise ValueError("Bad address")
... print "ClientStorage(%s %s)" % ( ... print("ClientStorage(%s %s)" % (
... repr(args)[1:-1], ... repr(args)[1:-1],
... ', '.join("%s=%r" % i for i in sorted(kw.items())), ... ', '.join("%s=%r" % i for i in sorted(kw.items())),
... ) ... ))
... def pack(self, t=None, *args, **kw): ... def pack(self, t=None, *args, **kw):
... now = time.localtime(time.time()) ... now = time.localtime(time.time())
... local_midnight = time.mktime(now[:3]+(0, 0, 0)+now[6:]) ... local_midnight = time.mktime(now[:3]+(0, 0, 0)+now[6:])
... t -= local_midnight # adjust for tz ... t -= local_midnight # adjust for tz
... t += 86400*7 # add a week to make sure we're positive ... 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], ... t, repr(args)[1:-1],
... ', '.join("%s=%r" % i for i in sorted(kw.items())), ... ', '.join("%s=%r" % i for i in sorted(kw.items())),
... ) ... ))
... def is_connected(self): ... def is_connected(self):
... self.connect_wait -= 1 ... self.connect_wait -= 1
... print 'is_connected', self.connect_wait < 0 ... print('is_connected', self.connect_wait < 0)
... return self.connect_wait < 0 ... return self.connect_wait < 0
... def close(self): ... def close(self):
... print "close()" ... print("close()")
>>> import ZEO >>> import ZEO
>>> ClientStorage_orig = ZEO.ClientStorage.ClientStorage >>> ClientStorage_orig = ZEO.ClientStorage.ClientStorage
...@@ -83,7 +83,7 @@ value is timezone dependent. ...@@ -83,7 +83,7 @@ value is timezone dependent.
>>> time.time = lambda : time.mktime((2009, 3, 24, 10, 55, 17, 1, 83, -1)) >>> time.time = lambda : time.mktime((2009, 3, 24, 10, 55, 17, 1, 83, -1))
>>> sleep_orig = time.sleep >>> sleep_orig = time.sleep
>>> def sleep(t): >>> def sleep(t):
... print 'sleep(%r)' % t ... print('sleep(%r)' % t)
>>> time.sleep = sleep >>> time.sleep = sleep
Normally, we pass one or more TCP server specifications: Normally, we pass one or more TCP server specifications:
...@@ -178,8 +178,8 @@ seconds of waiting for a connect. ...@@ -178,8 +178,8 @@ seconds of waiting for a connect.
... try: ... try:
... try: ... try:
... main(args) ... main(args)
... except SystemExit, v: ... except SystemExit as v:
... print "Exited", v ... print("Exited", v)
... finally: ... finally:
... sys.stderr = old_stderr ... sys.stderr = old_stderr
......
...@@ -82,7 +82,7 @@ dynamic port using ZConfig, you'd use a hostname by itself. In this ...@@ -82,7 +82,7 @@ dynamic port using ZConfig, you'd use a hostname by itself. In this
case, ZConfig passes None as the port. case, ZConfig passes None as the port.
>>> import ZEO.runzeo >>> import ZEO.runzeo
>>> open('conf', 'w').write(""" >>> r = open('conf', 'w').write("""
... <zeo> ... <zeo>
... address 127.0.0.1 ... address 127.0.0.1
... </zeo> ... </zeo>
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
############################################################################## ##############################################################################
"""Test suite for ZEO based on ZODB.tests.""" """Test suite for ZEO based on ZODB.tests."""
from __future__ import print_function from __future__ import print_function
import re
from ZEO.ClientStorage import ClientStorage from ZEO.ClientStorage import ClientStorage
from ZEO.tests.forker import get_port from ZEO.tests.forker import get_port
...@@ -1453,7 +1454,7 @@ def generate_script(name, src): ...@@ -1453,7 +1454,7 @@ def generate_script(name, src):
def runzeo_logrotate_on_sigusr2(): def runzeo_logrotate_on_sigusr2():
""" """
>>> port = get_port() >>> port = get_port()
>>> open('c', 'w').write(''' >>> r = open('c', 'w').write('''
... <zeo> ... <zeo>
... address %s ... address %s
... </zeo> ... </zeo>
...@@ -1756,8 +1757,14 @@ def test_suite(): ...@@ -1756,8 +1757,14 @@ def test_suite():
(re.compile(r"'start': '[^\n]+'"), 'start'), (re.compile(r"'start': '[^\n]+'"), 'start'),
]), ]),
)) ))
zeo.addTest(doctest.DocTestSuite(ZEO.tests.IterationTests, zeo.addTest(doctest.DocTestSuite(
setUp=forker.setUp, tearDown=zope.testing.setupstack.tearDown)) 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('registerDB.test'))
zeo.addTest( zeo.addTest(
doctest.DocFileSuite( doctest.DocFileSuite(
......
...@@ -231,7 +231,7 @@ We start a transaction and vote, this leads to getting the lock. ...@@ -231,7 +231,7 @@ We start a transaction and vote, this leads to getting the lock.
ZEO.StorageServer DEBUG ZEO.StorageServer DEBUG
(test-addr-1) ('1') lock: transactions waiting: 0 (test-addr-1) ('1') lock: transactions waiting: 0
ZEO.StorageServer BLATHER 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 ... 1 callAsync serialnos ...
If another client tried to vote, it's lock request will be queued and If another client tried to vote, it's lock request will be queued and
...@@ -253,7 +253,7 @@ When we end the first transaction, the queued vote gets the lock. ...@@ -253,7 +253,7 @@ When we end the first transaction, the queued vote gets the lock.
ZEO.StorageServer DEBUG ZEO.StorageServer DEBUG
(test-addr-2) ('1') lock: transactions waiting: 0 (test-addr-2) ('1') lock: transactions waiting: 0
ZEO.StorageServer BLATHER 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 ... 2 callAsync serialnos ...
Let's try again with the first client. The vote will be queued: Let's try again with the first client. The vote will be queued:
...@@ -328,7 +328,7 @@ release the lock and one of the waiting clients will get the lock. ...@@ -328,7 +328,7 @@ release the lock and one of the waiting clients will get the lock.
ZEO.StorageServer WARNING ZEO.StorageServer WARNING
(test-addr-1) ('1') lock: transactions waiting: 9 (test-addr-1) ('1') lock: transactions waiting: 9
ZEO.StorageServer BLATHER 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 ... 1 callAsync serialnos ...
(In practice, waiting clients won't necessarily get the lock in order.) (In practice, waiting clients won't necessarily get the lock in order.)
......
...@@ -52,7 +52,7 @@ Now, let's write some data: ...@@ -52,7 +52,7 @@ Now, let's write some data:
>>> conn = db.open() >>> conn = db.open()
>>> for i in range(1, 101): >>> for i in range(1, 101):
... conn.root()[i] = ZODB.blob.Blob() ... 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() >>> transaction.commit()
We've committed 10000 bytes of data, but our target size is 3000. We We've committed 10000 bytes of data, but our target size is 3000. We
...@@ -86,19 +86,19 @@ target: ...@@ -86,19 +86,19 @@ target:
>>> for i in range(1, 101): >>> for i in range(1, 101):
... data = conn.root()[i].open().read() ... 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)) ... print('bad data', repr(chr(i)), repr(data))
>>> wait_until("size is reduced", check, 99, onfail) >>> wait_until("size is reduced", check, 99, onfail)
>>> for i in range(1, 101): >>> for i in range(1, 101):
... data = conn.root()[i].open().read() ... 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)) ... print('bad data', repr(chr(i)), repr(data))
>>> for i in range(1, 101): >>> for i in range(1, 101):
... data = conn.root()[i].open('c').read() ... 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)) ... print('bad data', repr(chr(i)), repr(data))
>>> wait_until("size is reduced", check, 99, onfail) >>> wait_until("size is reduced", check, 99, onfail)
...@@ -115,11 +115,11 @@ provoke problems: ...@@ -115,11 +115,11 @@ provoke problems:
... time.sleep(0) ... time.sleep(0)
... i = random.randint(1, 100) ... i = random.randint(1, 100)
... data = conn.root()[i].open().read() ... 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)) ... print('bad data', repr(chr(i)), repr(data))
... i = random.randint(1, 100) ... i = random.randint(1, 100)
... data = conn.root()[i].open('c').read() ... 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)) ... print('bad data', repr(chr(i)), repr(data))
... db.close() ... db.close()
......
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