Merge pull request #580 from tahoe-lafs/3008-test-print-function

updated test code to use print function over print statement
This commit is contained in:
meejah 2019-03-26 00:19:33 +00:00 committed by GitHub
commit d73626b7da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 202 additions and 163 deletions

1
newsfragments/3008.other Normal file
View File

@ -0,0 +1 @@
Updated the testing code to use the print function instead of the print statement.

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import hotshot.stats, os, random, sys
from pyutil import benchutil, randutil # http://tahoe-lafs.org/trac/pyutil
@ -110,12 +112,12 @@ class B(object):
for (initfunc, func) in [(self.init_for_unpack, self.unpack),
(self.init_for_pack, self.pack),
(self.init_for_unpack, self.unpack_and_repack)]:
print "benchmarking %s" % (func,)
print("benchmarking %s" % (func,))
for N in 16, 512, 2048, 16384:
print "%5d" % N,
print("%5d" % N, end=' ')
benchutil.rep_bench(func, N, initfunc=initfunc, MAXREPS=20, UNITS_PER_SECOND=1000)
benchutil.print_bench_footer(UNITS_PER_SECOND=1000)
print "(milliseconds)"
print("(milliseconds)")
def prof_benchmarks(self):
# This requires pyutil >= v1.3.34.
@ -128,7 +130,7 @@ class B(object):
if __name__ == "__main__":
if '--profile' in sys.argv:
if os.path.exists(PROF_FILE_NAME):
print "WARNING: profiling results file '%s' already exists -- the profiling results from this run will be added into the profiling results stored in that file and then the sum of them will be printed out after this run." % (PROF_FILE_NAME,)
print("WARNING: profiling results file '%s' already exists -- the profiling results from this run will be added into the profiling results stored in that file and then the sum of them will be printed out after this run." % (PROF_FILE_NAME,))
b = B()
b.prof_benchmarks()
b.print_stats()

View File

