File: test_script_main.py

package info (click to toggle)
send2trash 1.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: python: 816; sh: 13; makefile: 10
file content (41 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# encoding: utf-8
import os
import sys
import pytest
from tempfile import NamedTemporaryFile
from os import path as op

from send2trash.__main__ import main as trash_main

# Only import HOMETRASH on supported platforms
if sys.platform != "win32":
    from send2trash.plat_other import HOMETRASH


@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):
    pytest.raises(SystemExit, trash_main, [])
    pytest.raises(SystemExit, trash_main, ["-v"])
    assert op.exists(file) is True