def test_empty_sparse(self): with namedTemporaryDir() as tmpdir: filename = os.path.join(tmpdir, 'test') with io.open(filename, "wb") as f: f.truncate(MB) runs = qemuimg.map(filename) self.assertEqual(qcow2.count_clusters(runs), 0)
def test_full(self): with namedTemporaryDir() as tmpdir: filename = os.path.join(tmpdir, 'test') with io.open(filename, "wb") as f: f.write(b"x" * qcow2.CLUSTER_SIZE * 3) runs = qemuimg.map(filename) self.assertEqual(qcow2.count_clusters(runs), 3)
def test_multiple_blocks(self, tmpdir): filename = str(tmpdir.join("test")) with io.open(filename, "wb") as f: f.write(b"x") f.seek(16 * 1024) f.write(b"x") f.seek(42 * 1024) f.write(b"x") runs = qemuimg.map(filename) assert qcow2.count_clusters(runs) == 1
def test_multiple_blocks(self): with namedTemporaryDir() as tmpdir: filename = os.path.join(tmpdir, 'test') with io.open(filename, "wb") as f: f.write(b"x") f.seek(16 * 1024) f.write(b"x") f.seek(42 * 1024) f.write(b"x") runs = qemuimg.map(filename) self.assertEqual(qcow2.count_clusters(runs), 1)
def test_big_sparse(self, tmpdir): filename = str(tmpdir.join("test")) with io.open(filename, "wb") as f: f.truncate(1024 * MB) # First cluster f.write(b"x") # Second cluster f.seek(512 * MB) f.write(b"x") runs = qemuimg.map(filename) assert qcow2.count_clusters(runs) == 2
def test_big_sparse(self): with namedTemporaryDir() as tmpdir: filename = os.path.join(tmpdir, 'test') with io.open(filename, "wb") as f: f.truncate(1024 * MB) # First cluster f.write(b"x") # Second cluster f.seek(512 * MB) f.write(b"x") runs = qemuimg.map(filename) self.assertEqual(qcow2.count_clusters(runs), 2)
def test_partial(self, tmpdir): filename = str(tmpdir.join("test")) with io.open(filename, "wb") as f: f.truncate(MB) # First cluster f.seek(8192) f.write(b"x") # Second cluster f.seek(qcow2.CLUSTER_SIZE) f.write(b"x") f.seek(qcow2.CLUSTER_SIZE * 2 - 1) f.write(b"x") # Third cluster f.seek(qcow2.CLUSTER_SIZE * 2) f.write(b"x") runs = qemuimg.map(filename) assert qcow2.count_clusters(runs) == 3
def test_partial(self): with namedTemporaryDir() as tmpdir: filename = os.path.join(tmpdir, 'test') with io.open(filename, "wb") as f: f.truncate(MB) # First cluster f.seek(8192) f.write(b"x") # Second cluster f.seek(qcow2.CLUSTER_SIZE) f.write(b"x") f.seek(qcow2.CLUSTER_SIZE * 2 - 1) f.write(b"x") # Third cluster f.seek(qcow2.CLUSTER_SIZE * 2) f.write(b"x") runs = qemuimg.map(filename) self.assertEqual(qcow2.count_clusters(runs), 3)
def test_full(self, tmpdir): filename = str(tmpdir.join("test")) with io.open(filename, "wb") as f: f.write(b"x" * qcow2.CLUSTER_SIZE * 3) runs = qemuimg.map(filename) assert qcow2.count_clusters(runs) == 3
def test_empty_sparse(self, tmpdir): filename = str(tmpdir.join("test")) with io.open(filename, "wb") as f: f.truncate(MB) runs = qemuimg.map(filename) assert qcow2.count_clusters(runs) == 0
def test_empty(self, tmpdir): filename = str(tmpdir.join("test")) with io.open(filename, "wb"): pass runs = qemuimg.map(filename) assert qcow2.count_clusters(runs) == 0