Home | History | Annotate | Download | only in tests
      1 # coding: utf-8
      2 
      3 import tarfile
      4 import io
      5 
      6 from setuptools.extern import six
      7 
      8 import pytest
      9 
     10 from setuptools import archive_util
     11 
     12 
     13 @pytest.fixture
     14 def tarfile_with_unicode(tmpdir):
     15     """
     16     Create a tarfile containing only a file whose name is
     17     a zero byte file called testimage.png.
     18     """
     19     tarobj = io.BytesIO()
     20 
     21     with tarfile.open(fileobj=tarobj, mode="w:gz") as tgz:
     22         data = b""
     23 
     24         filename = "testimage.png"
     25         if six.PY2:
     26             filename = filename.decode('utf-8')
     27 
     28         t = tarfile.TarInfo(filename)
     29         t.size = len(data)
     30 
     31         tgz.addfile(t, io.BytesIO(data))
     32 
     33     target = tmpdir / 'unicode-pkg-1.0.tar.gz'
     34     with open(str(target), mode='wb') as tf:
     35         tf.write(tarobj.getvalue())
     36     return str(target)
     37 
     38 
     39 @pytest.mark.xfail(reason="#710 and #712")
     40 def test_unicode_files(tarfile_with_unicode, tmpdir):
     41     target = tmpdir / 'out'
     42     archive_util.unpack_archive(tarfile_with_unicode, six.text_type(target))
     43