From: Brian Warner Date: Wed, 29 Oct 2008 04:28:31 +0000 (-0700) Subject: move testutil into test/common_util.py, since it doesn't count as 'code under test... X-Git-Url: https://git.rkrishnan.org/CLI.txt?a=commitdiff_plain;h=b73c380cdb3bb272843c3853b1404ddce981a492;p=tahoe-lafs%2Ftahoe-lafs.git move testutil into test/common_util.py, since it doesn't count as 'code under test' for our pyflakes numbers --- diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 3fd6b6a3..af86e77a 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -16,9 +16,10 @@ from allmydata.checker_results import CheckerResults, CheckAndRepairResults, \ DeepCheckResults, DeepCheckAndRepairResults from allmydata.mutable.common import CorruptShareError from allmydata.storage import storage_index_to_dir -from allmydata.util import log, testutil, fileutil, pollmixin +from allmydata.util import log, fileutil, pollmixin from allmydata.stats import PickleStatsGatherer from allmydata.key_generator import KeyGeneratorService +import common_util as testutil def flush_but_dont_ignore(res): diff --git a/src/allmydata/test/common_util.py b/src/allmydata/test/common_util.py new file mode 100644 index 00000000..27d6b434 --- /dev/null +++ b/src/allmydata/test/common_util.py @@ -0,0 +1,151 @@ +import os, signal, time +from random import randrange + +from twisted.internet import reactor, defer +from twisted.python import failure + +def insecurerandstr(n): + return ''.join(map(chr, map(randrange, [0]*n, [256]*n))) + +def flip_bit(good, which): + # flip the low-order bit of good[which] + if which == -1: + pieces = good[:which], good[-1:], "" + else: + pieces = good[:which], good[which:which+1], good[which+1:] + return pieces[0] + chr(ord(pieces[1]) ^ 0x01) + pieces[2] + +def flip_one_bit(s, offset=0, size=None): + """ flip one random bit of the string s, in a byte greater than or equal to offset and less + than offset+size. """ + if size is None: + size=len(s)-offset + i = randrange(offset, offset+size) + result = s[:i] + chr(ord(s[i])^(0x01<