1# coding: utf-8
2
3import tarfile
4import io
5
6from setuptools.extern import six
7
8import pytest
9
10from setuptools import archive_util
11
12
13@pytest.fixture
14def tarfile_with_unicode(tmpdir):
15    """
16    Create a tarfile containing only a file whose name is
17    a zero byte file called testimäge.png.
18    """
19    tarobj = io.BytesIO()
20
21    with tarfile.open(fileobj=tarobj, mode="w:gz") as tgz:
22        data = b""
23
24        filename = "testimäge.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")
40def test_unicode_files(tarfile_with_unicode, tmpdir):
41    target = tmpdir / 'out'
42    archive_util.unpack_archive(tarfile_with_unicode, six.text_type(target))
43