1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2026-01-22 14:41:40 +00:00

Fix silently failing on Windows (#33)

* Fix #31: Silently failing on Windows

* Update Windows test

* Fix test folders not getting removed
This commit is contained in:
sharkykh
2019-04-30 19:28:09 +03:00
committed by Virgil Dupras
parent 8f684a9c8b
commit 66afce7252
2 changed files with 39 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
# coding: utf-8
import os
import shutil
import sys
import unittest
from os import path as op
@@ -8,12 +9,37 @@ from tempfile import gettempdir
from send2trash import send2trash as s2t
@unittest.skipIf(sys.platform != 'win32', 'Windows only')
class TestNormal(unittest.TestCase):
def setUp(self):
self.dirname = '\\\\?\\' + op.join(gettempdir(), 'python.send2trash')
self.file = op.join(self.dirname, 'testfile.txt')
self._create_tree(self.file)
def tearDown(self):
shutil.rmtree(self.dirname, ignore_errors=True)
def _create_tree(self, path):
dirname = op.dirname(path)
if not op.isdir(dirname):
os.makedirs(dirname)
with open(path, 'w') as writer:
writer.write('send2trash test')
def test_trash_file(self):
s2t(self.file)
self.assertFalse(op.exists(self.file))
def test_file_not_found(self):
file = op.join(self.dirname, 'otherfile.txt')
self.assertRaises(WindowsError, s2t, file)
@unittest.skipIf(sys.platform != 'win32', 'Windows only')
class TestLongPath(unittest.TestCase):
def setUp(self):
filename = 'A' * 100
self.dirname = '\\\\?\\' + os.path.join(gettempdir(), filename)
self.file = os.path.join(
self.dirname = '\\\\?\\' + op.join(gettempdir(), filename)
self.file = op.join(
self.dirname,
filename,
filename, # From there, the path is not trashable from Explorer
@@ -22,14 +48,11 @@ class TestLongPath(unittest.TestCase):
self._create_tree(self.file)
def tearDown(self):
try:
os.remove(self.dirname)
except OSError:
pass
shutil.rmtree(self.dirname, ignore_errors=True)
def _create_tree(self, path):
dirname = os.path.dirname(path)
if not os.path.isdir(dirname):
dirname = op.dirname(path)
if not op.isdir(dirname):
os.makedirs(dirname)
with open(path, 'w') as writer:
writer.write('Looong filename!')