python3-send2trash: add ptest support

The tests take less than a second to execute.

The current source distribution is missing a test file,
which I added with a patch. The problem is already solved
by upstream just not tagged yet - the patch can be dropped
with the next update.

Sample output:
root@qemux86-64:~# ptest-runner
START: ptest-runner
2026-01-09T17:11
BEGIN: /usr/lib/python3-send2trash/ptest
SKIP: tests/test_plat_win.py:tests/test_plat_win.py # SKIP Skipping windows-only tests
PASS: tests/test_plat_other.py:test_trash
PASS: tests/test_plat_other.py:test_multitrash
PASS: tests/test_plat_other.py:test_trash_bytes
PASS: tests/test_plat_other.py:test_trash_unicode
PASS: tests/test_plat_other.py:test_trash_topdir
PASS: tests/test_plat_other.py:test_trash_topdir_fallback
PASS: tests/test_plat_other.py:test_trash_topdir_failure
PASS: tests/test_plat_other.py:test_trash_symlink
PASS: tests/test_script_main.py:test_trash
PASS: tests/test_script_main.py:test_no_args
============================================================================
Testsuite summary
DURATION: 1
END: /usr/lib/python3-send2trash/ptest
2026-01-09T17:11
STOP: ptest-runner
TOTAL: 1 FAIL: 0

Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
This commit is contained in:
Gyorgy Sarvari
2026-01-09 19:03:21 +01:00
committed by Khem Raj
parent 520656c647
commit db427155f0
4 changed files with 66 additions and 1 deletions

View File

@@ -94,6 +94,7 @@ PTESTS_FAST_META_PYTHON = "\
python3-rich-toolkit \
python3-schedule \
python3-semver \
python3-send2trash \
python3-serpent \
python3-service-identity \
python3-setproctitle \

View File

@@ -0,0 +1,52 @@
From ed6d20884108fd7e681baf7278e38ac4800fb5c1 Mon Sep 17 00:00:00 2001
From: Gyorgy Sarvari <skandigraun@gmail.com>
Date: Fri, 9 Jan 2026 18:04:08 +0100
Subject: [PATCH] add missing conftest.py
Conftest.py is missing from the source dictribution of v2.0.0,
making the tests to fail.
The issue is already solved by upstream, but not tagged yet.
This patch can be removed with the next release.
Upstream-Status: Inappropriate [workaround until https://github.com/arsenetar/send2trash/commit/f8a40143f696da41f81cae87e1c7f9a345cd4003 is tagged]
Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
---
tests/conftest.py | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 tests/conftest.py
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..0753384
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,27 @@
+# encoding: utf-8
+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)

View File

@@ -0,0 +1,10 @@
#!/bin/sh
# Not all tests can run as root
useradd tester || echo test user already exists
# The test are running in /tmp folder by default, but
# the tests expect the test folder to be a regular folder, not
# a mount/symlink. Specify the TMP folder explicitly.
export TMP=/var/volatile/tmp
su tester -c "pytest --automake"

View File

@@ -2,8 +2,10 @@ SUMMARY = "Send file to trash natively under Mac OS X, Windows and Linux"
LICENSE = "BSD-3-Clause"
LIC_FILES_CHKSUM = "file://LICENSE;md5=a02659c2d5f4cc626e4dcf6504b865eb"
inherit pypi python_setuptools_build_meta
inherit pypi python_setuptools_build_meta ptest-python-pytest
SRC_URI += "file://0001-add-missing-conftest.py.patch \
file://run-ptest"
SRC_URI[sha256sum] = "1761421da3f9930bfe51ed7c45343948573383ad4c27e3acebc91be324e7770d"
PYPI_PACKAGE = "send2trash"