diff --git a/lbrynet/testcase.py b/lbrynet/testcase.py index 29a487cf2..cc508d3a8 100644 --- a/lbrynet/testcase.py +++ b/lbrynet/testcase.py @@ -172,27 +172,43 @@ class CommandTestCase(IntegrationTestCase): return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result'] async def stream_create(self, name='hovercraft', bid='1.0', data=b'hi!', confirm=True, **kwargs): - with tempfile.NamedTemporaryFile() as file: - file.write(data) - file.flush() - claim = await self.out( - self.daemon.jsonrpc_stream_create(name, bid, file_path=file.name, **kwargs) - ) - self.assertEqual(claim['outputs'][0]['name'], name) - if confirm: - await self.on_transaction_dict(claim) - await self.generate(1) - await self.on_transaction_dict(claim) - return claim + file = tempfile.NamedTemporaryFile() + + def cleanup(): + try: + file.close() + except FileNotFoundError: + pass + + self.addCleanup(cleanup) + file.write(data) + file.flush() + claim = await self.out( + self.daemon.jsonrpc_stream_create(name, bid, file_path=file.name, **kwargs) + ) + self.assertEqual(claim['outputs'][0]['name'], name) + if confirm: + await self.on_transaction_dict(claim) + await self.generate(1) + await self.on_transaction_dict(claim) + return claim async def stream_update(self, claim_id, data=None, confirm=True, **kwargs): if data: - with tempfile.NamedTemporaryFile() as file: - file.write(data) - file.flush() - claim = await self.out( - self.daemon.jsonrpc_stream_update(claim_id, file_path=file.name, **kwargs) - ) + file = tempfile.NamedTemporaryFile() + file.write(data) + file.flush() + + def cleanup(): + try: + file.close() + except FileNotFoundError: + pass + + self.addCleanup(cleanup) + claim = await self.out( + self.daemon.jsonrpc_stream_update(claim_id, file_path=file.name, **kwargs) + ) else: claim = await self.out(self.daemon.jsonrpc_stream_update(claim_id, **kwargs)) self.assertIsNotNone(claim['outputs'][0]['name']) diff --git a/tests/integration/test_streaming.py b/tests/integration/test_streaming.py index da696a798..c36a5bdd8 100644 --- a/tests/integration/test_streaming.py +++ b/tests/integration/test_streaming.py @@ -97,7 +97,7 @@ class RangeRequests(CommandTestCase): async def test_range_requests_no_padding_size_from_claim(self): size = ((MAX_BLOB_SIZE - 1) * 4) - 14 await self.test_range_requests_0_padded_bytes(size, padding=b'', file_size=size, - expected_range=f"bytes 0-{size}/{size+1}") + expected_range=f"bytes 0-{size-1}/{size}") async def test_range_requests_15_padded_bytes(self): await self.test_range_requests_0_padded_bytes(