mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
Update test
This commit is contained in:
parent
65f5dd579b
commit
c2d5c1f17c
3 changed files with 36 additions and 68 deletions
19
poetry.lock
generated
19
poetry.lock
generated
|
|
@ -2453,23 +2453,6 @@ Werkzeug = "*"
|
|||
[package.extras]
|
||||
docs = ["Sphinx", "sphinx-rtd-theme"]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-mock"
|
||||
version = "3.15.1"
|
||||
description = "Thin-wrapper around the mock package for easier use with pytest"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
files = [
|
||||
{file = "pytest_mock-3.15.1-py3-none-any.whl", hash = "sha256:0a25e2eb88fe5168d535041d09a4529a188176ae608a6d249ee65abc0949630d"},
|
||||
{file = "pytest_mock-3.15.1.tar.gz", hash = "sha256:1849a238f6f396da19762269de72cb1814ab44416fa73a8686deac10b0d87a0f"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pytest = ">=6.2.5"
|
||||
|
||||
[package.extras]
|
||||
dev = ["pre-commit", "pytest-asyncio", "tox"]
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.9.0.post0"
|
||||
|
|
@ -3689,4 +3672,4 @@ web = ["flask", "flask-cors"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = ">=3.9,<4"
|
||||
content-hash = "8ed50b90e399bace64062c38f784f9c7bcab2c2b7c0728cfe0a9ee78ea1fd902"
|
||||
content-hash = "1db39186aca430ef6f1fd9e51b9dcc3ed91880a458bc21b22d950ed8589fdf5a"
|
||||
|
|
|
|||
|
|
@ -100,7 +100,6 @@ rarfile = "*"
|
|||
requests-mock = ">=1.12.1"
|
||||
requests_oauthlib = "*"
|
||||
responses = ">=0.3.0"
|
||||
pytest-mock = "^3.15.1"
|
||||
|
||||
[tool.poetry.group.lint.dependencies]
|
||||
docstrfmt = ">=1.11.1"
|
||||
|
|
|
|||
|
|
@ -14,16 +14,18 @@
|
|||
|
||||
"""Tests for the 'lastgenre' plugin."""
|
||||
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from beets.test import _common
|
||||
from beets.test.helper import BeetsTestCase
|
||||
from beets.test.helper import PluginTestCase
|
||||
from beetsplug import lastgenre
|
||||
|
||||
|
||||
class LastGenrePluginTest(BeetsTestCase):
|
||||
class LastGenrePluginTest(PluginTestCase):
|
||||
plugin = "lastgenre"
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.plugin = lastgenre.LastGenrePlugin()
|
||||
|
|
@ -131,6 +133,36 @@ class LastGenrePluginTest(BeetsTestCase):
|
|||
"math rock",
|
||||
]
|
||||
|
||||
@patch("beets.ui.should_write", Mock(return_value=True))
|
||||
@patch(
|
||||
"beetsplug.lastgenre.LastGenrePlugin._get_genre",
|
||||
Mock(return_value=("Mock Genre", "mock stage")),
|
||||
)
|
||||
def test_pretend_option_skips_library_updates(self):
|
||||
item = self.create_item(
|
||||
album="Pretend Album",
|
||||
albumartist="Pretend Artist",
|
||||
artist="Pretend Artist",
|
||||
title="Pretend Track",
|
||||
genre="Original Genre",
|
||||
)
|
||||
album = self.lib.add_album([item])
|
||||
|
||||
def unexpected_store(*_, **__):
|
||||
raise AssertionError("Unexpected store call")
|
||||
|
||||
# Verify that try_write was never called (file operations skipped)
|
||||
with (
|
||||
patch("beetsplug.lastgenre.Item.store", unexpected_store),
|
||||
self.assertLogs() as logs,
|
||||
):
|
||||
self.run_command("lastgenre", "--pretend")
|
||||
|
||||
assert "Mock Genre" in str(logs.output)
|
||||
album.load()
|
||||
assert album.genre == "Original Genre"
|
||||
assert album.items()[0].genre == "Original Genre"
|
||||
|
||||
def test_no_duplicate(self):
|
||||
"""Remove duplicated genres."""
|
||||
self._setup_config(count=99)
|
||||
|
|
@ -172,52 +204,6 @@ class LastGenrePluginTest(BeetsTestCase):
|
|||
assert res == ["ambient", "electronic"]
|
||||
|
||||
|
||||
def test_pretend_option_skips_library_updates(mocker):
|
||||
"""Test that pretend mode logs actions but skips library updates."""
|
||||
|
||||
# Setup
|
||||
test_case = BeetsTestCase()
|
||||
test_case.setUp()
|
||||
plugin = lastgenre.LastGenrePlugin()
|
||||
item = test_case.create_item(
|
||||
album="Album",
|
||||
albumartist="Artist",
|
||||
artist="Artist",
|
||||
title="Track",
|
||||
genre="Original Genre",
|
||||
)
|
||||
album = test_case.lib.add_album([item])
|
||||
command = plugin.commands()[0]
|
||||
opts, args = command.parser.parse_args(["--pretend"])
|
||||
|
||||
# Mocks
|
||||
mocker.patch.object(lastgenre.ui, "should_write", return_value=True)
|
||||
mock_get_genre = mocker.patch.object(
|
||||
plugin, "_get_genre", return_value=("New Genre", "log label")
|
||||
)
|
||||
mock_log = mocker.patch.object(plugin._log, "info")
|
||||
mock_write = mocker.patch.object(item, "try_write")
|
||||
|
||||
# Run lastgenre
|
||||
command.func(test_case.lib, opts, args)
|
||||
mock_get_genre.assert_called_once()
|
||||
|
||||
# Test logging
|
||||
assert any(
|
||||
call.args[0].startswith("Pretend:") for call in mock_log.call_args_list
|
||||
)
|
||||
|
||||
# Test file operations should be skipped
|
||||
mock_write.assert_not_called()
|
||||
|
||||
# Test database should remain unchanged
|
||||
stored_album = test_case.lib.get_album(album.id)
|
||||
assert stored_album.genre == "Original Genre"
|
||||
assert stored_album.items()[0].genre == "Original Genre"
|
||||
|
||||
test_case.tearDown()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config_values, item_genre, mock_genres, expected_result",
|
||||
[
|
||||
|
|
|
|||
Loading…
Reference in a new issue