Skip to content

Commit

Permalink
some quick py3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Feb 26, 2013
1 parent a88c933 commit ca7d0e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/z3c/recipe/compattest/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ declared a (superfluous) test dependency on ``zope.dottedname``, which is
picked up:

>>> try:
... print 'start'
... print('start')
... cat('parts', 'compattest-z3c.recipe.compattest', 'site-packages', 'site.py')
... except IOError:
... print 'start'
... print('start')
... # When the tests are run from a virtualenv, the bin scripts are created
... # in a different location.
... cat('bin', 'compattest-z3c.recipe.compattest')
Expand All @@ -76,7 +76,7 @@ dependencies are also picked up, for instance zc.buildout:
... recipe = z3c.recipe.compattest
... include-dependencies = z3c.recipe.compattest
... """)
>>> print 'start', system(buildout)
>>> print('start', system(buildout))
start...
Generated script '/sample-buildout/bin/compattest-zc.buildout'.
...
Expand All @@ -103,7 +103,7 @@ the ``exclude`` option:
... include-dependencies = z3c.recipe.compattest
... exclude = zc.buildout
... """)
>>> print 'start', system(buildout)
>>> print('start', system(buildout))
start...
Generated script '/sample-buildout/bin/compattest'...

Expand Down Expand Up @@ -161,10 +161,10 @@ that depends on zope2 < 2.12:
... """)
>>> ignore = system(buildout)
>>> try:
... print 'start'
... print('start')
... cat('parts', 'compattest-z3c.recipe.compattest', 'site-packages', 'site.py')
... except IOError:
... print 'start'
... print('start')
... # When the tests are run from a virtualenv, the bin scripts are created
... # in a different location.
... cat('bin', 'compattest-z3c.recipe.compattest')
Expand Down
28 changes: 16 additions & 12 deletions src/z3c/recipe/compattest/runner.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import StringIO
import os.path
import subprocess
import sys
import time
import pickle

try:
from StringIO import StringIO
except ImportError:
from io import StringIO


def usage():
print """
print("""
usage: %s [OPTIONS]
All given options will be passed to each test runner. To know which
options you can use, refer to the test runner documentation.
""" % sys.argv[0]
""" % sys.argv[0])

windoze = sys.platform.startswith('win')

Expand All @@ -23,7 +27,7 @@ def __init__(self, script, args):
self.script = script
self.args = args
self.name = os.path.basename(script)
self.output = StringIO.StringIO()
self.output = StringIO()
self.exitcode = None

def start(self):
Expand Down Expand Up @@ -52,7 +56,7 @@ def poll(self):
else:
# We're not done, so just get some
data = self.process.stdout.readline()
self.output.write(data.replace('\r\n', '\n'))
self.output.write(data.replace(b'\r\n', b'\n').decode('utf-8'))


def main(max_jobs, *scripts, **options):
Expand All @@ -69,7 +73,7 @@ def main(max_jobs, *scripts, **options):
# the slowest tests first.
stat_file_name = os.path.join(os.path.expanduser('~'), '.zope.teststats')
try:
stat_file = open(stat_file_name, 'r')
stat_file = open(stat_file_name, 'rb')
except IOError:
stats = {}
else:
Expand All @@ -92,27 +96,27 @@ def main(max_jobs, *scripts, **options):
completed.append(job)
running.remove(job)
if job.exitcode:
print "%s failed with:" % job.name
print job.output.getvalue()
print("%s failed with:" % job.name)
print(job.output.getvalue())

while (len(running) < max_jobs) and scripts:
script = scripts.pop(0)
job = Job(script, sys.argv[1:])
print "Running %s" % job.name
print("Running %s" % job.name)
job.start()
running.append(job)

# Result output
failures = [job for job in completed if job.exitcode]
print "%d failure(s)." % len(failures)
print("%d failure(s)." % len(failures))
for job in failures:
print "-", job.name
print("- %s" % job.name)

# Store statistics
for job in completed:
stats[job.name] = job.end - job.start
try:
stat_file = open(stat_file_name, 'w')
stat_file = open(stat_file_name, 'wb')
except IOError:
# Statistics aren't that important. Just ignore that.
pass
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/recipe/compattest/runner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ failures.
... #!%s
... import time
... time.sleep(1)
... print 'ok' ''' % sys.executable, ok_script)
... print('ok' ''' % sys.executable, ok_script))

>>> failure_script = os.path.join(sample_buildout, 'test-failure')
>>> _ = _create_script('''\
Expand Down

0 comments on commit ca7d0e9

Please sign in to comment.