From 1d85a2c5cf40a4e52bbb024e2edba4fcd883caa1 Mon Sep 17 00:00:00 2001 From: "Fon E. Noel NFEBE" Date: Sun, 20 Nov 2022 14:02:49 +0100 Subject: [PATCH] Refactor more test_storage.py classes As a follow up to commit fbc8baa238f72720cfa840a9c227c670a5e2fa6e this refactor continues to remove deprecated methods and ensures test classes either extend `SyncTestCase` or `AsyncTestCase` Classes refactored: - `MutableServer` - `MDMFProxies` - `Stats` - `MutableShareFileTests` Signed-off-by: Fon E. Noel NFEBE --- src/allmydata/test/test_storage.py | 654 ++++++++++++++--------------- 1 file changed, 327 insertions(+), 327 deletions(-) diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 920f2d935..3d35ec55f 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -470,7 +470,7 @@ class BucketProxy(SyncTestCase): num_segments=5, num_share_hashes=3, uri_extension_size=500) - self.failUnless(interfaces.IStorageBucketWriter.providedBy(bp), bp) + self.assertTrue(interfaces.IStorageBucketWriter.providedBy(bp), bp) def _do_test_readwrite(self, name, header_size, wbp_class, rbp_class): # Let's pretend each share has 100 bytes of data, and that there are @@ -520,7 +520,7 @@ class BucketProxy(SyncTestCase): server = NoNetworkServer(b"abc", None) rbp = rbp_class(rb, server, storage_index=b"") self.assertThat(repr(rbp), Contains("to peer")) - self.failUnless(interfaces.IStorageBucketReader.providedBy(rbp), rbp) + self.assertTrue(interfaces.IStorageBucketReader.providedBy(rbp), rbp) d1 = rbp.get_block_data(0, 25, 25) d1.addCallback(lambda res: self.failUnlessEqual(res, b"a"*25)) @@ -1281,7 +1281,7 @@ class Server(AsyncTestCase): ) -class MutableServer(unittest.TestCase): +class MutableServer(SyncTestCase): def setUp(self): self.sparent = LoggingServiceParent() @@ -1311,13 +1311,13 @@ class MutableServer(unittest.TestCase): def renew_secret(self, tag): if isinstance(tag, int): tag = b"%d" % (tag,) - assert isinstance(tag, bytes) + self.assertThat(tag, IsInstance(bytes)) return hashutil.tagged_hash(b"renew_blah", tag) def cancel_secret(self, tag): if isinstance(tag, int): tag = b"%d" % (tag,) - assert isinstance(tag, bytes) + self.assertThat(tag, IsInstance(bytes)) return hashutil.tagged_hash(b"cancel_blah", tag) def allocate(self, ss, storage_index, we_tag, lease_tag, sharenums, size): @@ -1333,9 +1333,9 @@ class MutableServer(unittest.TestCase): testandwritev, readv) (did_write, readv_data) = rc - self.failUnless(did_write) - self.failUnless(isinstance(readv_data, dict)) - self.failUnlessEqual(len(readv_data), 0) + self.assertTrue(did_write) + self.assertThat(readv_data, IsInstance(dict)) + self.assertThat(readv_data, HasLength(0)) def test_enumerate_mutable_shares(self): """ @@ -1357,9 +1357,9 @@ class MutableServer(unittest.TestCase): self.cancel_secret(b"le1")) ss.slot_testv_and_readv_and_writev(b"si1", secrets, {2: ([], [], 0)}, []) shares0_1_4 = ss.enumerate_mutable_shares(b"si1") - self.assertEqual( + self.assertThat( (empty, shares0_1_2_4, shares0_1_4), - (set(), {0, 1, 2, 4}, {0, 1, 4}) + Equals((set(), {0, 1, 2, 4}, {0, 1, 4})) ) def test_mutable_share_length(self): @@ -1373,7 +1373,7 @@ class MutableServer(unittest.TestCase): {16: ([], [(0, b"x" * 23)], None)}, [] ) - self.assertEqual(ss.get_mutable_share_length(b"si1", 16), 23) + self.assertThat(ss.get_mutable_share_length(b"si1", 16), Equals(23)) def test_mutable_share_length_unknown(self): """ @@ -1406,10 +1406,10 @@ class MutableServer(unittest.TestCase): read = ss.slot_readv e = self.failUnlessRaises(UnknownMutableContainerVersionError, read, b"si1", [0], [(0,10)]) - self.assertEqual(e.filename, fn) + self.assertThat(e.filename, Equals(fn)) self.assertTrue(e.version.startswith(b"BAD MAGIC")) - self.assertIn("had unexpected version", str(e)) - self.assertIn("BAD MAGIC", str(e)) + self.assertThat(str(e), Contains("had unexpected version")) + self.assertThat(str(e), Contains("BAD MAGIC")) def test_container_size(self): ss = self.create("test_container_size") @@ -1424,7 +1424,7 @@ class MutableServer(unittest.TestCase): answer = rstaraw(b"si1", secrets, {0: ([], [(0,data)], len(data)+12)}, []) - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) + self.assertThat(answer, Equals((True, {0:[],1:[],2:[]}))) # Trying to make the container too large (by sending a write vector # whose offset is too high) will raise an exception. @@ -1437,10 +1437,10 @@ class MutableServer(unittest.TestCase): answer = rstaraw(b"si1", secrets, {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) + self.assertThat(answer, Equals((True, {0:[],1:[],2:[]}))) read_answer = read(b"si1", [0], [(0,10)]) - self.failUnlessEqual(read_answer, {0: [data[:10]]}) + self.assertThat(read_answer, Equals({0: [data[:10]]})) # Sending a new_length shorter than the current length truncates the # data. @@ -1448,7 +1448,7 @@ class MutableServer(unittest.TestCase): {0: ([], [], 9)}, []) read_answer = read(b"si1", [0], [(0,10)]) - self.failUnlessEqual(read_answer, {0: [data[:9]]}) + self.assertThat(read_answer, Equals({0: [data[:9]]})) # Sending a new_length longer than the current length doesn't change # the data. @@ -1457,7 +1457,7 @@ class MutableServer(unittest.TestCase): []) assert answer == (True, {0:[],1:[],2:[]}) read_answer = read(b"si1", [0], [(0, 20)]) - self.failUnlessEqual(read_answer, {0: [data[:9]]}) + self.assertThat(read_answer, Equals({0: [data[:9]]})) # Sending a write vector whose start is after the end of the current # data doesn't reveal "whatever was there last time" (palimpsest), @@ -1479,7 +1479,7 @@ class MutableServer(unittest.TestCase): answer = rstaraw(b"si1", secrets, {0: ([], [], None)}, [(20, 1980)]) - self.failUnlessEqual(answer, (True, {0:[b''],1:[b''],2:[b'']})) + self.assertThat(answer, Equals((True, {0:[b''],1:[b''],2:[b'']}))) # Then the extend the file by writing a vector which starts out past # the end... @@ -1492,22 +1492,22 @@ class MutableServer(unittest.TestCase): answer = rstaraw(b"si1", secrets, {0: ([], [], None)}, [(20, 30)]) - self.failUnlessEqual(answer, (True, {0:[b'\x00'*30],1:[b''],2:[b'']})) + self.assertThat(answer, Equals((True, {0:[b'\x00'*30],1:[b''],2:[b'']}))) # Also see if the server explicitly declares that it supports this # feature. ver = ss.get_version() storage_v1_ver = ver[b"http://allmydata.org/tahoe/protocols/storage/v1"] - self.failUnless(storage_v1_ver.get(b"fills-holes-with-zero-bytes")) + self.assertTrue(storage_v1_ver.get(b"fills-holes-with-zero-bytes")) # If the size is dropped to zero the share is deleted. answer = rstaraw(b"si1", secrets, {0: ([], [(0,data)], 0)}, []) - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) + self.assertThat(answer, Equals((True, {0:[],1:[],2:[]}))) read_answer = read(b"si1", [0], [(0,10)]) - self.failUnlessEqual(read_answer, {}) + self.assertThat(read_answer, Equals({})) def test_allocate(self): ss = self.create("test_allocate") @@ -1515,12 +1515,12 @@ class MutableServer(unittest.TestCase): set([0,1,2]), 100) read = ss.slot_readv - self.failUnlessEqual(read(b"si1", [0], [(0, 10)]), - {0: [b""]}) - self.failUnlessEqual(read(b"si1", [], [(0, 10)]), - {0: [b""], 1: [b""], 2: [b""]}) - self.failUnlessEqual(read(b"si1", [0], [(100, 10)]), - {0: [b""]}) + self.assertThat(read(b"si1", [0], [(0, 10)]), + Equals({0: [b""]})) + self.assertThat(read(b"si1", [], [(0, 10)]), + Equals({0: [b""], 1: [b""], 2: [b""]})) + self.assertThat(read(b"si1", [0], [(100, 10)]), + Equals({0: [b""]})) # try writing to one secrets = ( self.write_enabler(b"we1"), @@ -1531,19 +1531,19 @@ class MutableServer(unittest.TestCase): answer = write(b"si1", secrets, {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) + self.assertThat(answer, Equals((True, {0:[],1:[],2:[]}))) - self.failUnlessEqual(read(b"si1", [0], [(0,20)]), - {0: [b"00000000001111111111"]}) - self.failUnlessEqual(read(b"si1", [0], [(95,10)]), - {0: [b"99999"]}) + self.assertThat(read(b"si1", [0], [(0,20)]), + Equals({0: [b"00000000001111111111"]})) + self.assertThat(read(b"si1", [0], [(95,10)]), + Equals({0: [b"99999"]})) #self.failUnlessEqual(s0.get_length(), 100) bad_secrets = (b"bad write enabler", secrets[1], secrets[2]) f = self.failUnlessRaises(BadWriteEnablerError, write, b"si1", bad_secrets, {}, []) - self.failUnlessIn("The write enabler was recorded by nodeid 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.", str(f)) + self.assertThat(str(f), Contains("The write enabler was recorded by nodeid 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'.")) # this testv should fail answer = write(b"si1", secrets, @@ -1555,12 +1555,12 @@ class MutableServer(unittest.TestCase): }, [(0,12), (20,5)], ) - self.failUnlessEqual(answer, (False, - {0: [b"000000000011", b"22222"], + self.assertThat(answer, (False, + Equals({0: [b"000000000011", b"22222"], 1: [b"", b""], 2: [b"", b""], - })) - self.failUnlessEqual(read(b"si1", [0], [(0,100)]), {0: [data]}) + }))) + self.assertThat(read(b"si1", [0], [(0,100)]), Equals({0: [data]})) def test_operators(self): # test operators, the data we're comparing is '11111' in all cases. @@ -1587,8 +1587,8 @@ class MutableServer(unittest.TestCase): [(0, b"x"*100)], None, )}, [(10,5)]) - self.failUnlessEqual(answer, (False, {0: [b"11111"]})) - self.failUnlessEqual(read(b"si1", [0], [(0,100)]), {0: [data]}) + self.assertThat(answer, Equals((False, {0: [b"11111"]}))) + self.assertThat(read(b"si1", [0], [(0,100)]), Equals({0: [data]})) reset() answer = write(b"si1", secrets, {0: ([(10, 5, b"eq", b"11111"), @@ -1596,8 +1596,8 @@ class MutableServer(unittest.TestCase): [(0, b"y"*100)], None, )}, [(10,5)]) - self.failUnlessEqual(answer, (True, {0: [b"11111"]})) - self.failUnlessEqual(read(b"si1", [0], [(0,100)]), {0: [b"y"*100]}) + self.assertThat(answer, Equals((True, {0: [b"11111"]}))) + self.assertThat(read(b"si1", [0], [(0,100)]), Equals({0: [b"y"*100]})) reset() # finally, test some operators against empty shares @@ -1606,8 +1606,8 @@ class MutableServer(unittest.TestCase): [(0, b"x"*100)], None, )}, [(10,5)]) - self.failUnlessEqual(answer, (False, {0: [b"11111"]})) - self.failUnlessEqual(read(b"si1", [0], [(0,100)]), {0: [data]}) + self.assertThat(answer, Equals((False, {0: [b"11111"]}))) + self.assertThat(read(b"si1", [0], [(0,100)]), Equals({0: [data]})) reset() def test_readv(self): @@ -1624,12 +1624,12 @@ class MutableServer(unittest.TestCase): 1: ([], [(0,data[1])], None), 2: ([], [(0,data[2])], None), }, []) - self.failUnlessEqual(rc, (True, {})) + self.assertThat(rc, Equals((True, {}))) answer = read(b"si1", [], [(0, 10)]) - self.failUnlessEqual(answer, {0: [b"0"*10], + self.assertThat(answer, Equals({0: [b"0"*10], 1: [b"1"*10], - 2: [b"2"*10]}) + 2: [b"2"*10]})) def compare_leases_without_timestamps(self, leases_a, leases_b): """ @@ -1646,11 +1646,11 @@ class MutableServer(unittest.TestCase): # non-equal inputs (expiration timestamp aside). It seems # reasonably safe to use `renew` to make _one_ of the timestamps # equal to the other though. - self.assertEqual( + self.assertThat( a.renew(b.get_expiration_time()), - b, + Equals(b), ) - self.assertEqual(len(leases_a), len(leases_b)) + self.assertThat(len(leases_a), Equals(len(leases_b))) def test_leases(self): ss = self.create("test_leases") @@ -1662,7 +1662,7 @@ class MutableServer(unittest.TestCase): write = ss.slot_testv_and_readv_and_writev read = ss.slot_readv rc = write(b"si1", secrets(0), {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(rc, (True, {})) + self.assertThat(rc, Equals((True, {}))) # create a random non-numeric file in the bucket directory, to # exercise the code that's supposed to ignore those. @@ -1673,32 +1673,32 @@ class MutableServer(unittest.TestCase): f.close() s0 = MutableShareFile(os.path.join(bucket_dir, "0")) - self.failUnlessEqual(len(list(s0.get_leases())), 1) + self.assertThat(list(s0.get_leases()), HasLength(1)) # add-lease on a missing storage index is silently ignored - self.failUnlessEqual(ss.add_lease(b"si18", b"", b""), None) + self.assertThat(ss.add_lease(b"si18", b"", b""), Equals(None)) # re-allocate the slots and use the same secrets, that should update # the lease write(b"si1", secrets(0), {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(len(list(s0.get_leases())), 1) + self.assertThat(list(s0.get_leases()), HasLength(1)) # renew it directly ss.renew_lease(b"si1", secrets(0)[1]) - self.failUnlessEqual(len(list(s0.get_leases())), 1) + self.assertThat(list(s0.get_leases()), HasLength(1)) # now allocate them with a bunch of different secrets, to trigger the # extended lease code. Use add_lease for one of them. write(b"si1", secrets(1), {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(len(list(s0.get_leases())), 2) + self.assertThat(list(s0.get_leases()), HasLength(2)) secrets2 = secrets(2) ss.add_lease(b"si1", secrets2[1], secrets2[2]) - self.failUnlessEqual(len(list(s0.get_leases())), 3) + self.assertThat(list(s0.get_leases()), HasLength(3)) write(b"si1", secrets(3), {0: ([], [(0,data)], None)}, []) write(b"si1", secrets(4), {0: ([], [(0,data)], None)}, []) write(b"si1", secrets(5), {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(len(list(s0.get_leases())), 6) + self.assertThat(list(s0.get_leases()), HasLength(6)) all_leases = list(s0.get_leases()) # and write enough data to expand the container, forcing the server @@ -1728,15 +1728,15 @@ class MutableServer(unittest.TestCase): ss.renew_lease, b"si1", secrets(20)[1]) e_s = str(e) - self.failUnlessIn("Unable to renew non-existent lease", e_s) - self.failUnlessIn("I have leases accepted by nodeids:", e_s) - self.failUnlessIn("nodeids: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' .", e_s) + self.assertThat(e_s, Contains("Unable to renew non-existent lease")) + self.assertThat(e_s, Contains("I have leases accepted by nodeids:")) + self.assertThat(e_s, Contains("nodeids: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' .")) - self.assertEqual(all_leases, list(s0.get_leases())) + self.assertThat(all_leases, Equals(list(s0.get_leases()))) # reading shares should not modify the timestamp read(b"si1", [], [(0,200)]) - self.assertEqual(all_leases, list(s0.get_leases())) + self.assertThat(all_leases, Equals(list(s0.get_leases()))) write(b"si1", secrets(0), {0: ([], [(200, b"make me bigger")], None)}, []) @@ -1764,13 +1764,13 @@ class MutableServer(unittest.TestCase): write_enabler, renew_secret, cancel_secret = secrets(0) rc = write(b"si1", (write_enabler, renew_secret, cancel_secret), {0: ([], [(0,data)], None)}, []) - self.failUnlessEqual(rc, (True, {})) + self.assertThat(rc, Equals((True, {}))) bucket_dir = os.path.join(self.workdir("test_mutable_add_lease_renews"), "shares", storage_index_to_dir(b"si1")) s0 = MutableShareFile(os.path.join(bucket_dir, "0")) [lease] = s0.get_leases() - self.assertEqual(lease.get_expiration_time(), 235 + DEFAULT_RENEWAL_TIME) + self.assertThat(lease.get_expiration_time(), Equals(235 + DEFAULT_RENEWAL_TIME)) # Time passes... clock.advance(835) @@ -1778,8 +1778,8 @@ class MutableServer(unittest.TestCase): # Adding a lease renews it: ss.add_lease(b"si1", renew_secret, cancel_secret) [lease] = s0.get_leases() - self.assertEqual(lease.get_expiration_time(), - 235 + 835 + DEFAULT_RENEWAL_TIME) + self.assertThat(lease.get_expiration_time(), + Equals(235 + 835 + DEFAULT_RENEWAL_TIME)) def test_remove(self): ss = self.create("test_remove") @@ -1796,26 +1796,26 @@ class MutableServer(unittest.TestCase): []) # the answer should mention all the shares that existed before the # write - self.failUnlessEqual(answer, (True, {0:[],1:[],2:[]}) ) + self.assertThat(answer, Equals((True, {0:[],1:[],2:[]}))) # but a new read should show only sh1 and sh2 - self.failUnlessEqual(readv(b"si1", [], [(0,10)]), - {1: [b""], 2: [b""]}) + self.assertThat(readv(b"si1", [], [(0,10)]), + Equals({1: [b""], 2: [b""]})) # delete sh1 by setting its size to zero answer = writev(b"si1", secrets, {1: ([], [], 0)}, []) - self.failUnlessEqual(answer, (True, {1:[],2:[]}) ) - self.failUnlessEqual(readv(b"si1", [], [(0,10)]), - {2: [b""]}) + self.assertThat(answer, Equals((True, {1:[],2:[]}))) + self.assertThat(readv(b"si1", [], [(0,10)]), + Equals({2: [b""]})) # delete sh2 by setting its size to zero answer = writev(b"si1", secrets, {2: ([], [], 0)}, []) - self.failUnlessEqual(answer, (True, {2:[]}) ) - self.failUnlessEqual(readv(b"si1", [], [(0,10)]), - {}) + self.assertThat(answer, Equals((True, {2:[]}))) + self.assertThat(readv(b"si1", [], [(0,10)]), + Equals({})) # and the bucket directory should now be gone si = base32.b2a(b"si1") # note: this is a detail of the storage server implementation, and @@ -1824,8 +1824,8 @@ class MutableServer(unittest.TestCase): prefix = si[:2] prefixdir = os.path.join(self.workdir("test_remove"), "shares", prefix) bucketdir = os.path.join(prefixdir, si) - self.failUnless(os.path.exists(prefixdir), prefixdir) - self.failIf(os.path.exists(bucketdir), bucketdir) + self.assertThat(prefixdir, Contains(os.path.exists(prefixdir))) + self.assertFalse(os.path.exists(bucketdir), bucketdir) def test_writev_without_renew_lease(self): """ @@ -1854,7 +1854,7 @@ class MutableServer(unittest.TestCase): renew_leases=False, ) leases = list(ss.get_slot_leases(storage_index)) - self.assertEqual([], leases) + self.assertThat([], Equals(leases)) def test_get_slot_leases_empty_slot(self): """ @@ -1862,9 +1862,9 @@ class MutableServer(unittest.TestCase): shares, it returns an empty iterable. """ ss = self.create("test_get_slot_leases_empty_slot") - self.assertEqual( + self.assertThat( list(ss.get_slot_leases(b"si1")), - [], + Equals([]), ) def test_remove_non_present(self): @@ -1900,10 +1900,10 @@ class MutableServer(unittest.TestCase): ) self.assertTrue(testv_is_good) - self.assertEqual({}, read_data) + self.assertThat({}, Equals(read_data)) -class MDMFProxies(unittest.TestCase, ShouldFailMixin): +class MDMFProxies(SyncTestCase, ShouldFailMixin): def setUp(self): self.sparent = LoggingServiceParent() self._lease_secret = itertools.count() @@ -2084,7 +2084,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): tws[0] = (testvs, [(0, data)], None) readv = [(0, 1)] results = write(storage_index, self.secrets, tws, readv) - self.failUnless(results[0]) + self.assertTrue(results[0]) def build_test_sdmf_share(self, empty=False): @@ -2150,7 +2150,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): tws[0] = (testvs, [(0, share)], None) readv = [] results = write(storage_index, self.secrets, tws, readv) - self.failUnless(results[0]) + self.assertFalse(results[0]) def test_read(self): @@ -2160,8 +2160,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d = defer.succeed(None) def _check_block_and_salt(block_and_salt): (block, salt) = block_and_salt - self.failUnlessEqual(block, self.block) - self.failUnlessEqual(salt, self.salt) + self.assertThat(block, Equals(self.block)) + self.assertThat(salt, Equals(self.salt)) for i in range(6): d.addCallback(lambda ignored, i=i: @@ -2171,57 +2171,57 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.get_encprivkey()) d.addCallback(lambda encprivkey: - self.failUnlessEqual(self.encprivkey, encprivkey)) + self.assertThat(self.encprivkey, Equals(encprivkey))) d.addCallback(lambda ignored: mr.get_blockhashes()) d.addCallback(lambda blockhashes: - self.failUnlessEqual(self.block_hash_tree, blockhashes)) + self.assertThat(self.block_hash_tree, Equals(blockhashes))) d.addCallback(lambda ignored: mr.get_sharehashes()) d.addCallback(lambda sharehashes: - self.failUnlessEqual(self.share_hash_chain, sharehashes)) + self.assertThat(self.share_hash_chain, Equals(sharehashes))) d.addCallback(lambda ignored: mr.get_signature()) d.addCallback(lambda signature: - self.failUnlessEqual(signature, self.signature)) + self.assertThat(signature, Equals(self.signature))) d.addCallback(lambda ignored: mr.get_verification_key()) d.addCallback(lambda verification_key: - self.failUnlessEqual(verification_key, self.verification_key)) + self.assertThat(verification_key, Equals(self.verification_key))) d.addCallback(lambda ignored: mr.get_seqnum()) d.addCallback(lambda seqnum: - self.failUnlessEqual(seqnum, 0)) + self.assertThat(seqnum, Equals(0))) d.addCallback(lambda ignored: mr.get_root_hash()) d.addCallback(lambda root_hash: - self.failUnlessEqual(self.root_hash, root_hash)) + self.assertThat(self.root_hash, Equals(root_hash))) d.addCallback(lambda ignored: mr.get_seqnum()) d.addCallback(lambda seqnum: - self.failUnlessEqual(0, seqnum)) + self.assertThat(seqnum, Equals(0))) d.addCallback(lambda ignored: mr.get_encoding_parameters()) def _check_encoding_parameters(args): (k, n, segsize, datalen) = args - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) - self.failUnlessEqual(segsize, 6) - self.failUnlessEqual(datalen, 36) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) + self.assertThat(segsize, Equals(6)) + self.assertThat(datalen, Equals(36)) d.addCallback(_check_encoding_parameters) d.addCallback(lambda ignored: mr.get_checkstring()) d.addCallback(lambda checkstring: - self.failUnlessEqual(checkstring, checkstring)) + self.assertThat(checkstring, Equals(checkstring))) return d @@ -2231,8 +2231,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d = mr.get_block_and_salt(5) def _check_tail_segment(results): block, salt = results - self.failUnlessEqual(len(block), 1) - self.failUnlessEqual(block, b"a") + self.assertThat(block, HasLength(1)) + self.assertThat(block, Equals(b"a")) d.addCallback(_check_tail_segment) return d @@ -2254,10 +2254,10 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d = mr.get_encoding_parameters() def _check_encoding_parameters(args): (k, n, segment_size, datalen) = args - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) - self.failUnlessEqual(segment_size, 6) - self.failUnlessEqual(datalen, 36) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) + self.assertThat(segment_size, Equals(6)) + self.assertThat(datalen, Equals(36)) d.addCallback(_check_encoding_parameters) return d @@ -2267,7 +2267,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr = MDMFSlotReadProxy(self.storage_server, b"si1", 0) d = mr.get_seqnum() d.addCallback(lambda seqnum: - self.failUnlessEqual(seqnum, 0)) + self.assertThat(seqnum, Equals(0))) return d @@ -2276,7 +2276,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr = MDMFSlotReadProxy(self.storage_server, b"si1", 0) d = mr.get_root_hash() d.addCallback(lambda root_hash: - self.failUnlessEqual(root_hash, self.root_hash)) + self.assertThat(root_hash, Equals(self.root_hash))) return d @@ -2285,7 +2285,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr = MDMFSlotReadProxy(self.storage_server, b"si1", 0) d = mr.get_checkstring() d.addCallback(lambda checkstring: - self.failUnlessEqual(checkstring, self.checkstring)) + self.assertThat(checkstring, Equals(self.checkstring))) return d @@ -2307,22 +2307,22 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mw.put_verification_key(self.verification_key) d = mw.finish_publishing() def _then(results): - self.failUnless(len(results), 2) + self.assertThat(results, HasLength(2)) result, readv = results - self.failUnless(result) - self.failIf(readv) + self.assertTrue(result) + self.assertFalse(readv) self.old_checkstring = mw.get_checkstring() mw.set_checkstring(b"") d.addCallback(_then) d.addCallback(lambda ignored: mw.finish_publishing()) def _then_again(results): - self.failUnlessEqual(len(results), 2) + self.assertThat(results, HasLength(2)) result, readvs = results - self.failIf(result) - self.failUnlessIn(0, readvs) + self.assertFalse(result) + self.assertThat(readvs, Contains(0)) readv = readvs[0][0] - self.failUnlessEqual(readv, self.old_checkstring) + self.assertThat(readv, Equals(self.old_checkstring)) d.addCallback(_then_again) # The checkstring remains the same for the rest of the process. return d @@ -2383,11 +2383,11 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): def _check_success(results): result, readvs = results - self.failUnless(result) + self.assertTrue(result) def _check_failure(results): result, readvs = results - self.failIf(result) + self.assertFalse(result) def _write_share(mw): for i in range(6): @@ -2431,14 +2431,14 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): # any point during the process, it should fail to write when we # tell it to write. def _check_failure(results): - self.failUnlessEqual(len(results), 2) + self.assertThat(results, Equals(2)) res, d = results - self.failIf(res) + self.assertFalse(res) def _check_success(results): - self.failUnlessEqual(len(results), 2) + self.assertThat(results, HasLength(2)) res, d = results - self.failUnless(results) + self.assertFalse(results) mw = self._make_new_mw(b"si1", 0) mw.set_checkstring(b"this is a lie") @@ -2495,100 +2495,100 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mw.put_verification_key(self.verification_key) d = mw.finish_publishing() def _check_publish(results): - self.failUnlessEqual(len(results), 2) + self.assertThat(results, HasLength(2)) result, ign = results - self.failUnless(result, "publish failed") + self.assertTrue(result, "publish failed") for i in range(6): - self.failUnlessEqual(read(b"si1", [0], [(expected_sharedata_offset + (i * written_block_size), written_block_size)]), - {0: [written_block]}) + self.assertThat(read(b"si1", [0], [(expected_sharedata_offset + (i * written_block_size), written_block_size)]), + Equals({0: [written_block]})) - self.failUnlessEqual(len(self.encprivkey), 7) - self.failUnlessEqual(read(b"si1", [0], [(expected_private_key_offset, 7)]), - {0: [self.encprivkey]}) + self.assertThat(self.encprivkey, HasLength(7)) + self.assertThat(read(b"si1", [0], [(expected_private_key_offset, 7)]), + Equals({0: [self.encprivkey]})) expected_block_hash_offset = expected_sharedata_offset + \ (6 * written_block_size) - self.failUnlessEqual(len(self.block_hash_tree_s), 32 * 6) - self.failUnlessEqual(read(b"si1", [0], [(expected_block_hash_offset, 32 * 6)]), - {0: [self.block_hash_tree_s]}) + self.assertThat(self.block_hash_tree_s, HasLength(32 * 6)) + self.assertThat(read(b"si1", [0], [(expected_block_hash_offset, 32 * 6)]), + Equals({0: [self.block_hash_tree_s]})) expected_share_hash_offset = expected_private_key_offset + len(self.encprivkey) - self.failUnlessEqual(read(b"si1", [0],[(expected_share_hash_offset, (32 + 2) * 6)]), - {0: [self.share_hash_chain_s]}) + self.assertThat(read(b"si1", [0],[(expected_share_hash_offset, (32 + 2) * 6)]), + Equals({0: [self.share_hash_chain_s]})) - self.failUnlessEqual(read(b"si1", [0], [(9, 32)]), - {0: [self.root_hash]}) + self.assertThat(read(b"si1", [0], [(9, 32)]), + Equals({0: [self.root_hash]})) expected_signature_offset = expected_share_hash_offset + \ len(self.share_hash_chain_s) - self.failUnlessEqual(len(self.signature), 9) - self.failUnlessEqual(read(b"si1", [0], [(expected_signature_offset, 9)]), - {0: [self.signature]}) + self.assertThat(self.signature, HasLength(9)) + self.assertThat(read(b"si1", [0], [(expected_signature_offset, 9)]), + Equals({0: [self.signature]})) expected_verification_key_offset = expected_signature_offset + len(self.signature) - self.failUnlessEqual(len(self.verification_key), 6) - self.failUnlessEqual(read(b"si1", [0], [(expected_verification_key_offset, 6)]), - {0: [self.verification_key]}) + self.assertThat(self.verification_key, HasLength(6)) + self.assertThat(read(b"si1", [0], [(expected_verification_key_offset, 6)]), + Equals({0: [self.verification_key]})) signable = mw.get_signable() verno, seq, roothash, k, n, segsize, datalen = \ struct.unpack(">BQ32sBBQQ", signable) - self.failUnlessEqual(verno, 1) - self.failUnlessEqual(seq, 0) - self.failUnlessEqual(roothash, self.root_hash) - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) - self.failUnlessEqual(segsize, 6) - self.failUnlessEqual(datalen, 36) + self.assertThat(verno, Equals(1)) + self.assertThat(seq, Equals(0)) + self.assertThat(roothash, Equals(self.root_hash)) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) + self.assertThat(segsize, Equals(6)) + self.assertThat(datalen, Equals(36)) expected_eof_offset = expected_block_hash_offset + \ len(self.block_hash_tree_s) # Check the version number to make sure that it is correct. expected_version_number = struct.pack(">B", 1) - self.failUnlessEqual(read(b"si1", [0], [(0, 1)]), - {0: [expected_version_number]}) + self.assertThat(read(b"si1", [0], [(0, 1)]), + Equals({0: [expected_version_number]})) # Check the sequence number to make sure that it is correct expected_sequence_number = struct.pack(">Q", 0) - self.failUnlessEqual(read(b"si1", [0], [(1, 8)]), - {0: [expected_sequence_number]}) + self.assertThat(read(b"si1", [0], [(1, 8)]), + Equals({0: [expected_sequence_number]})) # Check that the encoding parameters (k, N, segement size, data # length) are what they should be. These are 3, 10, 6, 36 expected_k = struct.pack(">B", 3) - self.failUnlessEqual(read(b"si1", [0], [(41, 1)]), - {0: [expected_k]}) + self.assertThat(read(b"si1", [0], [(41, 1)]), + Equals({0: [expected_k]})) expected_n = struct.pack(">B", 10) - self.failUnlessEqual(read(b"si1", [0], [(42, 1)]), - {0: [expected_n]}) + self.assertThat(read(b"si1", [0], [(42, 1)]), + Equals({0: [expected_n]})) expected_segment_size = struct.pack(">Q", 6) - self.failUnlessEqual(read(b"si1", [0], [(43, 8)]), - {0: [expected_segment_size]}) + self.assertThat(read(b"si1", [0], [(43, 8)]), + Equals({0: [expected_segment_size]})) expected_data_length = struct.pack(">Q", 36) - self.failUnlessEqual(read(b"si1", [0], [(51, 8)]), - {0: [expected_data_length]}) + self.assertThat(read(b"si1", [0], [(51, 8)]), + Equals({0: [expected_data_length]})) expected_offset = struct.pack(">Q", expected_private_key_offset) - self.failUnlessEqual(read(b"si1", [0], [(59, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(59, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_share_hash_offset) - self.failUnlessEqual(read(b"si1", [0], [(67, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(67, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_signature_offset) - self.failUnlessEqual(read(b"si1", [0], [(75, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(75, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_verification_key_offset) - self.failUnlessEqual(read(b"si1", [0], [(83, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(83, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_verification_key_offset + len(self.verification_key)) - self.failUnlessEqual(read(b"si1", [0], [(91, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(91, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_sharedata_offset) - self.failUnlessEqual(read(b"si1", [0], [(99, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(99, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_block_hash_offset) - self.failUnlessEqual(read(b"si1", [0], [(107, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(107, 8)]), + Equals({0: [expected_offset]})) expected_offset = struct.pack(">Q", expected_eof_offset) - self.failUnlessEqual(read(b"si1", [0], [(115, 8)]), - {0: [expected_offset]}) + self.assertThat(read(b"si1", [0], [(115, 8)]), + Equals({0: [expected_offset]})) d.addCallback(_check_publish) return d @@ -2803,8 +2803,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr = MDMFSlotReadProxy(self.storage_server, b"si1", 0) def _check_block_and_salt(block_and_salt): (block, salt) = block_and_salt - self.failUnlessEqual(block, self.block) - self.failUnlessEqual(salt, self.salt) + self.assertThat(block, Equals(self.block)) + self.assertThat(salt, Equals(self.salt)) for i in range(6): d.addCallback(lambda ignored, i=i: @@ -2814,52 +2814,52 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.get_encprivkey()) d.addCallback(lambda encprivkey: - self.failUnlessEqual(self.encprivkey, encprivkey)) + self.assertThat(self.encprivkey, Equals(encprivkey))) d.addCallback(lambda ignored: mr.get_blockhashes()) d.addCallback(lambda blockhashes: - self.failUnlessEqual(self.block_hash_tree, blockhashes)) + self.assertThat(self.block_hash_tree, Equals(blockhashes))) d.addCallback(lambda ignored: mr.get_sharehashes()) d.addCallback(lambda sharehashes: - self.failUnlessEqual(self.share_hash_chain, sharehashes)) + self.assertThat(self.share_hash_chain, Equals(sharehashes))) d.addCallback(lambda ignored: mr.get_signature()) d.addCallback(lambda signature: - self.failUnlessEqual(signature, self.signature)) + self.assertThat(signature, Equals(self.signature))) d.addCallback(lambda ignored: mr.get_verification_key()) d.addCallback(lambda verification_key: - self.failUnlessEqual(verification_key, self.verification_key)) + self.assertThat(verification_key, Equals(self.verification_key))) d.addCallback(lambda ignored: mr.get_seqnum()) d.addCallback(lambda seqnum: - self.failUnlessEqual(seqnum, 0)) + self.assertThat(seqnum, Equals(0))) d.addCallback(lambda ignored: mr.get_root_hash()) d.addCallback(lambda root_hash: - self.failUnlessEqual(self.root_hash, root_hash)) + self.assertThat(self.root_hash, Equals(root_hash))) d.addCallback(lambda ignored: mr.get_encoding_parameters()) def _check_encoding_parameters(args): (k, n, segsize, datalen) = args - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) - self.failUnlessEqual(segsize, 6) - self.failUnlessEqual(datalen, 36) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) + self.assertThat(segsize, Equals(6)) + self.assertThat(datalen, Equals(36)) d.addCallback(_check_encoding_parameters) d.addCallback(lambda ignored: mr.get_checkstring()) d.addCallback(lambda checkstring: - self.failUnlessEqual(checkstring, mw.get_checkstring())) + self.assertThat(checkstring, Equals(mw.get_checkstring()))) return d @@ -2871,7 +2871,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr = MDMFSlotReadProxy(self.storage_server, b"si1", 0) d = mr.is_sdmf() d.addCallback(lambda issdmf: - self.failUnless(issdmf)) + self.assertFalse(issdmf)) return d @@ -2884,7 +2884,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.is_sdmf()) d.addCallback(lambda issdmf: - self.failUnless(issdmf)) + self.assertTrue(issdmf)) # What do we need to read? # - The sharedata @@ -2897,51 +2897,51 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): # bytes in size. The share is composed entirely of the # letter a. self.block contains 2 as, so 6 * self.block is # what we are looking for. - self.failUnlessEqual(block, self.block * 6) - self.failUnlessEqual(salt, self.salt) + self.assertThat(block, Equals(self.block * 6)) + self.assertThat(salt, Equals(self.salt)) d.addCallback(_check_block_and_salt) # - The blockhashes d.addCallback(lambda ignored: mr.get_blockhashes()) d.addCallback(lambda blockhashes: - self.failUnlessEqual(self.block_hash_tree, - blockhashes, + self.assertThat(self.block_hash_tree, + Equals(blockhashes), blockhashes)) # - The sharehashes d.addCallback(lambda ignored: mr.get_sharehashes()) d.addCallback(lambda sharehashes: - self.failUnlessEqual(self.share_hash_chain, - sharehashes)) + self.assertThat(self.share_hash_chain, + Equals(sharehashes))) # - The keys d.addCallback(lambda ignored: mr.get_encprivkey()) d.addCallback(lambda encprivkey: - self.failUnlessEqual(encprivkey, self.encprivkey, encprivkey)) + self.assertThat(encprivkey, self.encprivkey, Equals(encprivkey))) d.addCallback(lambda ignored: mr.get_verification_key()) d.addCallback(lambda verification_key: - self.failUnlessEqual(verification_key, - self.verification_key, + self.assertThat(verification_key, + Equals(self.verification_key), verification_key)) # - The signature d.addCallback(lambda ignored: mr.get_signature()) d.addCallback(lambda signature: - self.failUnlessEqual(signature, self.signature, signature)) + self.assertThat(signature, Equals(self.signature), signature)) # - The sequence number d.addCallback(lambda ignored: mr.get_seqnum()) d.addCallback(lambda seqnum: - self.failUnlessEqual(seqnum, 0, seqnum)) + self.assertThat(seqnum, Equals(0), seqnum)) # - The root hash d.addCallback(lambda ignored: mr.get_root_hash()) d.addCallback(lambda root_hash: - self.failUnlessEqual(root_hash, self.root_hash, root_hash)) + self.assertThat(root_hash, Equals(self.root_hash), root_hash)) return d @@ -2955,7 +2955,7 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.is_sdmf()) d.addCallback(lambda issdmf: - self.failUnless(issdmf)) + self.assertTrue(issdmf)) d.addCallback(lambda ignored: self.shouldFail(LayoutInvalid, "test bad segment", None, @@ -2983,8 +2983,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda mr: mr.get_verinfo()) def _check_verinfo(verinfo): - self.failUnless(verinfo) - self.failUnlessEqual(len(verinfo), 9) + self.assertTrue(verinfo) + self.assertThat(verinfo, HasLength(9)) (seqnum, root_hash, salt_hash, @@ -2994,12 +2994,12 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, prefix, offsets) = verinfo - self.failUnlessEqual(seqnum, 0) - self.failUnlessEqual(root_hash, self.root_hash) - self.failUnlessEqual(segsize, 6) - self.failUnlessEqual(datalen, 36) - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) + self.assertThat(seqnum, Equals(0)) + self.assertThat(root_hash, Equals(self.root_hash)) + self.assertThat(segsize, Equals(6)) + self.assertThat(datalen, Equals(36)) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) expected_prefix = struct.pack(MDMFSIGNABLEHEADER, 1, seqnum, @@ -3008,8 +3008,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, segsize, datalen) - self.failUnlessEqual(expected_prefix, prefix) - self.failUnlessEqual(self.rref.read_count, 0) + self.assertThat(expected_prefix, Equals(prefix)) + self.assertThat(self.rref.read_count, Equals(0)) d.addCallback(_check_verinfo) # This is not enough data to read a block and a share, so the # wrapper should attempt to read this from the remote server. @@ -3018,9 +3018,9 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr.get_block_and_salt(0)) def _check_block_and_salt(block_and_salt): (block, salt) = block_and_salt - self.failUnlessEqual(block, self.block) - self.failUnlessEqual(salt, self.salt) - self.failUnlessEqual(self.rref.read_count, 1) + self.assertThat(block, Equals(self.block)) + self.assertThat(salt, Equals(self.salt)) + self.assertThat(self.rref.read_count, Equals(1)) # This should be enough data to read one block. d.addCallback(_make_mr, 123 + PRIVATE_KEY_SIZE + SIGNATURE_SIZE + VERIFICATION_KEY_SIZE + SHARE_HASH_CHAIN_SIZE + 140) d.addCallback(lambda mr: @@ -3044,8 +3044,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda mr: mr.get_verinfo()) def _check_verinfo(verinfo): - self.failUnless(verinfo) - self.failUnlessEqual(len(verinfo), 9) + self.assertTrue(verinfo) + self.assertThat(verinfo, HasLength(9)) (seqnum, root_hash, salt, @@ -3055,13 +3055,13 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, prefix, offsets) = verinfo - self.failUnlessEqual(seqnum, 0) - self.failUnlessEqual(root_hash, self.root_hash) - self.failUnlessEqual(salt, self.salt) - self.failUnlessEqual(segsize, 36) - self.failUnlessEqual(datalen, 36) - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) + self.assertThat(seqnum, Equals(0)) + self.assertThat(root_hash, Equals(self.root_hash)) + self.assertThat(salt, Equals(self.salt)) + self.assertThat(segsize, Equals(36)) + self.assertThat(datalen, Equals(36)) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) expected_prefix = struct.pack(SIGNED_PREFIX, 0, seqnum, @@ -3071,8 +3071,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, segsize, datalen) - self.failUnlessEqual(expected_prefix, prefix) - self.failUnlessEqual(self.rref.read_count, 0) + self.assertThat(expected_prefix, Equals(prefix)) + self.assertThat(self.rref.read_count, Equals(0)) d.addCallback(_check_verinfo) # This shouldn't be enough to read any share data. d.addCallback(_make_mr, 123) @@ -3080,11 +3080,11 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): mr.get_block_and_salt(0)) def _check_block_and_salt(block_and_salt): (block, salt) = block_and_salt - self.failUnlessEqual(block, self.block * 6) - self.failUnlessEqual(salt, self.salt) + self.assertThat(block, Equals(self.block * 6)) + self.assertThat(salt, Equals(self.salt)) # TODO: Fix the read routine so that it reads only the data # that it has cached if it can't read all of it. - self.failUnlessEqual(self.rref.read_count, 2) + self.assertThat(self.rref.read_count, Equals(2)) # This should be enough to read share data. d.addCallback(_make_mr, self.offsets['share_data']) @@ -3106,12 +3106,12 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.get_encoding_parameters()) def _check_encoding_parameters(params): - self.failUnlessEqual(len(params), 4) + self.assertThat(params, HasLength(4)) k, n, segsize, datalen = params - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) - self.failUnlessEqual(segsize, 0) - self.failUnlessEqual(datalen, 0) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) + self.assertThat(segsize, Equals(0)) + self.assertThat(datalen, Equals(0)) d.addCallback(_check_encoding_parameters) # We should not be able to fetch a block, since there are no @@ -3132,12 +3132,12 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.get_encoding_parameters()) def _check_encoding_parameters(params): - self.failUnlessEqual(len(params), 4) + self.assertThat(params, HasLength(4)) k, n, segsize, datalen = params - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) - self.failUnlessEqual(segsize, 0) - self.failUnlessEqual(datalen, 0) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) + self.assertThat(segsize, Equals(0)) + self.assertThat(datalen, Equals(0)) d.addCallback(_check_encoding_parameters) # It does not make sense to get a block in this format, so we @@ -3157,8 +3157,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.get_verinfo()) def _check_verinfo(verinfo): - self.failUnless(verinfo) - self.failUnlessEqual(len(verinfo), 9) + self.assertTrue(verinfo) + self.assertThat(verinfo, HasLength(9)) (seqnum, root_hash, salt, @@ -3168,13 +3168,13 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, prefix, offsets) = verinfo - self.failUnlessEqual(seqnum, 0) - self.failUnlessEqual(root_hash, self.root_hash) - self.failUnlessEqual(salt, self.salt) - self.failUnlessEqual(segsize, 36) - self.failUnlessEqual(datalen, 36) - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) + self.assertThat(seqnum, Equals(0)) + self.assertThat(root_hash, Equals(self.root_hash)) + self.assertThat(salt, Equals(self.salt)) + self.assertThat(segsize, Equals(36)) + self.assertThat(datalen, Equals(36)) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) expected_prefix = struct.pack(">BQ32s16s BBQQ", 0, seqnum, @@ -3184,8 +3184,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, segsize, datalen) - self.failUnlessEqual(prefix, expected_prefix) - self.failUnlessEqual(offsets, self.offsets) + self.assertThat(prefix, Equals(expected_prefix)) + self.assertThat(offsets, Equals(self.offsets)) d.addCallback(_check_verinfo) return d @@ -3197,8 +3197,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: mr.get_verinfo()) def _check_verinfo(verinfo): - self.failUnless(verinfo) - self.failUnlessEqual(len(verinfo), 9) + self.assertThat(verinfo) + self.assertThat(verinfo, HasLength(9)) (seqnum, root_hash, IV, @@ -3208,13 +3208,13 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, prefix, offsets) = verinfo - self.failUnlessEqual(seqnum, 0) - self.failUnlessEqual(root_hash, self.root_hash) - self.failIf(IV) - self.failUnlessEqual(segsize, 6) - self.failUnlessEqual(datalen, 36) - self.failUnlessEqual(k, 3) - self.failUnlessEqual(n, 10) + self.assertThat(seqnum, Equals(0)) + self.assertThat(root_hash, Equals(self.root_hash)) + self.assertFalse(IV) + self.assertThat(segsize, Equals(6)) + self.assertThat(datalen, Equals(36)) + self.assertThat(k, Equals(3)) + self.assertThat(n, Equals(10)) expected_prefix = struct.pack(">BQ32s BBQQ", 1, seqnum, @@ -3223,8 +3223,8 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): n, segsize, datalen) - self.failUnlessEqual(prefix, expected_prefix) - self.failUnlessEqual(offsets, self.offsets) + self.assertThat(prefix, Equals(expected_prefix)) + self.assertThat(offsets, Equals(self.offsets)) d.addCallback(_check_verinfo) return d @@ -3260,15 +3260,15 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): sdmfr.put_verification_key(self.verification_key) # Now check to make sure that nothing has been written yet. - self.failUnlessEqual(self.rref.write_count, 0) + self.assertThat(self.rref.write_count, Equals(0)) # Now finish publishing d = sdmfr.finish_publishing() def _then(ignored): - self.failUnlessEqual(self.rref.write_count, 1) + self.assertThat(self.rref.write_count, Equals(1)) read = self.ss.slot_readv - self.failUnlessEqual(read(b"si1", [0], [(0, len(data))]), - {0: [data]}) + self.assertThat(read(b"si1", [0], [(0, len(data))]), + Equals({0: [data]})) d.addCallback(_then) return d @@ -3304,11 +3304,11 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): sdmfw.put_verification_key(self.verification_key) # We shouldn't have a checkstring yet - self.failUnlessEqual(sdmfw.get_checkstring(), b"") + self.assertThat(sdmfw.get_checkstring(), Equals(b"")) d = sdmfw.finish_publishing() def _then(results): - self.failIf(results[0]) + self.assertFalse(results[0]) # this is the correct checkstring self._expected_checkstring = results[1][0][0] return self._expected_checkstring @@ -3318,21 +3318,21 @@ class MDMFProxies(unittest.TestCase, ShouldFailMixin): d.addCallback(lambda ignored: sdmfw.get_checkstring()) d.addCallback(lambda checkstring: - self.failUnlessEqual(checkstring, self._expected_checkstring)) + self.assertThat(checkstring, Equals(self._expected_checkstring))) d.addCallback(lambda ignored: sdmfw.finish_publishing()) def _then_again(results): - self.failUnless(results[0]) + self.assertTrue(results[0]) read = self.ss.slot_readv - self.failUnlessEqual(read(b"si1", [0], [(1, 8)]), + self.assertThat(read(b"si1", [0], [(1, 8)]), {0: [struct.pack(">Q", 1)]}) - self.failUnlessEqual(read(b"si1", [0], [(9, len(data) - 9)]), - {0: [data[9:]]}) + self.assertThat(read(b"si1", [0], [(9, len(data) - 9)]), + Equals({0: [data[9:]]})) d.addCallback(_then_again) return d -class Stats(unittest.TestCase): +class Stats(SyncTestCase): def setUp(self): self.sparent = LoggingServiceParent() @@ -3364,57 +3364,57 @@ class Stats(unittest.TestCase): output = ss.get_latencies() - self.failUnlessEqual(sorted(output.keys()), - sorted(["allocate", "renew", "cancel", "write", "get"])) - self.failUnlessEqual(len(ss.latencies["allocate"]), 1000) - self.failUnless(abs(output["allocate"]["mean"] - 9500) < 1, output) - self.failUnless(abs(output["allocate"]["01_0_percentile"] - 9010) < 1, output) - self.failUnless(abs(output["allocate"]["10_0_percentile"] - 9100) < 1, output) - self.failUnless(abs(output["allocate"]["50_0_percentile"] - 9500) < 1, output) - self.failUnless(abs(output["allocate"]["90_0_percentile"] - 9900) < 1, output) - self.failUnless(abs(output["allocate"]["95_0_percentile"] - 9950) < 1, output) - self.failUnless(abs(output["allocate"]["99_0_percentile"] - 9990) < 1, output) - self.failUnless(abs(output["allocate"]["99_9_percentile"] - 9999) < 1, output) + self.assertThat(sorted(output.keys()), + Equals(sorted(["allocate", "renew", "cancel", "write", "get"]))) + self.assertThat(ss.latencies["allocate"], HasLength(1000)) + self.assertTrue(abs(output["allocate"]["mean"] - 9500) < 1, output) + self.assertTrue(abs(output["allocate"]["01_0_percentile"] - 9010) < 1, output) + self.assertTrue(abs(output["allocate"]["10_0_percentile"] - 9100) < 1, output) + self.assertTrue(abs(output["allocate"]["50_0_percentile"] - 9500) < 1, output) + self.assertTrue(abs(output["allocate"]["90_0_percentile"] - 9900) < 1, output) + self.assertTrue(abs(output["allocate"]["95_0_percentile"] - 9950) < 1, output) + self.assertTrue(abs(output["allocate"]["99_0_percentile"] - 9990) < 1, output) + self.assertTrue(abs(output["allocate"]["99_9_percentile"] - 9999) < 1, output) - self.failUnlessEqual(len(ss.latencies["renew"]), 1000) - self.failUnless(abs(output["renew"]["mean"] - 500) < 1, output) - self.failUnless(abs(output["renew"]["01_0_percentile"] - 10) < 1, output) - self.failUnless(abs(output["renew"]["10_0_percentile"] - 100) < 1, output) - self.failUnless(abs(output["renew"]["50_0_percentile"] - 500) < 1, output) - self.failUnless(abs(output["renew"]["90_0_percentile"] - 900) < 1, output) - self.failUnless(abs(output["renew"]["95_0_percentile"] - 950) < 1, output) - self.failUnless(abs(output["renew"]["99_0_percentile"] - 990) < 1, output) - self.failUnless(abs(output["renew"]["99_9_percentile"] - 999) < 1, output) + self.assertThat(ss.latencies["renew"], HasLength(1000)) + self.assertTrue(abs(output["renew"]["mean"] - 500) < 1, output) + self.assertTrue(abs(output["renew"]["01_0_percentile"] - 10) < 1, output) + self.assertTrue(abs(output["renew"]["10_0_percentile"] - 100) < 1, output) + self.assertTrue(abs(output["renew"]["50_0_percentile"] - 500) < 1, output) + self.assertTrue(abs(output["renew"]["90_0_percentile"] - 900) < 1, output) + self.assertTrue(abs(output["renew"]["95_0_percentile"] - 950) < 1, output) + self.assertTrue(abs(output["renew"]["99_0_percentile"] - 990) < 1, output) + self.assertTrue(abs(output["renew"]["99_9_percentile"] - 999) < 1, output) - self.failUnlessEqual(len(ss.latencies["write"]), 20) - self.failUnless(abs(output["write"]["mean"] - 9) < 1, output) - self.failUnless(output["write"]["01_0_percentile"] is None, output) - self.failUnless(abs(output["write"]["10_0_percentile"] - 2) < 1, output) - self.failUnless(abs(output["write"]["50_0_percentile"] - 10) < 1, output) - self.failUnless(abs(output["write"]["90_0_percentile"] - 18) < 1, output) - self.failUnless(abs(output["write"]["95_0_percentile"] - 19) < 1, output) - self.failUnless(output["write"]["99_0_percentile"] is None, output) - self.failUnless(output["write"]["99_9_percentile"] is None, output) + self.assertThat(ss.latencies["write"], HasLength(20)) + self.assertTrue(abs(output["write"]["mean"] - 9) < 1, output) + self.assertTrue(output["write"]["01_0_percentile"] is None, output) + self.assertTrue(abs(output["write"]["10_0_percentile"] - 2) < 1, output) + self.assertTrue(abs(output["write"]["50_0_percentile"] - 10) < 1, output) + self.assertTrue(abs(output["write"]["90_0_percentile"] - 18) < 1, output) + self.assertTrue(abs(output["write"]["95_0_percentile"] - 19) < 1, output) + self.assertTrue(output["write"]["99_0_percentile"] is None, output) + self.assertTrue(output["write"]["99_9_percentile"] is None, output) - self.failUnlessEqual(len(ss.latencies["cancel"]), 10) - self.failUnless(abs(output["cancel"]["mean"] - 9) < 1, output) - self.failUnless(output["cancel"]["01_0_percentile"] is None, output) - self.failUnless(abs(output["cancel"]["10_0_percentile"] - 2) < 1, output) - self.failUnless(abs(output["cancel"]["50_0_percentile"] - 10) < 1, output) - self.failUnless(abs(output["cancel"]["90_0_percentile"] - 18) < 1, output) - self.failUnless(output["cancel"]["95_0_percentile"] is None, output) - self.failUnless(output["cancel"]["99_0_percentile"] is None, output) - self.failUnless(output["cancel"]["99_9_percentile"] is None, output) + self.assertThat(ss.latencies["cancel"], HasLength(10)) + self.assertTrue(abs(output["cancel"]["mean"] - 9) < 1, output) + self.assertTrue(output["cancel"]["01_0_percentile"] is None, output) + self.assertTrue(abs(output["cancel"]["10_0_percentile"] - 2) < 1, output) + self.assertTrue(abs(output["cancel"]["50_0_percentile"] - 10) < 1, output) + self.assertTrue(abs(output["cancel"]["90_0_percentile"] - 18) < 1, output) + self.assertTrue(output["cancel"]["95_0_percentile"] is None, output) + self.assertTrue(output["cancel"]["99_0_percentile"] is None, output) + self.assertTrue(output["cancel"]["99_9_percentile"] is None, output) - self.failUnlessEqual(len(ss.latencies["get"]), 1) - self.failUnless(output["get"]["mean"] is None, output) - self.failUnless(output["get"]["01_0_percentile"] is None, output) - self.failUnless(output["get"]["10_0_percentile"] is None, output) - self.failUnless(output["get"]["50_0_percentile"] is None, output) - self.failUnless(output["get"]["90_0_percentile"] is None, output) - self.failUnless(output["get"]["95_0_percentile"] is None, output) - self.failUnless(output["get"]["99_0_percentile"] is None, output) - self.failUnless(output["get"]["99_9_percentile"] is None, output) + self.assertThat(ss.latencies["get"], HasLength(1)) + self.assertTrue(output["get"]["mean"] is None, output) + self.assertTrue(output["get"]["01_0_percentile"] is None, output) + self.assertTrue(output["get"]["10_0_percentile"] is None, output) + self.assertTrue(output["get"]["50_0_percentile"] is None, output) + self.assertTrue(output["get"]["90_0_percentile"] is None, output) + self.assertTrue(output["get"]["95_0_percentile"] is None, output) + self.assertTrue(output["get"]["99_0_percentile"] is None, output) + self.assertTrue(output["get"]["99_9_percentile"] is None, output) immutable_schemas = strategies.sampled_from(list(ALL_IMMUTABLE_SCHEMAS)) @@ -3557,7 +3557,7 @@ class ShareFileTests(unittest.TestCase): mutable_schemas = strategies.sampled_from(list(ALL_MUTABLE_SCHEMAS)) -class MutableShareFileTests(unittest.TestCase): +class MutableShareFileTests(SyncTestCase): """ Tests for allmydata.storage.mutable.MutableShareFile. """