Update unit test asserts

This commit is contained in:
Hugo 2019-10-02 19:58:51 +03:00 committed by Lex Berezhny
parent c5cfd8f40e
commit 087124ce42
15 changed files with 47 additions and 47 deletions

View file

@ -1177,7 +1177,7 @@ class SupportCommands(CommandTestCase):
self.assertEqual(len(txs[0]['support_info']), 1)
self.assertEqual(txs[0]['support_info'][0]['balance_delta'], '1.0')
self.assertEqual(txs[0]['support_info'][0]['claim_id'], claim_id)
self.assertEqual(txs[0]['support_info'][0]['is_tip'], True)
self.assertTrue(txs[0]['support_info'][0]['is_tip'])
self.assertEqual(txs[0]['value'], '1.0')
self.assertEqual(txs[0]['fee'], '0.0')
@ -1188,7 +1188,7 @@ class SupportCommands(CommandTestCase):
self.assertEqual(len(txs2[0]['support_info']), 1)
self.assertEqual(txs2[0]['support_info'][0]['balance_delta'], '-1.0')
self.assertEqual(txs2[0]['support_info'][0]['claim_id'], claim_id)
self.assertEqual(txs2[0]['support_info'][0]['is_tip'], True)
self.assertTrue(txs2[0]['support_info'][0]['is_tip'])
self.assertEqual(txs2[0]['value'], '-1.0')
self.assertEqual(txs2[0]['fee'], '-0.0001415')
@ -1208,6 +1208,6 @@ class SupportCommands(CommandTestCase):
self.assertEqual(len(txs2[0]['support_info']), 1)
self.assertEqual(txs2[0]['support_info'][0]['balance_delta'], '-2.0')
self.assertEqual(txs2[0]['support_info'][0]['claim_id'], claim_id)
self.assertEqual(txs2[0]['support_info'][0]['is_tip'], False)
self.assertFalse(txs2[0]['support_info'][0]['is_tip'])
self.assertEqual(txs2[0]['value'], '0.0')
self.assertEqual(txs2[0]['fee'], '-0.0001415')

View file

@ -323,7 +323,7 @@ class CommentCommands(CommandTestCase):
self.assertIn('has_hidden_comments', comments)
self.assertTrue(comments['has_hidden_comments'])
hidden_cmts1 = list(filter(lambda c: c['is_hidden'], comments['items']))
self.assertTrue(len(hidden_cmts1) == 1)
self.assertEqual(len(hidden_cmts1), 1)
hidden_comment = hidden_cmts1[0]
self.assertEqual(hidden_comment['comment_id'], hidden[0])

View file

@ -31,7 +31,7 @@ class RangeRequests(CommandTestCase):
self.data = data
await self.stream_create('foo', '0.01', data=self.data, file_size=file_size)
if save_blobs:
self.assertTrue(len(os.listdir(self.daemon.blob_manager.blob_dir)) > 1)
self.assertGreater(len(os.listdir(self.daemon.blob_manager.blob_dir)), 1)
await self.daemon.jsonrpc_file_list()['items'][0].fully_reflected.wait()
await self.daemon.jsonrpc_file_delete(delete_from_download_dir=True, claim_name='foo')
self.assertEqual(0, len(os.listdir(self.daemon.blob_manager.blob_dir)))

View file

