mirror of
https://github.com/arsenetar/send2trash.git
synced 2026-01-22 14:41:40 +00:00
tests: Cleanup some pylint errors and share common fixture
- Cleanup some of the pylint erros in the tests - Reorganize some of the tests functions and fixtures - Move the one common fixture to conftest.py for sharing
This commit is contained in:
@@ -1,41 +1,16 @@
|
||||
# encoding: utf-8
|
||||
import os
|
||||
import sys
|
||||
import pytest
|
||||
from tempfile import NamedTemporaryFile
|
||||
from os import path as op
|
||||
import pytest
|
||||
|
||||
from send2trash.__main__ import main as trash_main
|
||||
|
||||
# Only import HOMETRASH on supported platforms
|
||||
if sys.platform != "win32":
|
||||
from send2trash.plat_other import HOMETRASH
|
||||
|
||||
def test_trash(test_file):
|
||||
trash_main(["-v", test_file])
|
||||
assert op.exists(test_file) is False
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def file():
|
||||
file = NamedTemporaryFile(dir=op.expanduser("~"), prefix="send2trash_test", delete=False)
|
||||
file.close()
|
||||
# Verify file was actually created
|
||||
assert op.exists(file.name) is True
|
||||
yield file.name
|
||||
# Cleanup trash files on supported platforms
|
||||
if sys.platform != "win32":
|
||||
name = op.basename(file.name)
|
||||
# Remove trash files if they exist
|
||||
if op.exists(op.join(HOMETRASH, "files", name)):
|
||||
os.remove(op.join(HOMETRASH, "files", name))
|
||||
os.remove(op.join(HOMETRASH, "info", name + ".trashinfo"))
|
||||
if op.exists(file.name):
|
||||
os.remove(file.name)
|
||||
|
||||
|
||||
def test_trash(file):
|
||||
trash_main(["-v", file])
|
||||
assert op.exists(file) is False
|
||||
|
||||
|
||||
def test_no_args(file):
|
||||
def test_no_args(test_file):
|
||||
pytest.raises(SystemExit, trash_main, [])
|
||||
pytest.raises(SystemExit, trash_main, ["-v"])
|
||||
assert op.exists(file) is True
|
||||
assert op.exists(test_file) is True
|
||||
|
||||
Reference in New Issue
Block a user