def test_append_mode(self): source_data = 'Some text\nwith newlines\n' storage._store.clear() handle = storage.open(FILE, 'ab') try: f = storage.open(FILE) try: self.assertEqual(f.read(), '') finally: f.close() handle.write(source_data) finally: handle.close() handle = storage.open(FILE, 'rb') try: self.assertEqual(handle.read(), source_data) finally: handle.close() handle = storage.open(FILE, 'a') try: self.assertEqual(handle.tell(), len(source_data)) handle.write(source_data[::-1]) finally: handle.close() handle = storage.open(FILE) try: self.assertEqual(handle.read(), source_data + source_data[::-1]) finally: handle.close()
def test_open_simple_read_and_write(self): source_data = 'Some text\nwith newlines\n' handle = storage.open(FILE, 'w') self.assertTrue(isinstance(handle, storage.file)) self.assertEqual(handle.mode, 'w') handle.write(source_data) handle.close() handle = storage.open(FILE, 'r') self.assertTrue(isinstance(handle, storage.file)) data = handle.read() self.assertEqual(handle.mode, 'r') handle.close() self.assertEqual(data, source_data) handle = storage.open(FILE) self.assertTrue(isinstance(handle, storage.file)) self.assertEqual(handle.mode, 'r') data = handle.read() handle.close() self.assertEqual(data, source_data)