1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2024-12-21 10:59:03 +00:00

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

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):
self.assertFalse(op.exists(self.file.name))
def tearDown(self):
hometrash = send2trash.plat_other.HOMETRASH
name = op.basename(self.file.name)
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):
self.name = u'send2trash_tést1'
self.file = op.join(op.expanduser(b'~'), self.name.encode('utf-8'))
touch(self.file)
def test_trash_bytes(self):
s2t(self.file)
assert not op.exists(self.file)
def test_trash_unicode(self):
s2t(self.file.decode(sys.getfilesystemencoding()))
assert not op.exists(self.file)
def tearDown(self):
if op.exists(self.file):
os.remove(self.file)
trash_file = op.join(HOMETRASH, 'files', self.name)
if op.exists(trash_file):
os.remove(trash_file)
os.remove(op.join(HOMETRASH, 'info', self.name+'.trashinfo'))
#
# Tests for files on some other volume than the user's home directory.