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

First batch of updates to unit tests

- Remove content from __init__.py
- Change test_script_main to use pytest
- Update test_script_main to run on windows as well as linux
This commit is contained in:
Andrew Senetar 2021-03-02 00:26:29 -06:00
parent 054d56c564
commit dbdcce8b04
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
2 changed files with 31 additions and 40 deletions

View File

@ -1,18 +0,0 @@
import sys
import unittest
def TestSuite():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
if sys.platform == "win32":
from . import test_plat_win
suite.addTests(loader.loadTestsFromModule(test_plat_win))
else:
from . import test_script_main
from . import test_plat_other
suite.addTests(loader.loadTestsFromModule(test_script_main))
suite.addTests(loader.loadTestsFromModule(test_plat_other))
return suite

View File

@ -1,32 +1,41 @@
# encoding: utf-8 # encoding: utf-8
import os import os
import unittest import sys
import pytest
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from os import path as op from os import path as op
from send2trash.__main__ import main as trash_main from send2trash.__main__ import main as trash_main
from tests.test_plat_other import HOMETRASH
# Only import HOMETRASH on supported platforms
if sys.platform != "win32":
from send2trash.plat_other import HOMETRASH
class TestMainTrash(unittest.TestCase): @pytest.fixture
def setUp(self): def file():
self.file = NamedTemporaryFile(dir=op.expanduser('~'), prefix='send2trash_test', delete=False) file = NamedTemporaryFile(
dir=op.expanduser("~"), prefix="send2trash_test", delete=False
def test_trash(self): )
trash_main(['-v', self.file.name]) file.close()
self.assertFalse(op.exists(self.file.name)) yield file.name
# Cleanup trash files on supported platforms
def test_no_args(self): if sys.platform != "win32":
self.assertRaises(SystemExit, trash_main, []) name = op.basename(file.name)
self.assertRaises(SystemExit, trash_main, ['-v']) # Remove trash files if they exist
self.assertTrue(op.exists(self.file.name)) if op.exists(op.join(HOMETRASH, "files", name)):
trash_main([self.file.name]) # Trash the file so tearDown runs properly os.remove(op.join(HOMETRASH, "files", name))
os.remove(op.join(HOMETRASH, "info", name + ".trashinfo"))
def tearDown(self): if op.exists(file.name):
name = op.basename(self.file.name) os.remove(file.name)
os.remove(op.join(HOMETRASH, 'files', name))
os.remove(op.join(HOMETRASH, 'info', name + '.trashinfo'))
if __name__ == '__main__': def test_trash(file):
unittest.main() trash_main(["-v", file])
assert op.exists(file) is False
def test_no_args(file):
pytest.raises(SystemExit, trash_main, [])
pytest.raises(SystemExit, trash_main, ["-v"])
assert op.exists(file) is True