summaryrefslogtreecommitdiff
blob: 75bd478f670dadaeb4131f4bedcdc6e3cb2a3193 (plain)
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
From 566dbd8bdde01514c5cf0802d03a9dca918b6e82 Mon Sep 17 00:00:00 2001
From: Zoltan Puskas <zoltan@sinustrom.info>
Date: Sat, 4 Dec 2021 12:59:37 -0800
Subject: [PATCH] Fix unit test test_trash_empty_will_skip_unreadable_dir

This patch fixes two issues with the current test:
- it prevents the test from breaking out of the test environment and
  does not try to clean trash directories for all mount points
- it does actually test the "unreadable" directory

Bug: GH-217
---
 tests/test_trash_empty.py | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/tests/test_trash_empty.py b/tests/test_trash_empty.py
index c7a987d..a2f87e6 100644
--- a/tests/test_trash_empty.py
+++ b/tests/test_trash_empty.py
@@ -15,26 +15,35 @@ from .support import MyPath
 from trashcli.fs import FileSystemReader
 from trashcli.fs import FileRemover
 
-from trashcli.empty import main as empty
-
 
 @pytest.mark.slow
 class TestTrashEmptyCmd(unittest.TestCase):
     def setUp(self):
         self.tmp_dir = MyPath.make_temp_dir()
         self.unreadable_dir = self.tmp_dir / 'data/Trash/files/unreadable'
+        self.volumes_listing = Mock(spec=VolumesListing)
+        self.volumes_listing.list_volumes.return_value = [self.unreadable_dir]
+        self.err=StringIO()
+        self.empty = EmptyCmd(
+            out=StringIO(),
+            err=self.err,
+            environ={'XDG_DATA_HOME':self.tmp_dir / 'data'},
+            volumes_listing=self.volumes_listing,
+            now=None,
+            file_reader=FileSystemReader(),
+            getuid=lambda: 123,
+            file_remover=FileRemover(),
+            version=None,
+            volume_of=lambda x: "volume_of %s" % x
+        )
 
     def test_trash_empty_will_skip_unreadable_dir(self):
-        out = StringIO()
-        err = StringIO()
-
         make_unreadable_dir(self.unreadable_dir)
 
-        empty(['trash-empty'], stdout = out, stderr = err,
-                environ={'XDG_DATA_HOME':self.tmp_dir / 'data'})
+        self.empty.run('trash-empty')
 
         assert ("trash-empty: cannot remove %s\n"  % self.unreadable_dir ==
-                     err.getvalue())
+                     self.err.getvalue())
 
     def tearDown(self):
         make_readable(self.unreadable_dir)
-- 
2.33.1