@ -1,3 +1,5 @@
from __future__ import print_function
"""
Test an existing Tahoe grid, both to see if the grid is still running and to
see if the client is still compatible with it. This script is suitable for
@ -95,13 +97,13 @@ class GridTester:
rc = p.returncode
if expected_rc != None and rc != expected_rc:
if stderr:
print "STDERR:"
print stderr
print("STDERR:")
print(stderr)
raise CommandFailed("command '%s' failed: rc=%d" % (cmd, rc))
return stdout, stderr
def cli(self, cmd, *args, **kwargs):
print "tahoe", cmd, " ".join(args)
print("tahoe", cmd, " ".join(args))
stdout, stderr = self.command(self.tahoe, cmd, "-d", self.nodedir,
*args, **kwargs)
if not kwargs.get("ignore_stderr", False) and stderr != "":
@ -110,16 +112,16 @@ class GridTester:
return stdout
def stop_old_node(self):
print "tahoe stop", self.nodedir, "(force)"
print("tahoe stop", self.nodedir, "(force)")
self.command(self.tahoe, "stop", self.nodedir, expected_rc=None)
def start_node(self):
print "tahoe start", self.nodedir
print("tahoe start", self.nodedir)
self.command(self.tahoe, "start", self.nodedir)
time.sleep(5)
def stop_node(self):
print "tahoe stop", self.nodedir
print("tahoe stop", self.nodedir)
self.command(self.tahoe, "stop", self.nodedir)
def read_and_check(self, f):
@ -146,7 +148,7 @@ class GridTester:
def listdir(self, dirname):
out = self.cli("ls", "testgrid:"+dirname).strip().split("\n")
files = [f.strip() for f in out]
print " ", files
print(" ", files)
return files
def do_test(self):

View File

@ -1,3 +1,5 @@
from __future__ import print_function
"""
this is a load-generating client program. It does all of its work through a
given tahoe node (specified by URL), and performs random reads and writes
@ -56,24 +58,24 @@ if sys.argv[1] == "--stats":
if last_stats:
delta = dict( [ (n,stats[n]-last_stats[n])
for n in stats ] )
print "THIS SAMPLE:"
print("THIS SAMPLE:")
for name in sorted(delta.keys()):
avg = float(delta[name]) / float(DELAY)
print "%20s: %0.2f per second" % (name, avg)
print("%20s: %0.2f per second" % (name, avg))
totals.append(delta)
while len(totals) > MAXSAMPLES:
totals.pop(0)
# now compute average
print
print "MOVING WINDOW AVERAGE:"
print()
print("MOVING WINDOW AVERAGE:")
for name in sorted(delta.keys()):
avg = sum([ s[name] for s in totals]) / (DELAY*len(totals))
print "%20s %0.2f per second" % (name, avg)
print("%20s %0.2f per second" % (name, avg))
last_stats = stats
print
print
print()
print()
time.sleep(DELAY)
stats_out = sys.argv[1]
@ -107,8 +109,8 @@ def listdir(nodeurl, root, remote_pathname):
try:
parsed = json.loads(data)
except ValueError:
print "URL was", url
print "DATA was", data
print("URL was", url)
print("DATA was", data)
raise
nodetype, d = parsed
assert nodetype == "dirnode"
@ -238,11 +240,11 @@ while True:
op = "read"
else:
op = "write"
print "OP:", op
print("OP:", op)
server = random.choice(server_urls)
if op == "read":
pathname = choose_random_descendant(server, root)
print " reading", pathname
print(" reading", pathname)
read_and_discard(server, root, pathname)
files_downloaded += 1
elif op == "write":
@ -253,9 +255,9 @@ while True:
pathname = current_writedir + "/" + filename
else:
pathname = filename
print " writing", pathname
print(" writing", pathname)
size = choose_size()
print " size", size
print(" size", size)
generate_and_put(server, root, pathname, size)
files_uploaded += 1

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os, shutil, sys, urllib, time, stat, urlparse
from cStringIO import StringIO
from twisted.internet import defer, reactor, protocol, error
@ -24,17 +26,17 @@ class StallableHTTPGetterDiscarder(tw_client.HTTPPageGetter):
return
if self._bytes_so_far > 1e6+100:
if not self.stalled:
print "STALLING"
print("STALLING")
self.transport.pauseProducing()
self.stalled = reactor.callLater(10.0, self._resume_speed)
def _resume_speed(self):
print "RESUME SPEED"
print("RESUME SPEED")
self.stalled = None
self.full_speed_ahead = True
self.transport.resumeProducing()
def handleResponseEnd(self):
if self.stalled:
print "CANCEL"
print("CANCEL")
self.stalled.cancel()
self.stalled = None
return tw_client.HTTPPageGetter.handleResponseEnd(self)
@ -101,7 +103,7 @@ class SystemFramework(pollmixin.PollMixin):
def _err(err):
self.failed = err
log.err(err)
print err
print(err)
d.addErrback(_err)
def _done(res):
reactor.stop()
@ -133,15 +135,15 @@ class SystemFramework(pollmixin.PollMixin):
return d
def record_initial_memusage(self):
print
print "Client started (no connections yet)"
print()
print("Client started (no connections yet)")
d = self._print_usage()
d.addCallback(self.stash_stats, "init")
return d
def wait_for_client_connected(self):
print
print "Client connecting to other nodes.."
print()
print("Client connecting to other nodes..")
return self.control_rref.callRemote("wait_for_client_connections",
self.numnodes+1)
@ -360,16 +362,16 @@ this file are ignored.
def _print_usage(self, res=None):
d = self.control_rref.callRemote("get_memory_usage")
def _print(stats):
print "VmSize: %9d VmPeak: %9d" % (stats["VmSize"],
stats["VmPeak"])
print("VmSize: %9d VmPeak: %9d" % (stats["VmSize"],
stats["VmPeak"]))
return stats
d.addCallback(_print)
return d
def _do_upload(self, res, size, files, uris):
name = '%d' % size
print
print "uploading %s" % name
print()
print("uploading %s" % name)
if self.mode in ("upload", "upload-self"):
d = self.control_rref.callRemote("upload_random_data_from_file",
size,
@ -400,7 +402,7 @@ this file are ignored.
raise ValueError("unknown mode=%s" % self.mode)
def _complete(uri):
uris[name] = uri
print "uploaded %s" % name
print("uploaded %s" % name)
d.addCallback(_complete)
return d
@ -408,7 +410,7 @@ this file are ignored.
if self.mode not in ("download", "download-GET", "download-GET-slow"):
return
name = '%d' % size
print "downloading %s" % name
print("downloading %s" % name)
uri = uris[name]
if self.mode == "download":
@ -422,7 +424,7 @@ this file are ignored.
d = self.GET_discard(urllib.quote(url), stall=True)
def _complete(res):
print "downloaded %s" % name
print("downloaded %s" % name)
return res
d.addCallback(_complete)
return d
@ -465,7 +467,7 @@ this file are ignored.
#d.addCallback(self.stall)
def _done(res):
print "FINISHING"
print("FINISHING")
d.addCallback(_done)
return d
@ -478,9 +480,9 @@ this file are ignored.
class ClientWatcher(protocol.ProcessProtocol):
ended = False
def outReceived(self, data):
print "OUT:", data
print("OUT:", data)
def errReceived(self, data):
print "ERR:", data
print("ERR:", data)
def processEnded(self, reason):
self.ended = reason
self.d.callback(None)
@ -496,7 +498,7 @@ if __name__ == '__main__':
bits = "64"
else:
bits = "?"
print "%s-bit system (sys.maxint=%d)" % (bits, sys.maxint)
print("%s-bit system (sys.maxint=%d)" % (bits, sys.maxint))
# put the logfile and stats.out in _test_memory/ . These stick around.
# put the nodes and other files in _test_memory/test/ . These are
# removed each time we run.

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os, sys
from twisted.internet import reactor, defer
from twisted.python import log
@ -23,7 +25,7 @@ class SpeedTest:
self.download_times = {}
def run(self):
print "STARTING"
print("STARTING")
d = fireEventually()
d.addCallback(lambda res: self.setUp())
d.addCallback(lambda res: self.do_test())
@ -31,7 +33,7 @@ class SpeedTest:
def _err(err):
self.failed = err
log.err(err)
print err
print(err)
d.addErrback(_err)
def _done(res):
reactor.stop()
@ -39,8 +41,8 @@ class SpeedTest:
d.addBoth(_done)
reactor.run()
if self.failed:
print "EXCEPTION"
print self.failed
print("EXCEPTION")
print(self.failed)
sys.exit(1)
def setUp(self):
@ -51,7 +53,7 @@ class SpeedTest:
d = self.tub.getReference(self.control_furl)
def _gotref(rref):
self.client_rref = rref
print "Got Client Control reference"
print("Got Client Control reference")
return self.stall(5)
d.addCallback(_gotref)
return d
@ -62,7 +64,7 @@ class SpeedTest:
return d
def record_times(self, times, key):
print "TIME (%s): %s up, %s down" % (key, times[0], times[1])
print("TIME (%s): %s up, %s down" % (key, times[0], times[1]))
self.upload_times[key], self.download_times[key] = times
def one_test(self, res, name, count, size, mutable):
@ -84,15 +86,15 @@ class SpeedTest:
self.total_rtt = sum(times)
self.average_rtt = sum(times) / len(times)
self.max_rtt = max(times)
print "num-peers: %d" % len(times)
print "total-RTT: %f" % self.total_rtt
print "average-RTT: %f" % self.average_rtt
print "max-RTT: %f" % self.max_rtt
print("num-peers: %d" % len(times))
print("total-RTT: %f" % self.total_rtt)
print("average-RTT: %f" % self.average_rtt)
print("max-RTT: %f" % self.max_rtt)
d.addCallback(_got)
return d
def do_test(self):
print "doing test"
print("doing test")
d = defer.succeed(None)
d.addCallback(self.one_test, "startup", 1, 1000, False) #ignore this one
d.addCallback(self.measure_rtt)
@ -103,7 +105,7 @@ class SpeedTest:
d.addCallback(self.one_test, "10x 200B", 10, 200, False)
def _maybe_do_100x_200B(res):
if self.upload_times["10x 200B"] < 5:
print "10x 200B test went too fast, doing 100x 200B test"
print("10x 200B test went too fast, doing 100x 200B test")
return self.one_test(None, "100x 200B", 100, 200, False)
return
d.addCallback(_maybe_do_100x_200B)
@ -111,7 +113,7 @@ class SpeedTest:
d.addCallback(self.one_test, "10MB", 1, 10*MB, False)
def _maybe_do_100MB(res):
if self.upload_times["10MB"] > 30:
print "10MB test took too long, skipping 100MB test"
print("10MB test took too long, skipping 100MB test")
return
return self.one_test(None, "100MB", 1, 100*MB, False)
d.addCallback(_maybe_do_100MB)
@ -126,7 +128,7 @@ class SpeedTest:
d.addCallback(self.one_test, "10x 200B SSK", 10, 200, "upload")
def _maybe_do_100x_200B_SSK(res):
if self.upload_times["10x 200B SSK"] < 5:
print "10x 200B SSK test went too fast, doing 100x 200B SSK"
print("10x 200B SSK test went too fast, doing 100x 200B SSK")
return self.one_test(None, "100x 200B SSK", 100, 200,
"upload")
return
@ -146,37 +148,37 @@ class SpeedTest:
B = self.upload_times["100x 200B"] / 100
else:
B = self.upload_times["10x 200B"] / 10
print "upload per-file time: %.3fs" % B
print "upload per-file times-avg-RTT: %f" % (B / self.average_rtt)
print "upload per-file times-total-RTT: %f" % (B / self.total_rtt)
print("upload per-file time: %.3fs" % B)
print("upload per-file times-avg-RTT: %f" % (B / self.average_rtt))
print("upload per-file times-total-RTT: %f" % (B / self.total_rtt))
A1 = 1*MB / (self.upload_times["1MB"] - B) # in bytes per second
print "upload speed (1MB):", self.number(A1, "Bps")
print("upload speed (1MB):", self.number(A1, "Bps"))
A2 = 10*MB / (self.upload_times["10MB"] - B)
print "upload speed (10MB):", self.number(A2, "Bps")
print("upload speed (10MB):", self.number(A2, "Bps"))
if "100MB" in self.upload_times:
A3 = 100*MB / (self.upload_times["100MB"] - B)
print "upload speed (100MB):", self.number(A3, "Bps")
print("upload speed (100MB):", self.number(A3, "Bps"))
# download
if "100x 200B" in self.download_times:
B = self.download_times["100x 200B"] / 100
else:
B = self.download_times["10x 200B"] / 10
print "download per-file time: %.3fs" % B
print "download per-file times-avg-RTT: %f" % (B / self.average_rtt)
print "download per-file times-total-RTT: %f" % (B / self.total_rtt)
print("download per-file time: %.3fs" % B)
print("download per-file times-avg-RTT: %f" % (B / self.average_rtt))
print("download per-file times-total-RTT: %f" % (B / self.total_rtt))
A1 = 1*MB / (self.download_times["1MB"] - B) # in bytes per second
print "download speed (1MB):", self.number(A1, "Bps")
print("download speed (1MB):", self.number(A1, "Bps"))
A2 = 10*MB / (self.download_times["10MB"] - B)
print "download speed (10MB):", self.number(A2, "Bps")
print("download speed (10MB):", self.number(A2, "Bps"))
if "100MB" in self.download_times:
A3 = 100*MB / (self.download_times["100MB"] - B)
print "download speed (100MB):", self.number(A3, "Bps")
print("download speed (100MB):", self.number(A3, "Bps"))
if self.DO_MUTABLE_CREATE:
# SSK creation
B = self.upload_times["10x 200B SSK creation"] / 10
print "create per-file time SSK: %.3fs" % B
print("create per-file time SSK: %.3fs" % B)
if self.DO_MUTABLE:
# upload SSK
@ -184,19 +186,19 @@ class SpeedTest:
B = self.upload_times["100x 200B SSK"] / 100
else:
B = self.upload_times["10x 200B SSK"] / 10
print "upload per-file time SSK: %.3fs" % B
print("upload per-file time SSK: %.3fs" % B)
A1 = 1*MB / (self.upload_times["1MB SSK"] - B) # in bytes per second
print "upload speed SSK (1MB):", self.number(A1, "Bps")
print("upload speed SSK (1MB):", self.number(A1, "Bps"))
# download SSK
if "100x 200B SSK" in self.download_times:
B = self.download_times["100x 200B SSK"] / 100
else:
B = self.download_times["10x 200B SSK"] / 10
print "download per-file time SSK: %.3fs" % B
print("download per-file time SSK: %.3fs" % B)
A1 = 1*MB / (self.download_times["1MB SSK"] - B) # in bytes per
# second
print "download speed SSK (1MB):", self.number(A1, "Bps")
print("download speed SSK (1MB):", self.number(A1, "Bps"))
def number(self, value, suffix=""):
scaling = 1

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os.path, json
from twisted.trial import unittest
from twisted.python import usage
@ -976,8 +978,8 @@ class CopyOut(GridTestMixin, CLITestMixin, unittest.TestCase):
def _dump(got):
ok = "ok" if got == expected else "FAIL"
printable_got = ",".join(sorted(got))
print "%-31s: got %-19s, want %-19s %s" % (case, printable_got,
printable_expected, ok)
print("%-31s: got %-19s, want %-19s %s" % (case, printable_got,
printable_expected, ok))
return got
#d.addCallback(_dump)
def _check(got):

View File

@ -1,3 +1,5 @@
from __future__ import print_function
__all__ = [
"SyncTestCase",
"AsyncTestCase",
@ -512,7 +514,7 @@ class WebErrorMixin:
# this method as an errback handler, and it will reveal the hidden
# message.
f.trap(WebError)
print "Web Error:", f.value, ":", f.value.response
print("Web Error:", f.value, ":", f.value.response)
return f
def _shouldHTTPError(self, res, which, validator):
@ -561,7 +563,7 @@ class WebErrorMixin:
class ErrorMixin(WebErrorMixin):
def explain_error(self, f):
if f.check(defer.FirstError):
print "First Error:", f.value.subFailure
print("First Error:", f.value.subFailure)
return f
def corrupt_field(data, offset, size, debug=False):

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os, signal, sys, time
from random import randrange
from six.moves import StringIO
@ -99,7 +101,7 @@ class NonASCIIPathMixin:
if os.path.exists(dirpath):
msg = ("We were unable to delete a non-ASCII directory %r created by the test. "
"This is liable to cause failures on future builds." % (dirpath,))
print msg
print(msg)
log.err(msg)
self.addCleanup(_cleanup)
os.mkdir(dirpath)
@ -228,7 +230,7 @@ class TestMixin(SignalMixin):
if p.active():
p.cancel()
else:
print "WEIRDNESS! pending timed call not active!"
print("WEIRDNESS! pending timed call not active!")
if required_to_quiesce and active:
self.fail("Reactor was still active when it was required to be quiescent.")

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os, base64
from twisted.trial import unittest
from twisted.internet import defer
@ -236,9 +238,9 @@ class Problems(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin):
d.addCallback(lambda res: n.download_best_version())
d.addCallback(lambda res: self.failUnlessEqual(res, "contents 2"))
def _explain_error(f):
print f
print(f)
if f.check(NotEnoughServersError):
print "first_error:", f.value.first_error
print("first_error:", f.value.first_error)
return f
d.addErrback(_explain_error)
return d

View File

@ -1,3 +1,5 @@
from __future__ import print_function
from cStringIO import StringIO
from twisted.trial import unittest
@ -41,11 +43,11 @@ class Roundtrip(unittest.TestCase, testutil.ShouldFailMixin, PublishMixin):
return output
def dump_servermap(self, servermap):
print "SERVERMAP", servermap
print "RECOVERABLE", [self.abbrev_verinfo(v)
for v in servermap.recoverable_versions()]
print "BEST", self.abbrev_verinfo(servermap.best_recoverable_version())
print "available", self.abbrev_verinfo_dict(servermap.shares_available())
print("SERVERMAP", servermap)
print("RECOVERABLE", [self.abbrev_verinfo(v)
for v in servermap.recoverable_versions()])
print("BEST", self.abbrev_verinfo(servermap.best_recoverable_version()))
print("available", self.abbrev_verinfo_dict(servermap.shares_available()))
def do_download(self, servermap, version=None):
if version is None:

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import re
from twisted.trial import unittest
from twisted.internet import defer
@ -56,9 +58,9 @@ class Update(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin):
d.addCallback(lambda ign: self.mdmf_node.download_best_version())
def _check(results):
if results != expected:
print
print "got: %s ... %s" % (results[:20], results[-20:])
print "exp: %s ... %s" % (expected[:20], expected[-20:])
print()
print("got: %s ... %s" % (results[:20], results[-20:]))
print("exp: %s ... %s" % (expected[:20], expected[-20:]))
self.fail("results != expected")
d.addCallback(_check)
return d
@ -111,21 +113,21 @@ class Update(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin):
#print "expecting: %s" % expspans
if got != expected:
print "differences:"
print("differences:")
for segnum in range(len(expected)//SEGSIZE):
start = segnum * SEGSIZE
end = (segnum+1) * SEGSIZE
got_ends = "%s .. %s" % (got[start:start+20], got[end-20:end])
exp_ends = "%s .. %s" % (expected[start:start+20], expected[end-20:end])
if got_ends != exp_ends:
print "expected[%d]: %s" % (start, exp_ends)
print "got [%d]: %s" % (start, got_ends)
print("expected[%d]: %s" % (start, exp_ends))
print("got [%d]: %s" % (start, got_ends))
if expspans != gotspans:
print "expected: %s" % expspans
print "got : %s" % gotspans
print("expected: %s" % expspans)
print("got : %s" % gotspans)
open("EXPECTED","wb").write(expected)
open("GOT","wb").write(got)
print "wrote data to EXPECTED and GOT"
print("wrote data to EXPECTED and GOT")
self.fail("didn't get expected data")

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os
from cStringIO import StringIO
from twisted.internet import defer
@ -346,10 +348,10 @@ class Version(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin, \
d.addCallback(lambda ignored: "".join(c.chunks))
def _check(results):
if results != expected_range:
print "read([%d]+%s) got %d bytes, not %d" % \
(offset, length, len(results), len(expected_range))
print "got: %s ... %s" % (results[:20], results[-20:])
print "exp: %s ... %s" % (expected_range[:20], expected_range[-20:])
print("read([%d]+%s) got %d bytes, not %d" % \
(offset, length, len(results), len(expected_range)))
print("got: %s ... %s" % (results[:20], results[-20:]))
print("exp: %s ... %s" % (expected_range[:20], expected_range[-20:]))
self.fail("results[%s] != expected_range" % name)
return version # daisy-chained to next call
d.addCallback(_check)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import time
import os.path
@ -373,9 +374,9 @@ class Basic(unittest.TestCase, StallMixin, pollmixin.PollMixin):
# our buildslaves vary too much in their speeds and load levels,
# and many of them only manage to hit 7% usage when our target is
# 50%. So don't assert anything about the results, just log them.
print
print "crawler: got %d%% percent when trying for 50%%" % percent
print "crawler: got %d full cycles" % c.cycles
print()
print("crawler: got %d%% percent when trying for 50%%" % percent)
print("crawler: got %d full cycles" % c.cycles)
d.addCallback(_done)
return d

View File

@ -1,3 +1,4 @@
from __future__ import print_function
# system-level upload+download roundtrip test, but using shares created from
# a previous run. This asserts that the current code is capable of decoding
@ -1065,8 +1066,8 @@ class Corruption(_Base, unittest.TestCase):
d.addCallback(_uploaded)
def _show_results(ign):
share_len = len(self.shares.values()[0])
print
print ("of [0:%d], corruption ignored in %s" %
print()
print("of [0:%d], corruption ignored in %s" %
(share_len, undetected.dump()))
if self.catalog_detection:
d.addCallback(_show_results)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
lumiere_nfc = u"lumi\u00E8re"
Artonwall_nfc = u"\u00C4rtonwall.mp3"
@ -19,24 +20,24 @@ if __name__ == "__main__":
import platform
if len(sys.argv) != 2:
print "Usage: %s lumi<e-grave>re" % sys.argv[0]
print("Usage: %s lumi<e-grave>re" % sys.argv[0])
sys.exit(1)
if sys.platform == "win32":
try:
from allmydata.windows.fixups import initialize
except ImportError:
print "set PYTHONPATH to the src directory"
print("set PYTHONPATH to the src directory")
sys.exit(1)
initialize()
print
print "class MyWeirdOS(EncodingUtil, unittest.TestCase):"
print " uname = '%s'" % ' '.join(platform.uname())
print " argv = %s" % repr(sys.argv[1])
print " platform = '%s'" % sys.platform
print " filesystem_encoding = '%s'" % sys.getfilesystemencoding()
print " io_encoding = '%s'" % sys.stdout.encoding
print()
print("class MyWeirdOS(EncodingUtil, unittest.TestCase):")
print(" uname = '%s'" % ' '.join(platform.uname()))
print(" argv = %s" % repr(sys.argv[1]))
print(" platform = '%s'" % sys.platform)
print(" filesystem_encoding = '%s'" % sys.getfilesystemencoding())
print(" io_encoding = '%s'" % sys.stdout.encoding)
try:
tmpdir = tempfile.mkdtemp()
for fname in TEST_FILENAMES:
@ -48,10 +49,10 @@ if __name__ == "__main__":
else:
dirlist = os.listdir(tmpdir)
print " dirlist = %s" % repr(dirlist)
print(" dirlist = %s" % repr(dirlist))
except:
print " # Oops, I cannot write filenames containing non-ascii characters"
print
print(" # Oops, I cannot write filenames containing non-ascii characters")
print()
shutil.rmtree(tmpdir)
sys.exit(0)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import os, sys, time
import stat, shutil, json
@ -1340,12 +1341,12 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
bob_clock = self.bob_magicfolder.uploader._clock
def _wait_for_Alice(ign, downloaded_d):
if _debug: print "Now waiting for Alice to download\n"
if _debug: print("Now waiting for Alice to download\n")
alice_clock.advance(4)
return downloaded_d
def _wait_for_Bob(ign, downloaded_d):
if _debug: print "Now waiting for Bob to download\n"
if _debug: print("Now waiting for Bob to download\n")
bob_clock.advance(4)
return downloaded_d
@ -1361,11 +1362,11 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
def advance(ign):
if alice:
if _debug: print "Waiting for Alice to upload 3\n"
if _debug: print("Waiting for Alice to upload 3\n")
alice_clock.advance(4)
uploaded_d.addCallback(_wait_for_Bob, downloaded_d)
else:
if _debug: print "Waiting for Bob to upload\n"
if _debug: print("Waiting for Bob to upload\n")
bob_clock.advance(4)
uploaded_d.addCallback(_wait_for_Alice, downloaded_d)
return uploaded_d
@ -1374,7 +1375,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@inline_callbacks
def Alice_to_write_a_file():
if _debug: print "Alice writes a file\n\n\n\n\n"
if _debug: print("Alice writes a file\n\n\n\n\n")
self.file_path = abspath_expanduser_unicode(u"file1", base=self.alice_magicfolder.uploader._local_path_u)
yield self.alice_fileops.write(self.file_path, "meow, meow meow. meow? meow meow! meow.")
yield iterate(self.alice_magicfolder)
@ -1402,7 +1403,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@inline_callbacks
def Alice_to_delete_file():
if _debug: print "Alice deletes the file!\n\n\n\n"
if _debug: print("Alice deletes the file!\n\n\n\n")
yield self.alice_fileops.delete(self.file_path)
yield iterate(self.alice_magicfolder)
yield iterate(self.bob_magicfolder)
@ -1438,7 +1439,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@inline_callbacks
def Alice_to_rewrite_file():
if _debug: print "Alice rewrites file\n"
if _debug: print("Alice rewrites file\n")
self.file_path = abspath_expanduser_unicode(u"file1", base=self.alice_magicfolder.uploader._local_path_u)
yield self.alice_fileops.write(
self.file_path,
@ -1472,7 +1473,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
encoded_path_u = magicpath.path2magic(u"/tmp/magic_folder_test")
def Alice_tries_to_p0wn_Bob(ign):
if _debug: print "Alice tries to p0wn Bob\n"
if _debug: print("Alice tries to p0wn Bob\n")
iter_d = iterate(self.bob_magicfolder)
processed_d = self.bob_magicfolder.downloader.set_hook('processed')
@ -1498,9 +1499,9 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@inline_callbacks
def Bob_to_rewrite_file():
if _debug: print "Bob rewrites file\n"
if _debug: print("Bob rewrites file\n")
self.file_path = abspath_expanduser_unicode(u"file1", base=self.bob_magicfolder.uploader._local_path_u)
if _debug: print "---- bob's file is %r" % (self.file_path,)
if _debug: print("---- bob's file is %r" % (self.file_path,))
yield self.bob_fileops.write(self.file_path, "No white rabbit to be found.")
yield iterate(self.bob_magicfolder)
d.addCallback(lambda ign: _wait_for(None, Bob_to_rewrite_file, alice=False))
@ -1525,7 +1526,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
d.addCallback(check_state)
def Alice_conflicts_with_Bobs_last_downloaded_uri():
if _debug: print "Alice conflicts with Bob\n"
if _debug: print("Alice conflicts with Bob\n")
downloaded_d = self.bob_magicfolder.downloader.set_hook('processed')
uploadable = Data("do not follow the white rabbit", self.alice_magicfolder._client.convergence)
alice_dmd = self.alice_magicfolder.uploader._upload_dirnode
@ -1533,7 +1534,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
metadata={"version": 5,
"last_downloaded_uri" : "URI:LIT:" },
overwrite=True)
if _debug: print "Waiting for Alice to upload\n"
if _debug: print("Waiting for Alice to upload\n")
d2.addCallback(lambda ign: bob_clock.advance(6))
d2.addCallback(lambda ign: downloaded_d)
d2.addCallback(lambda ign: self.failUnless(alice_dmd.has_child(encoded_path_u)))
@ -1555,7 +1556,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@log_call_deferred(action_type=u"alice:to-write:file2")
@inline_callbacks
def Alice_to_write_file2():
if _debug: print "Alice writes a file2\n"
if _debug: print("Alice writes a file2\n")
self.file_path = abspath_expanduser_unicode(u"file2", base=self.alice_magicfolder.uploader._local_path_u)
d = self.alice_fileops.write(self.file_path, "something")
self.bob_clock.advance(4)
@ -1588,14 +1589,14 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@inline_callbacks
def Bob_to_rewrite_file2():
if _debug: print "Bob rewrites file2\n"
if _debug: print("Bob rewrites file2\n")
self.file_path = abspath_expanduser_unicode(u"file2", base=self.bob_magicfolder.uploader._local_path_u)
if _debug: print "---- bob's file is %r" % (self.file_path,)
if _debug: print("---- bob's file is %r" % (self.file_path,))
yield iterate(self.bob_magicfolder)
yield self.bob_fileops.write(self.file_path, "roger roger. what vector?")
if _debug: print "---- bob rewrote file2"
if _debug: print("---- bob rewrote file2")
yield iterate(self.bob_magicfolder)
if _debug: print "---- iterated bob's magicfolder"
if _debug: print("---- iterated bob's magicfolder")
d.addCallback(lambda ign: _wait_for(None, Bob_to_rewrite_file2, alice=False))
@log_call_deferred(action_type=u"check_state")
@ -1636,7 +1637,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
d.addCallback(check_state)
def Alice_conflicts_with_Bobs_last_uploaded_uri():
if _debug: print "Alice conflicts with Bob\n"
if _debug: print("Alice conflicts with Bob\n")
encoded_path_u = magicpath.path2magic(u"file2")
downloaded_d = self.bob_magicfolder.downloader.set_hook('processed')
uploadable = Data("rabbits with sharp fangs", self.alice_magicfolder._client.convergence)
@ -1645,7 +1646,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
metadata={"version": 5,
"last_uploaded_uri" : "URI:LIT:" },
overwrite=True)
if _debug: print "Waiting for Alice to upload\n"
if _debug: print("Waiting for Alice to upload\n")
d2.addCallback(lambda ign: bob_clock.advance(6))
d2.addCallback(lambda ign: downloaded_d)
d2.addCallback(lambda ign: self.failUnless(alice_dmd.has_child(encoded_path_u)))
@ -1685,7 +1686,7 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
# prepare to perform another conflict test
@inline_callbacks
def Alice_to_write_file3():
if _debug: print "Alice writes a file\n"
if _debug: print("Alice writes a file\n")
self.file_path = abspath_expanduser_unicode(u"file3", base=self.alice_magicfolder.uploader._local_path_u)
yield self.alice_fileops.write(self.file_path, "something")
yield iterate(self.alice_magicfolder)
@ -1706,9 +1707,9 @@ class MagicFolderAliceBobTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Rea
@inline_callbacks
def Bob_to_rewrite_file3():
if _debug: print "Bob rewrites file3\n"
if _debug: print("Bob rewrites file3\n")
self.file_path = abspath_expanduser_unicode(u"file3", base=self.bob_magicfolder.uploader._local_path_u)
if _debug: print "---- bob's file is %r" % (self.file_path,)
if _debug: print("---- bob's file is %r" % (self.file_path,))
yield iterate(self.bob_magicfolder)
yield self.bob_fileops.write(self.file_path, "roger roger")
yield iterate(self.bob_magicfolder)

View File

@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from allmydata.test import common
from allmydata.monitor import Monitor
from allmydata import check_results
@ -348,9 +350,9 @@ class Verifier(GridTestMixin, unittest.TestCase, RepairTestMixin):
def _show_results(ign):
f = open("test_each_byte_output", "w")
for i in sorted(results.keys()):
print >>f, "%d: %s" % (i, results[i])
print("%d: %s" % (i, results[i]), file=f)
f.close()
print "Please look in _trial_temp/test_each_byte_output for results"
print("Please look in _trial_temp/test_each_byte_output for results")
d.addCallback(_show_results)
return d

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import re, struct, traceback, time, calendar
from stat import S_IFREG, S_IFDIR
@ -54,7 +55,7 @@ class Handler(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, unittest.TestCas
"%s was supposed to raise SFTPError(%r), not SFTPError(%r): %s" %
(which, expected_code, res.value.code, res))
else:
print '@' + '@'.join(s)
print('@' + '@'.join(s))
self.fail("%s was supposed to raise SFTPError(%r), not get %r" %
(which, expected_code, res))
d.addBoth(_done)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import os, re, sys, time, json
from functools import partial
@ -1303,9 +1304,9 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
base32.b2a(storage_index))
self.failUnless(expected in output)
except unittest.FailTest:
print
print "dump-share output was:"
print output
print()
print("dump-share output was:")
print(output)
raise
d.addCallback(_test_debug)
@ -1550,9 +1551,9 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
self.failUnless("Subscription Summary: storage: 5" in res)
self.failUnless("tahoe.css" in res)
except unittest.FailTest:
print
print "GET %s output was:" % self.introweb_url
print res
print()
print("GET %s output was:" % self.introweb_url)
print(res)
raise
d.addCallback(_check)
# make sure it serves the CSS too
@ -1566,9 +1567,9 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
self.failUnlessEqual(data["announcement_summary"],
{"storage": 5})
except unittest.FailTest:
print
print "GET %s?t=json output was:" % self.introweb_url
print res
print()
print("GET %s?t=json output was:" % self.introweb_url)
print(res)
raise
d.addCallback(_check_json)
return d

View File

@ -1,3 +1,5 @@
from __future__ import print_function
def foo(): pass # keep the line number constant
@ -49,7 +51,7 @@ class NoArgumentException(Exception):
class HumanReadable(unittest.TestCase):
def test_repr(self):
hr = humanreadable.hr
self.failUnlessEqual(hr(foo), "<foo() at test_util.py:2>")
self.failUnlessEqual(hr(foo), "<foo() at test_util.py:4>")
self.failUnlessEqual(hr(self.test_repr),
"<bound method HumanReadable.test_repr of <allmydata.test.test_util.HumanReadable testMethod=test_repr>>")
self.failUnlessEqual(hr(1L), "1")
@ -2084,13 +2086,13 @@ class StringSpans(unittest.TestCase):
p_added = set(range(start, end))
b = base()
if DEBUG:
print
print dump(b), which
print()
print(dump(b), which)
add = klass(); add.add(start, S[start:end])
print dump(add)
print(dump(add))
b.add(start, S[start:end])
if DEBUG:
print dump(b)
print(dump(b))
# check that the new span is there
d = b.get(start, end-start)
self.failUnlessEqual(d, S[start:end], which)

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os.path, re, urllib
import json
from StringIO import StringIO
@ -611,8 +613,8 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
for line in res.splitlines()
if line]
except ValueError:
print "response is:", res
print "undecodeable line was '%s'" % line
print("response is:", res)
print("undecodeable line was '%s'" % line)
raise
self.failUnlessReallyEqual(len(units), 5+1)
# should be parent-first

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os.path, re, urllib, time, cgi
import json
import treq
@ -2441,10 +2443,10 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
return d
def dump_root(self):
print "NODEWALK"
print("NODEWALK")
w = webish.DirnodeWalkerMixin()
def visitor(childpath, childnode, metadata):
print childpath
print(childpath)
d = w.walk(self.public_root, visitor)
return d
@ -2886,9 +2888,9 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
# will be rather terse and unhelpful. addErrback this method to the
# end of your chain to get more information out of these errors.
if f.check(error.Error):
print "web.error.Error:"
print f
print f.value.response
print("web.error.Error:")
print(f)
print(f.value.response)
return f
def test_POST_upload_replace(self):