Skip to content

Commit 72caf0d

Browse files
committed
Replace assertCount
1 parent 111cb56 commit 72caf0d

File tree

1 file changed

+10
-43
lines changed

1 file changed

+10
-43
lines changed

test/plugins/test_edit.py

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,6 @@ def setUp(self):
134134
{f: item[f] for f in item._fields} for item in self.album.items()
135135
]
136136

137-
def assertCounts(
138-
self,
139-
mock_write,
140-
album_count=ALBUM_COUNT,
141-
track_count=TRACK_COUNT,
142-
write_call_count=TRACK_COUNT,
143-
title_starts_with="",
144-
):
145-
"""Several common assertions on Album, Track and call counts."""
146-
assert len(self.lib.albums()) == album_count
147-
assert len(self.lib.items()) == track_count
148-
assert mock_write.call_count == write_call_count
149-
assert all(
150-
i.title.startswith(title_starts_with) for i in self.lib.items()
151-
)
152-
153137
def test_title_edit_discard(self, mock_write):
154138
"""Edit title for all items in the library, then discard changes."""
155139
# Edit track titles.
@@ -159,9 +143,7 @@ def test_title_edit_discard(self, mock_write):
159143
["c"],
160144
)
161145

162-
self.assertCounts(
163-
mock_write, write_call_count=0, title_starts_with="t\u00eftle"
164-
)
146+
assert mock_write.call_count == 0
165147
self.assertItemFieldsModified(self.album.items(), self.items_orig, [])
166148

167149
def test_title_edit_apply(self, mock_write):
@@ -173,11 +155,7 @@ def test_title_edit_apply(self, mock_write):
173155
["a"],
174156
)
175157

176-
self.assertCounts(
177-
mock_write,
178-
write_call_count=self.TRACK_COUNT,
179-
title_starts_with="modified t\u00eftle",
180-
)
158+
assert mock_write.call_count == self.TRACK_COUNT
181159
self.assertItemFieldsModified(
182160
self.album.items(), self.items_orig, ["title", "mtime"]
183161
)
@@ -191,10 +169,7 @@ def test_single_title_edit_apply(self, mock_write):
191169
["a"],
192170
)
193171

194-
self.assertCounts(
195-
mock_write,
196-
write_call_count=1,
197-
)
172+
assert mock_write.call_count == 1
198173
# No changes except on last item.
199174
self.assertItemFieldsModified(
200175
list(self.album.items())[:-1], self.items_orig[:-1], []
@@ -210,9 +185,7 @@ def test_noedit(self, mock_write):
210185
[],
211186
)
212187

213-
self.assertCounts(
214-
mock_write, write_call_count=0, title_starts_with="t\u00eftle"
215-
)
188+
assert mock_write.call_count == 0
216189
self.assertItemFieldsModified(self.album.items(), self.items_orig, [])
217190

218191
def test_album_edit_apply(self, mock_write):
@@ -226,7 +199,7 @@ def test_album_edit_apply(self, mock_write):
226199
["a"],
227200
)
228201

229-
self.assertCounts(mock_write, write_call_count=self.TRACK_COUNT)
202+
assert mock_write.call_count == self.TRACK_COUNT
230203
self.assertItemFieldsModified(
231204
self.album.items(), self.items_orig, ["album", "mtime"]
232205
)
@@ -249,9 +222,7 @@ def test_single_edit_add_field(self, mock_write):
249222
# Even though a flexible attribute was written (which is not directly
250223
# written to the tags), write should still be called since templates
251224
# might use it.
252-
self.assertCounts(
253-
mock_write, write_call_count=1, title_starts_with="t\u00eftle"
254-
)
225+
assert mock_write.call_count == 1
255226

256227
def test_a_album_edit_apply(self, mock_write):
257228
"""Album query (-a), edit album field, apply changes."""
@@ -263,7 +234,7 @@ def test_a_album_edit_apply(self, mock_write):
263234
)
264235

265236
self.album.load()
266-
self.assertCounts(mock_write, write_call_count=self.TRACK_COUNT)
237+
assert mock_write.call_count == self.TRACK_COUNT
267238
assert self.album.album == "modified \u00e4lbum"
268239
self.assertItemFieldsModified(
269240
self.album.items(), self.items_orig, ["album", "mtime"]
@@ -279,7 +250,7 @@ def test_a_albumartist_edit_apply(self, mock_write):
279250
)
280251

281252
self.album.load()
282-
self.assertCounts(mock_write, write_call_count=self.TRACK_COUNT)
253+
assert mock_write.call_count == self.TRACK_COUNT
283254
assert self.album.albumartist == "the modified album artist"
284255
self.assertItemFieldsModified(
285256
self.album.items(), self.items_orig, ["albumartist", "mtime"]
@@ -295,9 +266,7 @@ def test_malformed_yaml(self, mock_write):
295266
["n"],
296267
)
297268

298-
self.assertCounts(
299-
mock_write, write_call_count=0, title_starts_with="t\u00eftle"
300-
)
269+
assert mock_write.call_count == 0
301270

302271
def test_invalid_yaml(self, mock_write):
303272
"""Edit the yaml file incorrectly (resulting in a well-formed but
@@ -309,9 +278,7 @@ def test_invalid_yaml(self, mock_write):
309278
[],
310279
)
311280

312-
self.assertCounts(
313-
mock_write, write_call_count=0, title_starts_with="t\u00eftle"
314-
)
281+
assert mock_write.call_count == 0
315282

316283

317284
@_common.slow_test()

0 commit comments

Comments
 (0)