@ -64,7 +64,7 @@ class TestBlobExchange(BlobExchangeTestBase):
writer.write(blob_bytes)
await server_blob.verified.wait()
self.assertTrue(os.path.isfile(server_blob.file_path))
self.assertEqual(server_blob.get_is_verified(), True)
self.assertTrue(server_blob.get_is_verified())
self.assertTrue(writer.closed())
async def _test_transfer_blob(self, blob_hash: str):
@ -76,7 +76,7 @@ class TestBlobExchange(BlobExchangeTestBase):
self.assertIsNotNone(transport)
self.addCleanup(transport.close)
await client_blob.verified.wait()
self.assertEqual(client_blob.get_is_verified(), True)
self.assertTrue(client_blob.get_is_verified())
self.assertTrue(downloaded)
client_blob.close()
@ -121,7 +121,7 @@ class TestBlobExchange(BlobExchangeTestBase):
self._test_transfer_blob(blob_hash)
)
await second_client_blob.verified.wait()
self.assertEqual(second_client_blob.get_is_verified(), True)
self.assertTrue(second_client_blob.get_is_verified())
async def test_blob_writers_concurrency(self):
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
@ -212,7 +212,7 @@ class TestBlobExchange(BlobExchangeTestBase):
self._test_transfer_blob(sd_hash),
second_client_blob.verified.wait()
)
self.assertEqual(second_client_blob.get_is_verified(), True)
self.assertTrue(second_client_blob.get_is_verified())
async def test_server_chunked_request(self):
blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
@ -225,7 +225,7 @@ class TestBlobExchange(BlobExchangeTestBase):
for byte in blob_request:
server_protocol.data_received(bytes([byte]))
await asyncio.sleep(0.1) # yield execution
self.assertTrue(len(received_data.getvalue()) > 0)
self.assertGreater(len(received_data.getvalue()), 0)
async def test_idle_timeout(self):
self.server.idle_timeout = 1
@ -252,7 +252,7 @@ class TestBlobExchange(BlobExchangeTestBase):
downloaded, protocol2 = await request_blob(self.loop, client_blob, self.server_from_client.address,
self.server_from_client.tcp_port, 2, 3,
connected_protocol=protocol)
self.assertTrue(protocol is protocol2)
self.assertIs(protocol, protocol2)
self.assertFalse(protocol.transport.is_closing())
await client_blob.verified.wait()
self.assertTrue(client_blob.get_is_verified())

View file

@ -75,9 +75,9 @@ class TestProtocol(AsyncioTestCase):
)
store_result = await peer2.store_to_peer(b'2' * 48, peer)
self.assertEqual(store_result[0], peer.node_id)
self.assertEqual(True, store_result[1])
self.assertEqual(True, peer1.data_store.has_peers_for_blob(b'2' * 48))
self.assertEqual(False, peer1.data_store.has_peers_for_blob(b'3' * 48))
self.assertTrue(store_result[1])
self.assertTrue(peer1.data_store.has_peers_for_blob(b'2' * 48))
self.assertFalse(peer1.data_store.has_peers_for_blob(b'3' * 48))
self.assertListEqual([peer2_from_peer1], peer1.data_store.get_storing_contacts())
peer1.data_store.completed_blobs.add(binascii.hexlify(b'2' * 48).decode())
find_value_response = peer1.node_rpc.find_value(peer3, b'2' * 48)

View file

@ -58,7 +58,7 @@ class TestRouting(AsyncioTestCase):
udp_port=node.protocol.udp_port
)
added = await node_1.protocol._add_peer(peer)
self.assertEqual(True, added)
self.assertTrue(added)
contact_cnt += 1
self.assertEqual(len(node_1.protocol.routing_table.get_peers()), 8)

View file

@ -144,7 +144,7 @@ class TestBlobAnnouncer(AsyncioTestCase):
self.assertEqual(response, b'OK')
peers_for_blob = await peer.find_value(blob_hash, 0)
if i == 1:
self.assertTrue(blob_hash not in peers_for_blob)
self.assertNotIn(blob_hash, peers_for_blob)
self.assertEqual(peers_for_blob[b'p'], 0)
else:
self.assertEqual(len(peers_for_blob[blob_hash]), min(i - 1, constants.k))
@ -161,7 +161,7 @@ class TestBlobAnnouncer(AsyncioTestCase):
self.assertNotIn(b'contacts', page_x)
page_x_set = set(page_x[blob_hash])
self.assertEqual(len(page_x[blob_hash]), len(page_x_set))
self.assertTrue(len(page_x_set) > 0)
self.assertGreater(len(page_x_set), 0)
self.assertSetEqual(seen.intersection(page_x_set), set())
seen.intersection_update(page_x_set)
total_seen.update(page_x_set)

View file

