Browse Source

Fixed test for writing directories.

test_fixup
Travis Cunningham 9 years ago
parent
commit
b208154939
2 changed files with 11 additions and 5 deletions
  1. +2
    -0
      libarchive/__init__.py
  2. +9
    -5
      tests.py

+ 2
- 0
libarchive/__init__.py View File

@@ -539,6 +539,7 @@ class Archive(object):
if data:
member.size = len(data)
member.to_archive(self)
if data:
_libarchive.archive_write_data_from_str(self._a, data)
_libarchive.archive_write_finish_entry(self._a)
@@ -554,6 +555,7 @@ class Archive(object):
member.pathname = pathname
if folder and not member.isdir():
member.mode = stat.S_IFDIR

if hasattr(f, 'read'):
# TODO: optimize this to write directly from f to archive.
self.write(member, data=f.read())


+ 9
- 5
tests.py View File

@@ -43,12 +43,13 @@ FILENAMES = [
#'álért.txt',
]


def make_temp_files():
print TMPDIR
if not os.path.exists(ZIPPATH):
for name in FILENAMES:
file(os.path.join(TMPDIR, name), 'w').write(''.join(random.sample(string.printable, 10)))


def make_temp_archive():
if not os.access(ZIPCMD, os.X_OK):
raise AssertionError('Cannot execute %s.' % ZIPCMD)
@@ -56,7 +57,7 @@ def make_temp_archive():
make_temp_files()
cmd.extend(FILENAMES)
os.chdir(TMPDIR)
subprocess.call(cmd)
subprocess.call(cmd, stdout=subprocess.PIPE)


class TestIsArchiveName(unittest.TestCase):
@@ -175,15 +176,18 @@ class TestZipWrite(unittest.TestCase):

f = file(ZIPPATH, mode='w')
z = ZipFile(f, 'w')
z.writepath('/home/user/testpath', pathname='/testdir', folder=True)
z.writepath(None, pathname='/testdir', folder=True)
z.writepath(None, pathname='/testdir/testinside', folder=True)
z.close()
f.close()

f = file(ZIPPATH, mode='r')
z = ZipFile(f, 'r')

assert len(z.entries) == 1
assert z.entries[0].isdir()
entries = z.infolist()

assert len(entries) == 2
assert entries[0].isdir()
z.close()
f.close()



Loading…
Cancel
Save