def test_bz2_add_fo(self): marfile = os.path.join(self.tmpdir, 'test.mar') with BZ2MarFile(None, fileobj=open(marfile, "wb")) as m: m.add(__file__) with BZ2MarFile(None, fileobj=open(marfile, "rb")) as m: self.assertEquals(len(m.members), 1) extracted = m.extract(m.members[0], self.tmpdir) self.assertEquals( open(extracted, 'rb').read(), open(__file__, 'rb').read())
def test_bz2_add_dir_fo(self): marfile = os.path.join(self.tmpdir, 'test.mar') dirname = os.path.dirname(__file__) with BZ2MarFile(None, fileobj=open(marfile, "wb")) as m: m.add(dirname) # List out the files in dirname so we can compare my_files = [] for root, dirs, files in os.walk(dirname): for f in files: my_files.append(os.path.join(root, f)) with BZ2MarFile(None, fileobj=open(marfile, "rb")) as m: self.assertEquals(len(m.members), len(my_files)) for member in m.members: self.assertTrue(member.name in my_files) self.assertEquals(member.flags, os.stat(member.name).st_mode & 0o777) extracted = m.extract(member, self.tmpdir) self.assertNotEquals(extracted, member.name) self.assertEquals( open(extracted, 'rb').read(), open(member.name, 'rb').read())
def extractMar(filename, tempdir): m = BZ2MarFile(filename) m.extractall(path=tempdir)
def test_list_fo_bz(self): self.check_list(BZ2MarFile(None, fileobj=open(TEST_MAR, 'rb')))
def test_list_name_bz(self): self.check_list(BZ2MarFile(TEST_MAR))
def test_extract_bz2_fo(self): self.check_extract_bz2(BZ2MarFile(None, fileobj=open(TEST_MAR, "rb")))
def test_extract_bz2(self): self.check_extract_bz2(BZ2MarFile(TEST_MAR))