Skip to content

Commit

Permalink
Trivial Py3 porting changes: binary data, print functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
alga committed Mar 8, 2013
1 parent 114dd15 commit 7830739
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/ZEO/tests/ConnectionTests.py
Expand Up @@ -335,7 +335,7 @@ def checkDisconnectionError(self):
self.shutdownServer()
self._storage = self.openClientStorage('test', 1000, wait=0)
self.assertRaises(ClientDisconnected,
self._storage.load, 'fredwash', '')
self._storage.load, b'fredwash', '')
self._storage.close()

def checkBasicPersistence(self):
Expand Down Expand Up @@ -579,13 +579,13 @@ def checkCheckForOutOfDateServer(self):
self._storage = self.openClientStorage()
self._dostore()
self.shutdownServer()
self.assertRaises(ClientDisconnected, self._storage.load, '\0'*8, '')
self.assertRaises(ClientDisconnected, self._storage.load, b'\0'*8, '')

self.startServer()

# No matter how long we wait, the client won't reconnect:
time.sleep(2)
self.assertRaises(ClientDisconnected, self._storage.load, '\0'*8, '')
self.assertRaises(ClientDisconnected, self._storage.load, b'\0'*8, '')

class InvqTests(CommonSetupTearDown):
invq = 3
Expand Down
4 changes: 2 additions & 2 deletions src/ZEO/tests/IterationTests.py
Expand Up @@ -127,8 +127,8 @@ def checkIteratorParallel(self):
txn_info1 = six.advance_iterator(iter1)
txn_info2 = six.advance_iterator(iter2)
self.assertEquals(txn_info1.tid, txn_info2.tid)
self.assertRaises(StopIteration, iter1.next)
self.assertRaises(StopIteration, iter2.next)
self.assertRaises(StopIteration, next, iter1)
self.assertRaises(StopIteration, next, iter2)


def iterator_sane_after_reconnect():
Expand Down
3 changes: 2 additions & 1 deletion src/ZEO/tests/forker.py
Expand Up @@ -23,6 +23,7 @@
import logging
import tempfile
import logging
import six
import ZODB.tests.util
import zope.testing.setupstack
from ZEO._compat import BytesIO
Expand Down Expand Up @@ -358,7 +359,7 @@ def wait_until(label=None, func=None, timeout=30, onfail=None):
if label is None:
if func is not None:
label = func.__name__
elif not isinstance(label, basestring) and func is None:
elif not isinstance(label, six.string_types) and func is None:
func = label
label = func.__name__

Expand Down
24 changes: 12 additions & 12 deletions src/ZEO/tests/testZEO.py
Expand Up @@ -13,7 +13,6 @@
##############################################################################
"""Test suite for ZEO based on ZODB.tests."""
from __future__ import print_function
from __future__ import print_function

from ZEO.ClientStorage import ClientStorage
from ZEO.tests.forker import get_port
Expand Down Expand Up @@ -258,7 +257,7 @@ def do_store():
try:
t = transaction.get()
store.tpc_begin(t)
store.store(oid, revid, 'x', '', t)
store.store(oid, revid, b'x', '', t)
store.tpc_vote(t)
store.tpc_finish(t)
except Exception as v:
Expand Down Expand Up @@ -625,7 +624,7 @@ def checkStoreBlob(self):
handle_serials
import transaction

somedata = 'a' * 10
somedata = b'a' * 10

blob = Blob()
bd_fh = blob.open('w')
Expand All @@ -649,7 +648,7 @@ def checkStoreBlob(self):
self.assert_(not os.path.exists(tfname))
filename = self._storage.fshelper.getBlobFilename(oid, revid)
self.assert_(os.path.exists(filename))
self.assertEqual(somedata, open(filename).read())
self.assertEqual(somedata, open(filename, 'rb').read())

def checkStoreBlob_wrong_partition(self):
os_rename = os.rename
Expand All @@ -667,7 +666,7 @@ def checkLoadBlob(self):
handle_serials
import transaction

somedata = 'a' * 10
somedata = b'a' * 10

blob = Blob()
bd_fh = blob.open('w')
Expand Down Expand Up @@ -699,7 +698,8 @@ def checkTemporaryDirectory(self):

def checkTransactionBufferCleanup(self):
oid = self._storage.new_oid()
open('blob_file', 'w').write('I am a happy blob.')
with open('blob_file', 'wb') as f:
f.write(b'I am a happy blob.')
t = transaction.Transaction()
self._storage.tpc_begin(t)
self._storage.storeBlob(
Expand All @@ -720,7 +720,7 @@ def checkStoreAndLoadBlob(self):
somedata_path = os.path.join(self.blob_cache_dir, 'somedata')
somedata = open(somedata_path, 'w+b')
for i in range(1000000):
somedata.write("%s\n" % i)
somedata.write(("%s\n" % i).encode('ascii'))
somedata.seek(0)

blob = Blob()
Expand Down Expand Up @@ -1240,10 +1240,10 @@ def runzeo_without_configfile():
... ''' % sys.path)
>>> import subprocess, re
>>> print re.sub('\d\d+|[:]', '', subprocess.Popen(
>>> print(re.sub('\d\d+|[:]', '', subprocess.Popen(
... [sys.executable, 'runzeo', '-a:%s' % get_port(), '-ft', '--test'],
... stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
... ).stdout.read()), # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
... ).stdout.read())) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
------
--T INFO ZEO.runzeo () opening storage '1' using FileStorage
------
Expand Down Expand Up @@ -1277,7 +1277,7 @@ def close_client_storage_w_invalidations():
>>> time.sleep(.01)
>>> for i in range(10):
... conn = ZEO.connection(addr)
... _ = conn._storage.load('\0'*8)
... _ = conn._storage.load(b'\0'*8)
... conn.close()
>>> writing.clear()
Expand Down Expand Up @@ -1336,7 +1336,7 @@ def client_labels():
... def check_for_test_label_1():
... for line in open('server-%s.log' % addr[1]):
... if 'test-label-1' in line:
... print line.split()[1:4]
... print(line.split()[1:4])
... return True
['INFO', 'ZEO.StorageServer', '(test-label-1']
Expand All @@ -1356,7 +1356,7 @@ def client_labels():
... def check_for_test_label_2():
... for line in open('server-%s.log' % addr[1]):
... if 'test-label-2' in line:
... print line.split()[1:4]
... print(line.split()[1:4])
... return True
['INFO', 'ZEO.StorageServer', '(test-label-2']
Expand Down
2 changes: 1 addition & 1 deletion src/ZEO/zrpc/client.py
Expand Up @@ -507,7 +507,7 @@ def _connect_wrappers(self, wrappers, deadline):
def _fallback_wrappers(self, wrappers, deadline):
# If we've got wrappers left at this point, they're fallback
# connections. Try notifying them until one succeeds.
for wrap in wrappers.keys():
for wrap in list(wrappers.keys()):
assert wrap.state == "tested" and wrap.preferred == 0
if self.mgr.is_connected():
wrap.close()
Expand Down
2 changes: 1 addition & 1 deletion src/ZEO/zrpc/smac.py
Expand Up @@ -196,7 +196,7 @@ def handle_read(self):
inp = d
else:
inp.append(d)
inp = "".join(inp)
inp = b"".join(inp)

offset = 0
while (offset + msg_size) <= input_len:
Expand Down

0 comments on commit 7830739

Please sign in to comment.