summaryrefslogtreecommitdiff
path: root/app-misc/trash-cli/files/trash-cli-0.21.10.24-fix-unit-tests-not-deleting-temp-directories.patch
blob: 917f34d50e60e1db629147225e89b987e3b4fff5 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From 196144f90aaeb9d062019db4937dc4a1ec5991aa Mon Sep 17 00:00:00 2001
From: Zoltan Puskas <zoltan@sinustrom.info>
Date: Sat, 4 Dec 2021 11:12:16 -0800
Subject: [PATCH] Fix unit tests not deleting temp directories

Some tests were not deleting temporary directories polluting /tmp. This
patch fixes all locations in the code where this was forgotten.

Additionally we apply a suffix on top of the randomly generated name for
the temp directories (new name example: tmpwl2fvrn9_trash_cli_test)
becasue:
- it has no cost to us or the users
- helps identify temporary directories as belonging to trash-cli tests
- will make similar issues obvious in the future

Bug: GH-218
---
 tests/empty/test_empty_end_to_end_interactive.py   | 3 +++
 tests/empty/test_empty_end_to_end_with_argument.py | 3 +++
 tests/put/test_end_to_end_put.py                   | 3 +++
 tests/restore/test_trash_directory.py              | 3 ++-
 tests/support.py                                   | 2 +-
 tests/test_files.py                                | 1 +
 tests/test_filesystem.py                           | 2 ++
 tests/test_trash_put_slow.py                       | 3 +++
 8 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/tests/empty/test_empty_end_to_end_interactive.py b/tests/empty/test_empty_end_to_end_interactive.py
index 80b8f81..14b2867 100644
--- a/tests/empty/test_empty_end_to_end_interactive.py
+++ b/tests/empty/test_empty_end_to_end_interactive.py
@@ -40,3 +40,6 @@ class TestEmptyEndToEndInteractive(unittest.TestCase):
             'Would empty the following trash directories:\n'
             '    - %s\n'
             'Proceed? (y/n) ' % self.trash_dir, '', 0]
+
+    def tearDown(self):
+        self.tmp_dir.clean_up()
diff --git a/tests/empty/test_empty_end_to_end_with_argument.py b/tests/empty/test_empty_end_to_end_with_argument.py
index bfa660b..aad10de 100644
--- a/tests/empty/test_empty_end_to_end_with_argument.py
+++ b/tests/empty/test_empty_end_to_end_with_argument.py
@@ -54,3 +54,6 @@ class TestEmptyEndToEndWithArgument(unittest.TestCase):
         self.user_run_trash_empty(['2'])
 
         assert list_trash_dir(self.trash_dir) == ['info/foo.trashinfo']
+
+    def tearDown(self):
+        self.tmp_dir.clean_up()
diff --git a/tests/put/test_end_to_end_put.py b/tests/put/test_end_to_end_put.py
index 5b95b57..8af89b8 100644
--- a/tests/put/test_end_to_end_put.py
+++ b/tests/put/test_end_to_end_put.py
@@ -89,3 +89,6 @@ class TestEndToEndPut(unittest.TestCase):
                                          ['-f', 'this_file_does_not_exist', 'nor_does_this_file'])
 
         assert [result.stdout, result.stderr, result.exit_code] == ['', '', 0]
+
+    def tearDown(self):
+        self.tmp_dir.clean_up()
diff --git a/tests/restore/test_trash_directory.py b/tests/restore/test_trash_directory.py
index d961f45..5328f98 100644
--- a/tests/restore/test_trash_directory.py
+++ b/tests/restore/test_trash_directory.py
@@ -53,4 +53,5 @@ class TestTrashDirectory(unittest.TestCase):
     def list_trashinfos(self):
         return list(self.trash_dir.all_info_files(self.temp_dir / 'trash-dir'))
 
-
+    def tearDown(self):
+        self.temp_dir.clean_up()
diff --git a/tests/support.py b/tests/support.py
index afbb402..d5966d3 100644
--- a/tests/support.py
+++ b/tests/support.py
@@ -34,4 +34,4 @@ class MyPath(str):
 
     @classmethod
     def make_temp_dir(cls):
-        return cls(os.path.realpath(tempfile.mkdtemp()))
+        return cls(os.path.realpath(tempfile.mkdtemp(suffix="_trash_cli_test")))
diff --git a/tests/test_files.py b/tests/test_files.py
index abe4ae0..487ffd3 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -45,3 +45,4 @@ class Test_make_unreadable_dir(unittest.TestCase):
     def tearDown(self):
         make_readable(self.unreadable_dir)
         shutil.rmtree(self.unreadable_dir)
+        self.tmp_dir.clean_up()
diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py
index 2df08b1..b1e9aa6 100644
--- a/tests/test_filesystem.py
+++ b/tests/test_filesystem.py
@@ -64,3 +64,5 @@ class Test_is_sticky_dir(unittest.TestCase):
 
         assert not is_sticky_dir(self.temp_dir / 'dir')
 
+    def tearDown(self):
+        self.temp_dir.clean_up()
diff --git a/tests/test_trash_put_slow.py b/tests/test_trash_put_slow.py
index e85f699..078c371 100644
--- a/tests/test_trash_put_slow.py
+++ b/tests/test_trash_put_slow.py
@@ -29,6 +29,9 @@ class TrashPutFixture:
         self.stderr = result.stderr
         self.exit_code = result.exit_code
 
+    def __del__(self):
+        self.temp_dir.clean_up()
+
 
 @pytest.mark.slow
 class TestDeletingExistingFile(unittest.TestCase):
-- 
2.33.1