@ -75,7 +75,7 @@ class TestLanguages(TestCase):
stream.languages.append('es-419')
self.assertEqual(stream.languages[3].langtag, 'es-419')
self.assertEqual(stream.languages[3].language, 'es')
self.assertEqual(stream.languages[3].script, None)
self.assertIsNone(stream.languages[3].script)
self.assertEqual(stream.languages[3].region, '419')
self.assertEqual(stream.langtags, ['en', 'en-US', 'en-Latn-US', 'es-419'])
@ -139,17 +139,17 @@ class TestLocations(TestCase):
# from partial string
stream = Stream()
stream.locations.append('::Manchester:03101:')
self.assertEqual(stream.locations[0].country, None)
self.assertIsNone(stream.locations[0].country)
self.assertEqual(stream.locations[0].state, '')
self.assertEqual(stream.locations[0].city, 'Manchester')
self.assertEqual(stream.locations[0].code, '03101')
self.assertEqual(stream.locations[0].latitude, None)
self.assertEqual(stream.locations[0].longitude, None)
self.assertIsNone(stream.locations[0].latitude)
self.assertIsNone(stream.locations[0].longitude)
# from partial string lat/long
stream = Stream()
stream.locations.append('::::42.990605:-71.460989')
self.assertEqual(stream.locations[0].country, None)
self.assertIsNone(stream.locations[0].country)
self.assertEqual(stream.locations[0].state, '')
self.assertEqual(stream.locations[0].city, '')
self.assertEqual(stream.locations[0].code, '')
@ -159,7 +159,7 @@ class TestLocations(TestCase):
# from short circuit lat/long
stream = Stream()
stream.locations.append('42.990605:-71.460989')
self.assertEqual(stream.locations[0].country, None)
self.assertIsNone(stream.locations[0].country)
self.assertEqual(stream.locations[0].state, '')
self.assertEqual(stream.locations[0].city, '')
self.assertEqual(stream.locations[0].code, '')

View file

@ -173,7 +173,7 @@ class TestManagedStream(BlobExchangeTestBase):
decrypted = f.read()
self.assertEqual(decrypted, self.stream_bytes)
self.assertEqual(True, self.client_blob_manager.get_blob(self.sd_hash).get_is_verified())
self.assertTrue(self.client_blob_manager.get_blob(self.sd_hash).get_is_verified())
self.assertEqual(
True, self.client_blob_manager.get_blob(self.stream.descriptor.blobs[0].blob_hash).get_is_verified()
)

View file

@ -133,7 +133,7 @@ class TestStreamManager(BlobExchangeTestBase):
sd_blob_duration = event['properties']['sd_blob_duration']
self.assertFalse(event['properties']['added_fixed_peers'])
self.assertEqual(event['properties']['wallet_server'], "fakespv.lbry.com:50001")
self.assertTrue(total_duration >= resolve_duration + head_blob_duration + sd_blob_duration)
self.assertGreaterEqual(total_duration, resolve_duration + head_blob_duration + sd_blob_duration)
await self._test_time_to_first_bytes(check_post)
@ -156,8 +156,8 @@ class TestStreamManager(BlobExchangeTestBase):
self.assertEqual(event['properties']['tried_peers_count'], 1)
self.assertEqual(event['properties']['active_peer_count'], 1)
self.assertEqual(event['properties']['connection_failures_count'], 0)
self.assertEqual(event['properties']['use_fixed_peers'], True)
self.assertEqual(event['properties']['added_fixed_peers'], True)
self.assertTrue(event['properties']['use_fixed_peers'])
self.assertTrue(event['properties']['added_fixed_peers'])
self.assertEqual(event['properties']['fixed_peer_delay'], self.client_config.fixed_peer_delay)
self.assertGreaterEqual(total_duration, resolve_duration + head_blob_duration + sd_blob_duration)
@ -196,14 +196,14 @@ class TestStreamManager(BlobExchangeTestBase):
self.assertEqual(event['event'], 'Time To First Bytes')
self.assertEqual(event['properties']['tried_peers_count'], 1)
self.assertEqual(event['properties']['active_peer_count'], 1)
self.assertEqual(event['properties']['use_fixed_peers'], True)
self.assertEqual(event['properties']['added_fixed_peers'], True)
self.assertTrue(event['properties']['use_fixed_peers'])
self.assertTrue(event['properties']['added_fixed_peers'])
self.assertEqual(event['properties']['fixed_peer_delay'], 0.0)
self.assertGreaterEqual(total_duration, resolve_duration + head_blob_duration + sd_blob_duration)
start = self.loop.time()
await self._test_time_to_first_bytes(check_post)
self.assertTrue(self.loop.time() - start < 3)
self.assertLess(self.loop.time() - start, 3)
async def test_no_peers_timeout(self):
# FIXME: the download should ideally fail right away if there are no peers
@ -216,9 +216,9 @@ class TestStreamManager(BlobExchangeTestBase):
self.assertEqual(event['properties']['error'], 'DownloadSDTimeout')
self.assertEqual(event['properties']['tried_peers_count'], 0)
self.assertEqual(event['properties']['active_peer_count'], 0)
self.assertEqual(event['properties']['use_fixed_peers'], False)
self.assertEqual(event['properties']['added_fixed_peers'], False)
self.assertEqual(event['properties']['fixed_peer_delay'], None)
self.assertFalse(event['properties']['use_fixed_peers'])
self.assertFalse(event['properties']['added_fixed_peers'])
self.assertIsNone(event['properties']['fixed_peer_delay'])
self.assertEqual(
event['properties']['error_message'], f'Failed to download sd blob {self.sd_hash} within timeout'
)
@ -277,7 +277,7 @@ class TestStreamManager(BlobExchangeTestBase):
stored_status = await self.client_storage.run_and_return_one_or_none(
"select status from file where stream_hash=?", stream_hash
)
self.assertEqual(stored_status, None)
self.assertIsNone(stored_status)
self.assertListEqual(expected_events, received)
async def _test_download_error_on_start(self, expected_error, timeout=None):

