mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-29 17:28:53 +00:00
Make new code more idiomatic
This commit is contained in:
parent
de48dff981
commit
9fccf37053
@ -73,7 +73,7 @@ def flip_bit(good, which):
|
||||
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. """
|
||||
assert isinstance(s, binary_type)
|
||||
precondition(isinstance(s, binary_type))
|
||||
if size is None:
|
||||
size=len(s)-offset
|
||||
i = randrange(offset, offset+size)
|
||||
|
@ -22,9 +22,9 @@ class TestFlipOneBit(unittest.TestCase):
|
||||
def setUp(self):
|
||||
random.seed(42) # I tried using version=1 on PY3 to avoid the if below, to no avail.
|
||||
|
||||
def test_bytestring(self):
|
||||
def test_accepts_byte_string(self):
|
||||
actual = flip_one_bit(b'foo')
|
||||
self.assertEqual(actual, b'fno' if PY2 else b'fom')
|
||||
|
||||
def test_unicode(self):
|
||||
def test_rejects_unicode_string(self):
|
||||
self.assertRaises(AssertionError, flip_one_bit, u'foo')
|
||||
|
Loading…
Reference in New Issue
Block a user