1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2026-01-28 01:21:40 +00:00
Files
send2trash/tests/conftest.py
Yaofei Zheng ad0f2af984 python2 removal: more clean up (#107)
1. remove from __future__ as those feature is mandatory >= 3.0 and we are in the future
2. python3 script defaults to UTF-8
2026-01-27 00:57:55 -06:00

27 lines
915 B
Python

import sys
import os
from tempfile import NamedTemporaryFile
import pytest
# Only import HOMETRASH on supported platforms
if sys.platform != "win32":
from send2trash.plat_other import HOMETRASH
@pytest.fixture(name="test_file")
def fixture_test_file():
file = NamedTemporaryFile(dir=os.path.expanduser("~"), prefix="send2trash_test", delete=False)
file.close()
# Verify file was actually created
assert os.path.exists(file.name) is True
yield file.name
# Cleanup trash files on supported platforms
if sys.platform != "win32":
name = os.path.basename(file.name)
# Remove trash files if they exist
if os.path.exists(os.path.join(HOMETRASH, "files", name)):
os.remove(os.path.join(HOMETRASH, "files", name))
os.remove(os.path.join(HOMETRASH, "info", name + ".trashinfo"))
if os.path.exists(file.name):
os.remove(file.name)