View file

@ -220,11 +220,11 @@ class ConfigurationTests(unittest.TestCase):
# disabled
args = parser.parse_args(['--no-max-key-fee'])
c = Config.create_from_arguments(args)
self.assertEqual(c.max_key_fee, None)
self.assertIsNone(c.max_key_fee)
args = parser.parse_args(['--max-key-fee', 'null'])
c = Config.create_from_arguments(args)
self.assertEqual(c.max_key_fee, None)
self.assertIsNone(c.max_key_fee)
# set
args = parser.parse_args(['--max-key-fee', '1.0', 'BTC'])

View file

@ -130,8 +130,8 @@ class BasicTransactionTests(IntegrationTestCase):
self.assertEqual(satoshis_to_coins(tx.inputs[1].amount), '1.1')
self.assertEqual(satoshis_to_coins(tx.outputs[0].amount), '2.0')
self.assertEqual(tx.outputs[0].get_address(self.ledger), address2)
self.assertEqual(tx.outputs[0].is_change, False)
self.assertEqual(tx.outputs[1].is_change, True)
self.assertFalse(tx.outputs[0].is_change)
self.assertTrue(tx.outputs[1].is_change)
async def test_history_edge_cases(self):
await self.assertBalance(self.account, '0.0')

View file

@ -19,5 +19,5 @@ class TestBCDataStream(unittest.TestCase):
self.assertEqual(s.read_string(), b'b'*254)
self.assertEqual(s.read_string(), b'c'*(0xFFFF + 1))
# self.assertEqual(s.read_string(), b'd'*(0xFFFFFFFF + 1))
self.assertEqual(s.read_boolean(), True)
self.assertEqual(s.read_boolean(), False)
self.assertTrue(s.read_boolean())
self.assertFalse(s.read_boolean())

View file

@ -357,14 +357,14 @@ class TestQueries(AsyncioTestCase):
tx = await self.ledger.db.get_transaction(txid=tx2.id)
self.assertEqual(tx.id, tx2.id)
self.assertEqual(tx.inputs[0].is_my_account, False)
self.assertEqual(tx.outputs[0].is_my_account, False)
self.assertFalse(tx.inputs[0].is_my_account)
self.assertFalse(tx.outputs[0].is_my_account)
tx = await self.ledger.db.get_transaction(wallet=wallet1, txid=tx2.id)
self.assertEqual(tx.inputs[0].is_my_account, True)
self.assertEqual(tx.outputs[0].is_my_account, False)
self.assertTrue(tx.inputs[0].is_my_account)
self.assertFalse(tx.outputs[0].is_my_account)
tx = await self.ledger.db.get_transaction(wallet=wallet2, txid=tx2.id)
self.assertEqual(tx.inputs[0].is_my_account, False)
self.assertEqual(tx.outputs[0].is_my_account, True)
self.assertFalse(tx.inputs[0].is_my_account)
self.assertTrue(tx.outputs[0].is_my_account)
# height 0 sorted to the top with the rest in descending order
tx4 = await self.create_tx_from_nothing(account1, 0)

View file

@ -74,7 +74,7 @@ class TestSynchronization(LedgerTestCase):
account = self.ledger.account_class.generate(self.ledger, Wallet(), "torba")
address = await account.receiving.get_or_create_usable_address()
address_details = await self.ledger.db.get_address(address=address)
self.assertEqual(address_details['history'], None)
self.assertIsNone(address_details['history'])
self.add_header(block_height=0, merkle_root=b'abcd04')
self.add_header(block_height=1, merkle_root=b'abcd04')