def _test_writer_netascii_mode(self, data): fname = get_random_filename() fw = TftpFileWriter(fname, 'netascii') write_whole_file(fw, data) self.assertTrue(fw._file.closed) with open(fname, mode='rb') as f: _buffer = f.read() self.assertEqual(_buffer, netascii.decode(data))
def _test_write_to_closed_file(self, mode): """ When trying to write to a closed file, a TftpIOError should be raised. """ fname = get_random_filename() fw = TftpFileWriter(fname, mode) if mode == 'netascii': write_whole_file(fw, netascii.decode(LOREM_IPSUM)) elif mode == 'octet': write_whole_file(fw, LOREM_IPSUM) self.assertTrue(fw._file.closed) with self.assertRaises(TftpIOError): fw.write_next_block('data'.encode())