def test_close_callbacks_when_not_enabled(self): with open(self.filename) as f: chunk = ReadFileChunk(f, chunk_size=1, full_file_size=3, enable_callbacks=False, close_callbacks=[self.close_callback]) chunk.close() self.assertEqual(self.num_close_callback_calls, 0)
def test_close_callbacks_when_context_handler_is_used(self): with open(self.filename) as f: with ReadFileChunk(f, chunk_size=1, full_file_size=3, close_callbacks=[self.close_callback]) as chunk: chunk.read(1) self.assertEqual(self.num_close_callback_calls, 1)
def test_close_callbacks(self): with open(self.filename) as f: chunk = ReadFileChunk(f, chunk_size=1, full_file_size=3, close_callbacks=[self.close_callback]) chunk.close() self.assertEqual(self.num_close_callback_calls, 1)
def test_no_call_signal_not_transferring_to_underlying_fileobj(self): underlying_stream = mock.Mock(io.RawIOBase) underlying_stream.tell.return_value = 0 chunk = ReadFileChunk(underlying_stream, 3, 3) try: chunk.signal_not_transferring() except AttributeError: self.fail('The stream should not have tried to call ' 'signal_not_transferring to the underlying stream.')
def test_signal_not_transferring_to_underlying_fileobj(self): underlying_stream = mock.Mock() underlying_stream.tell.return_value = 0 chunk = ReadFileChunk(underlying_stream, 3, 3) chunk.signal_not_transferring() self.assertTrue(underlying_stream.signal_not_transferring.called)