mirror of
https://github.com/arsenetar/send2trash.git
synced 2025-05-08 01:39:51 +00:00
Update windows tests to test both versions
This fixes #44 by testing the automatic import, the legacy version, and the modern version directtly.
This commit is contained in:
parent
d078554052
commit
e3d2be3243
@ -9,6 +9,7 @@ matrix:
|
|||||||
- choco install python3 --params "/InstallDir:C:\Python"
|
- choco install python3 --params "/InstallDir:C:\Python"
|
||||||
- export PATH="/c/Python:/c/Python/Scripts:$PATH"
|
- export PATH="/c/Python:/c/Python/Scripts:$PATH"
|
||||||
- python -m pip install --upgrade pip
|
- python -m pip install --upgrade pip
|
||||||
|
- python -m pip install pywin32
|
||||||
before_script:
|
before_script:
|
||||||
- export TOXENV=py3-win
|
- export TOXENV=py3-win
|
||||||
|
|
||||||
|
@ -8,6 +8,10 @@ from tempfile import gettempdir
|
|||||||
|
|
||||||
from send2trash import send2trash as s2t
|
from send2trash import send2trash as s2t
|
||||||
|
|
||||||
|
# import the two versions as well as the "automatic" version
|
||||||
|
from send2trash.plat_win_modern import send2trash as s2t_modern
|
||||||
|
from send2trash.plat_win_legacy import send2trash as s2t_legacy
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform != "win32", "Windows only")
|
@unittest.skipIf(sys.platform != "win32", "Windows only")
|
||||||
class TestNormal(unittest.TestCase):
|
class TestNormal(unittest.TestCase):
|
||||||
@ -30,22 +34,50 @@ class TestNormal(unittest.TestCase):
|
|||||||
with open(path, "w") as writer:
|
with open(path, "w") as writer:
|
||||||
writer.write("send2trash test")
|
writer.write("send2trash test")
|
||||||
|
|
||||||
def test_trash_file(self):
|
def _trash_file(self, fcn):
|
||||||
s2t(self.file)
|
fcn(self.file)
|
||||||
self.assertFalse(op.exists(self.file))
|
self.assertFalse(op.exists(self.file))
|
||||||
|
|
||||||
def test_trash_multifile(self):
|
def _trash_multifile(self, fcn):
|
||||||
s2t(self.files)
|
fcn(self.files)
|
||||||
self.assertFalse(any([op.exists(file) for file in self.files]))
|
self.assertFalse(any([op.exists(file) for file in self.files]))
|
||||||
|
|
||||||
def test_file_not_found(self):
|
def _file_not_found(self, fcn):
|
||||||
file = op.join(self.dirname, "otherfile.txt")
|
file = op.join(self.dirname, "otherfile.txt")
|
||||||
self.assertRaises(WindowsError, s2t, file)
|
self.assertRaises(WindowsError, fcn, file)
|
||||||
|
|
||||||
|
def test_trash_file(self):
|
||||||
|
self._trash_file(s2t)
|
||||||
|
|
||||||
|
def test_trash_multifile(self):
|
||||||
|
self._trash_multifile(s2t)
|
||||||
|
|
||||||
|
def test_file_not_found(self):
|
||||||
|
self._file_not_found(s2t)
|
||||||
|
|
||||||
|
def test_trash_file_modern(self):
|
||||||
|
self._trash_file(s2t_modern)
|
||||||
|
|
||||||
|
def test_trash_multifile_modern(self):
|
||||||
|
self._trash_multifile(s2t_modern)
|
||||||
|
|
||||||
|
def test_file_not_found_modern(self):
|
||||||
|
self._file_not_found(s2t_modern)
|
||||||
|
|
||||||
|
def test_trash_file_legacy(self):
|
||||||
|
self._trash_file(s2t_legacy)
|
||||||
|
|
||||||
|
def test_trash_multifile_legacy(self):
|
||||||
|
self._trash_multifile(s2t_legacy)
|
||||||
|
|
||||||
|
def test_file_not_found_legacy(self):
|
||||||
|
self._file_not_found(s2t_legacy)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform != "win32", "Windows only")
|
@unittest.skipIf(sys.platform != "win32", "Windows only")
|
||||||
class TestLongPath(unittest.TestCase):
|
class TestLongPath(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.functions = {s2t: "auto", s2t_legacy: "legacy", s2t_modern: "modern"}
|
||||||
filename = "A" * 100
|
filename = "A" * 100
|
||||||
self.dirname = "\\\\?\\" + op.join(gettempdir(), filename)
|
self.dirname = "\\\\?\\" + op.join(gettempdir(), filename)
|
||||||
path = op.join(
|
path = op.join(
|
||||||
@ -70,18 +102,53 @@ class TestLongPath(unittest.TestCase):
|
|||||||
with open(path, "w") as writer:
|
with open(path, "w") as writer:
|
||||||
writer.write("Looong filename!")
|
writer.write("Looong filename!")
|
||||||
|
|
||||||
def test_trash_file(self):
|
def _trash_file(self, fcn):
|
||||||
s2t(self.file)
|
fcn(self.file)
|
||||||
self.assertFalse(op.exists(self.file))
|
self.assertFalse(op.exists(self.file))
|
||||||
|
|
||||||
def test_trash_multifile(self):
|
def _trash_multifile(self, fcn):
|
||||||
s2t(self.files)
|
fcn(self.files)
|
||||||
self.assertFalse(any([op.exists(file) for file in self.files]))
|
self.assertFalse(any([op.exists(file) for file in self.files]))
|
||||||
|
|
||||||
|
def _trash_folder(self, fcn):
|
||||||
|
fcn(self.dirname)
|
||||||
|
self.assertFalse(op.exists(self.dirname))
|
||||||
|
|
||||||
|
def test_trash_file(self):
|
||||||
|
self._trash_file(s2t)
|
||||||
|
|
||||||
|
def test_trash_multifile(self):
|
||||||
|
self._trash_multifile(s2t)
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
op.splitdrive(os.getcwd())[0] != op.splitdrive(gettempdir())[0],
|
op.splitdrive(os.getcwd())[0] != op.splitdrive(gettempdir())[0],
|
||||||
"Cannot trash long path from other drive",
|
"Cannot trash long path from other drive",
|
||||||
)
|
)
|
||||||
def test_trash_folder(self):
|
def test_trash_folder(self):
|
||||||
s2t(self.dirname)
|
self._trash_folder(s2t)
|
||||||
self.assertFalse(op.exists(self.dirname))
|
|
||||||
|
def test_trash_file_modern(self):
|
||||||
|
self._trash_file(s2t_modern)
|
||||||
|
|
||||||
|
def test_trash_multifile_modern(self):
|
||||||
|
self._trash_multifile(s2t_modern)
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
op.splitdrive(os.getcwd())[0] != op.splitdrive(gettempdir())[0],
|
||||||
|
"Cannot trash long path from other drive",
|
||||||
|
)
|
||||||
|
def test_trash_folder_modern(self):
|
||||||
|
self._trash_folder(s2t_modern)
|
||||||
|
|
||||||
|
def test_trash_file_legacy(self):
|
||||||
|
self._trash_file(s2t_legacy)
|
||||||
|
|
||||||
|
def test_trash_multifile_legacy(self):
|
||||||
|
self._trash_multifile(s2t_legacy)
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
op.splitdrive(os.getcwd())[0] != op.splitdrive(gettempdir())[0],
|
||||||
|
"Cannot trash long path from other drive",
|
||||||
|
)
|
||||||
|
def test_trash_folder_legacy(self):
|
||||||
|
self._trash_folder(s2t_legacy)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user