Add failing test (on Python 2) for unicode file names

This commit is contained in:
Thomas Kluyver 2017-08-01 11:28:40 +01:00
parent dd69edad3b
commit 4181ed65e9
1 changed files with 36 additions and 3 deletions

View File

@ -1,3 +1,5 @@
# encoding: utf-8
import codecs
import unittest
import os
from os import path as op
@ -7,8 +9,11 @@ from configparser import ConfigParser
from tempfile import mkdtemp, NamedTemporaryFile, mktemp
import shutil
import stat
import sys
# Could still use cleaning up. But no longer relies on ramfs.
HOMETRASH = send2trash.plat_other.HOMETRASH
def touch(path):
with open(path, 'a'):
os.utime(path, None)
@ -23,10 +28,38 @@ class TestHomeTrash(unittest.TestCase):
def tearDown(self):
hometrash = send2trash.plat_other.HOMETRASH
name = op.basename(
os.remove(op.join(hometrash, 'files', name))
os.remove(op.join(hometrash, 'info', name+'.trashinfo'))
os.remove(op.join(HOMETRASH, 'files', name))
os.remove(op.join(HOMETRASH, 'info', name+'.trashinfo'))
def _filesys_enc():
enc = sys.getfilesystemencoding()
# Get canonical name of codec
return codecs.lookup(enc).name
@unittest.skipIf(_filesys_enc() == 'ascii', 'ASCII filesystem')
class TestUnicodeTrash(unittest.TestCase):
def setUp(self): = u'send2trash_tést1'
self.file = op.join(op.expanduser(b'~'),'utf-8'))
def test_trash_bytes(self):
assert not op.exists(self.file)
def test_trash_unicode(self):
assert not op.exists(self.file)
def tearDown(self):
if op.exists(self.file):
trash_file = op.join(HOMETRASH, 'files',
if op.exists(trash_file):
os.remove(op.join(HOMETRASH, 'info','.trashinfo'))
# Tests for files on some other volume than the user's home directory.