Make new code more idiomatic

This commit is contained in:
Chad Whitacre 2020-09-23 08:24:39 -04:00
parent de48dff981
commit 9fccf37053
2 changed files with 3 additions and 3 deletions

View File

@ -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)

View File

@ -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')