You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. # encoding: utf-8
  2. import os
  3. import sys
  4. import pytest
  5. from tempfile import NamedTemporaryFile
  6. from os import path as op
  7. from send2trash.__main__ import main as trash_main
  8. # Only import HOMETRASH on supported platforms
  9. if sys.platform != "win32":
  10. from send2trash.plat_other import HOMETRASH
  11. @pytest.fixture
  12. def file():
  13. file = NamedTemporaryFile(
  14. dir=op.expanduser("~"), prefix="send2trash_test", delete=False
  15. )
  16. file.close()
  17. yield file.name
  18. # Cleanup trash files on supported platforms
  19. if sys.platform != "win32":
  20. name = op.basename(file.name)
  21. # Remove trash files if they exist
  22. if op.exists(op.join(HOMETRASH, "files", name)):
  23. os.remove(op.join(HOMETRASH, "files", name))
  24. os.remove(op.join(HOMETRASH, "info", name + ".trashinfo"))
  25. if op.exists(file.name):
  26. os.remove(file.name)
  27. def test_trash(file):
  28. trash_main(["-v", file])
  29. assert op.exists(file) is False
  30. def test_no_args(file):
  31. pytest.raises(SystemExit, trash_main, [])
  32. pytest.raises(SystemExit, trash_main, ["-v"])
  33. assert op.exists(file) is True