Test that plugin callbacks are being called upon user choice.
(self)
| 388 | ) |
| 389 | |
| 390 | def test_plugin_callback(self): |
| 391 | """Test that plugin callbacks are being called upon user choice.""" |
| 392 | |
| 393 | class DummyPlugin(plugins.BeetsPlugin): |
| 394 | def __init__(self): |
| 395 | super().__init__() |
| 396 | self.register_listener( |
| 397 | "before_choose_candidate", self.return_choices |
| 398 | ) |
| 399 | |
| 400 | def return_choices(self, session, task): |
| 401 | return [PromptChoice("f", "Foo", self.foo)] |
| 402 | |
| 403 | def foo(self, session, task): |
| 404 | pass |
| 405 | |
| 406 | self.register_plugin(DummyPlugin) |
| 407 | # Default options + extra choices by the plugin ('Foo', 'Bar') |
| 408 | opts = ( |
| 409 | "Apply", |
| 410 | "More candidates", |
| 411 | "Skip", |
| 412 | "Use as-is", |
| 413 | "as Tracks", |
| 414 | "Group albums", |
| 415 | "Enter search", |
| 416 | "enter Id", |
| 417 | "aBort", |
| 418 | "Foo", |
| 419 | ) |
| 420 | |
| 421 | # DummyPlugin.foo() should be called once |
| 422 | with patch.object(DummyPlugin, "foo", autospec=True) as mock_foo: |
| 423 | self.io.addinput("f") |
| 424 | self.io.addinput("n") |
| 425 | self.importer.run() |
| 426 | assert mock_foo.call_count == 1 |
| 427 | |
| 428 | # input_options should be called twice, as foo() returns None |
| 429 | assert self.mock_input_options.call_count == 2 |
| 430 | self.mock_input_options.assert_called_with( |
| 431 | opts, default="a", require=ANY |
| 432 | ) |
| 433 | |
| 434 | def test_plugin_callback_return(self): |
| 435 | """Test that plugin callbacks that return a value exit the loop.""" |
nothing calls this directly
no test coverage detected