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.

44 lines
1.2 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. # Verify file was actually created
  18. assert op.exists(file.name) is True
  19. yield file.name
  20. # Cleanup trash files on supported platforms
  21. if sys.platform != "win32":
  22. name = op.basename(file.name)
  23. # Remove trash files if they exist
  24. if op.exists(op.join(HOMETRASH, "files", name)):
  25. os.remove(op.join(HOMETRASH, "files", name))
  26. os.remove(op.join(HOMETRASH, "info", name + ".trashinfo"))
  27. if op.exists(file.name):
  28. os.remove(file.name)
  29. def test_trash(file):
  30. trash_main(["-v", file])
  31. assert op.exists(file) is False
  32. def test_no_args(file):
  33. pytest.raises(SystemExit, trash_main, [])
  34. pytest.raises(SystemExit, trash_main, ["-v"])
  35. assert op.exists(file) is True