def test_tell(self): raw = RawDirect(self.file) raw.write('A' * 512) self.assertEquals(raw.tell(), 512) raw.write('B' * 512) self.assertEquals(raw.tell(), 1024) raw.seek(0) self.assertEquals(raw.read(512), ('A' * 512)) self.assertEquals(raw.read(512), ('B' * 512)) self.assertEquals(raw.tell(), 1024)
def test_write_past_device_eof(self): # Create a sparse file that is less than the block size fd, file = tempfile.mkstemp(dir='/tmp') os.ftruncate(fd, 511) os.close(fd) try: # Mount the file as a loopback device (simulate a block device) device = find_loopback_device() call("losetup %s %s" % (device, file), shell=True) raw = RawDirect(device) # Should raise IOError: [Errno 28] No space left on device self.assertRaises(OSError, raw.write, 'A' * 512) self.assertEquals(raw.tell(), 0) self.assertEquals(os.lseek(raw._fd, 0, os.SEEK_CUR), 0) raw.close() finally: call("losetup -d %s" % device, shell=True)