Files
beets/test/plugins/test_scrub.py
T
shuwen.wu 15637ed148 fix(scrub): skip scrubbing when --nowrite is passed
When `beet import -W` (--nowrite) is run with the scrub plugin
enabled (auto=True), the plugin was scrubbing (removing) tags even
though --nowrite means "don't write to files". This caused tags
to be lost.

The fix adds a guard at the start of import_task_files to skip
the entire scrub operation when should_write() returns False,
making the scrub plugin respect the --nowrite flag like other
plugins do.

Fixes #6958
2026-09-03 02:46:03 +08:00

37 lines
1.3 KiB
Python

from mediafile import MediaFile
from beets.test.helper import AsIsImporterMixin, ImportHelper, PluginMixin
class TestScrubbedImport(AsIsImporterMixin, PluginMixin, ImportHelper):
db_on_disk = True
plugin = "scrub"
def test_tags_not_scrubbed(self):
with self.configure_plugin({"auto": False}):
self.run_asis_importer(write=True)
for item in self.lib.items():
imported_file = MediaFile(item.filepath)
assert imported_file.artist == "Tag Artist"
assert imported_file.album == "Tag Album"
def test_tags_restored(self):
with self.configure_plugin({"auto": True}):
self.run_asis_importer(write=True)
for item in self.lib.items():
imported_file = MediaFile(item.filepath)
assert imported_file.artist == "Tag Artist"
assert imported_file.album == "Tag Album"
def test_tags_not_scrubbed_when_nowrite(self):
"""When --nowrite is passed, scrubbing should be skipped entirely."""
with self.configure_plugin({"auto": True}):
self.run_asis_importer(write=False)
for item in self.lib.items():
imported_file = MediaFile(item.filepath)
assert imported_file.artist == "Tag Artist"
assert imported_file.album == "Tag Album"