Skip to content

Commit ca3adfe

Browse files
committed
Replace assertPrem
1 parent 8dcc69e commit ca3adfe

File tree

1 file changed

+8
-41
lines changed

1 file changed

+8
-41
lines changed

test/plugins/test_permissions.py

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from beets.test._common import touch
88
from beets.test.helper import AsIsImporterMixin, ImportTestCase, PluginMixin
9-
from beets.util import displayable_path
109
from beetsplug.permissions import (
1110
check_permissions,
1211
convert_perm,
@@ -23,57 +22,25 @@ def setUp(self):
2322
self.config["permissions"] = {"file": "777", "dir": "777"}
2423

2524
def test_permissions_on_album_imported(self):
26-
self.do_thing(True)
25+
self.import_and_check_permissions()
2726

2827
def test_permissions_on_item_imported(self):
2928
self.config["import"]["singletons"] = True
30-
self.do_thing(True)
29+
self.import_and_check_permissions()
3130

32-
@patch("os.chmod", Mock())
33-
def test_failing_to_set_permissions(self):
34-
self.do_thing(False)
35-
36-
def do_thing(self, expect_success):
31+
def import_and_check_permissions(self):
3732
if platform.system() == "Windows":
3833
self.skipTest("permissions not available on Windows")
3934

40-
def get_stat(v):
41-
return (
42-
os.stat(os.path.join(self.temp_dir, b"import", *v)).st_mode
43-
& 0o777
44-
)
45-
46-
typs = ["file", "dir"]
47-
48-
track_file = (b"album", b"track_1.mp3")
49-
self.exp_perms = {
50-
True: {
51-
k: convert_perm(self.config["permissions"][k].get())
52-
for k in typs
53-
},
54-
False: {k: get_stat(v) for (k, v) in zip(typs, (track_file, ()))},
55-
}
35+
track_file = os.path.join(self.import_dir, b"album", b"track_1.mp3")
36+
assert os.stat(track_file).st_mode & 0o777 != 511
5637

5738
self.run_asis_importer()
5839
item = self.lib.items().get()
5940

60-
self.assertPerms(item.path, "file", expect_success)
61-
62-
for path in dirs_in_library(self.lib.directory, item.path):
63-
self.assertPerms(path, "dir", expect_success)
64-
65-
def assertPerms(self, path, typ, expect_success):
66-
for x in [
67-
(True, self.exp_perms[expect_success][typ], "!="),
68-
(False, self.exp_perms[not expect_success][typ], "=="),
69-
]:
70-
msg = "{} : {} {} {}".format(
71-
displayable_path(path),
72-
oct(os.stat(path).st_mode),
73-
x[2],
74-
oct(x[1]),
75-
)
76-
assert x[0] == check_permissions(path, x[1]), msg
41+
paths = (item.path, *dirs_in_library(self.lib.directory, item.path))
42+
for path in paths:
43+
assert os.stat(path).st_mode & 0o777 == 511
7744

7845
def test_convert_perm_from_string(self):
7946
assert convert_perm("10") == 8

0 commit comments

Comments
 (0)