File: test_util_trash.py

package info (click to toggle)
quodlibet 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,228 kB
  • sloc: python: 89,728; sh: 381; xml: 110; makefile: 91
file content (74 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

"""Tests for quodlibet.util.trash."""

import os
import sys

from quodlibet import config
from quodlibet.util import is_linux, is_flatpak
from quodlibet.util.trash import use_trash, trash
from tests import TestCase, mkstemp, skipUnless


class TTrash(TestCase):
    def setUp(self):
        config.init()

    def tearDown(self):
        config.quit()

    def test_use_trash_is_false_on_non_posix(self):
        old_os_name = os.name
        try:
            os.name = "not posix"
            assert not use_trash()
        finally:
            os.name = old_os_name

    def test_use_trash_is_false_on_darwin(self):
        old_os_name = os.name
        old_sys_platform = sys.platform
        try:
            os.name = "posix"
            sys.platform = "darwin"
            assert not use_trash()
        finally:
            os.name = old_os_name
            sys.platform = old_sys_platform

    def test_use_trash_is_true_by_default_on_posix(self):
        old_os_name = os.name
        old_sys_platform = sys.platform
        try:
            os.name = "posix"
            sys.platform = "linux"
            if not is_flatpak():
                assert use_trash()
        finally:
            os.name = old_os_name
            sys.platform = old_sys_platform

    def test_use_trash_is_false_when_bypassed(self):
        old_os_name = os.name
        old_sys_platform = sys.platform
        try:
            config.set("settings", "bypass_trash", "true")
            os.name = "posix"
            sys.platform = "linux"
            assert not use_trash()
        finally:
            os.name = old_os_name
            sys.platform = old_sys_platform

    @skipUnless(is_linux(), reason="Trash only supported for Linux")
    def test_trash_removes_file(self):
        filename = mkstemp()[1]
        with open(filename, "w") as f:
            f.write("\n")
        assert os.path.exists(filename)
        trash(filename)
        assert not os.path.exists(filename)