|
9 | 9 | import freezegun
|
10 | 10 |
|
11 | 11 | import streamlink_cli.main
|
| 12 | +import tests.resources |
12 | 13 | from streamlink.plugin.plugin import Plugin
|
13 | 14 | from streamlink.session import Streamlink
|
14 |
| -from streamlink_cli.compat import is_win32 |
| 15 | +from streamlink_cli.compat import DeprecatedPath, is_win32 |
15 | 16 | from streamlink_cli.main import (
|
| 17 | + NoPluginError, |
16 | 18 | check_file_output,
|
17 | 19 | create_output,
|
18 | 20 | format_valid_streams,
|
19 | 21 | handle_stream,
|
20 | 22 | handle_url,
|
21 | 23 | log_current_arguments,
|
22 |
| - resolve_stream_name |
| 24 | + resolve_stream_name, |
| 25 | + setup_config_args |
23 | 26 | )
|
24 | 27 | from streamlink_cli.output import FileOutput, PlayerOutput
|
25 | 28 |
|
@@ -269,6 +272,90 @@ def test_create_output_record_and_other_file_output(self):
|
269 | 272 | console.exit.assert_called_with("Cannot use record options with other file output options.")
|
270 | 273 |
|
271 | 274 |
|
| 275 | +@patch("streamlink_cli.main.log") |
| 276 | +class TestCLIMainSetupConfigArgs(unittest.TestCase): |
| 277 | + configdir = Path(tests.resources.__path__[0], "cli", "config") |
| 278 | + parser = Mock() |
| 279 | + |
| 280 | + @classmethod |
| 281 | + def subject(cls, config_files, **args): |
| 282 | + def resolve_url(name): |
| 283 | + if name == "noplugin": |
| 284 | + raise NoPluginError() |
| 285 | + return Mock(module="testplugin") |
| 286 | + |
| 287 | + session = Mock() |
| 288 | + session.resolve_url.side_effect = resolve_url |
| 289 | + args.setdefault("url", "testplugin") |
| 290 | + |
| 291 | + with patch("streamlink_cli.main.setup_args") as mock_setup_args, \ |
| 292 | + patch("streamlink_cli.main.args", **args), \ |
| 293 | + patch("streamlink_cli.main.streamlink", session), \ |
| 294 | + patch("streamlink_cli.main.CONFIG_FILES", config_files): |
| 295 | + setup_config_args(cls.parser) |
| 296 | + return mock_setup_args |
| 297 | + |
| 298 | + def test_no_plugin(self, mock_log): |
| 299 | + mock_setup_args = self.subject( |
| 300 | + [self.configdir / "primary", DeprecatedPath(self.configdir / "secondary")], |
| 301 | + config=None, |
| 302 | + url="noplugin" |
| 303 | + ) |
| 304 | + expected = [self.configdir / "primary"] |
| 305 | + mock_setup_args.assert_called_once_with(self.parser, expected, ignore_unknown=False) |
| 306 | + self.assertEqual(mock_log.info.mock_calls, []) |
| 307 | + |
| 308 | + def test_default_primary(self, mock_log): |
| 309 | + mock_setup_args = self.subject( |
| 310 | + [self.configdir / "primary", DeprecatedPath(self.configdir / "secondary")], |
| 311 | + config=None |
| 312 | + ) |
| 313 | + expected = [self.configdir / "primary", self.configdir / "primary.testplugin"] |
| 314 | + mock_setup_args.assert_called_once_with(self.parser, expected, ignore_unknown=False) |
| 315 | + self.assertEqual(mock_log.info.mock_calls, []) |
| 316 | + |
| 317 | + def test_default_secondary_deprecated(self, mock_log): |
| 318 | + mock_setup_args = self.subject( |
| 319 | + [self.configdir / "non-existent", DeprecatedPath(self.configdir / "secondary")], |
| 320 | + config=None |
| 321 | + ) |
| 322 | + expected = [self.configdir / "secondary", self.configdir / "secondary.testplugin"] |
| 323 | + mock_setup_args.assert_called_once_with(self.parser, expected, ignore_unknown=False) |
| 324 | + self.assertEqual(mock_log.info.mock_calls, [ |
| 325 | + call(f"Loaded config from deprecated path, see CLI docs for how to migrate: {expected[0]}"), |
| 326 | + call(f"Loaded plugin config from deprecated path, see CLI docs for how to migrate: {expected[1]}") |
| 327 | + ]) |
| 328 | + |
| 329 | + def test_custom_with_primary_plugin(self, mock_log): |
| 330 | + mock_setup_args = self.subject( |
| 331 | + [self.configdir / "primary", DeprecatedPath(self.configdir / "secondary")], |
| 332 | + config=[str(self.configdir / "custom")] |
| 333 | + ) |
| 334 | + expected = [self.configdir / "custom", self.configdir / "primary.testplugin"] |
| 335 | + mock_setup_args.assert_called_once_with(self.parser, expected, ignore_unknown=False) |
| 336 | + self.assertEqual(mock_log.info.mock_calls, []) |
| 337 | + |
| 338 | + def test_custom_with_deprecated_plugin(self, mock_log): |
| 339 | + mock_setup_args = self.subject( |
| 340 | + [self.configdir / "non-existent", DeprecatedPath(self.configdir / "secondary")], |
| 341 | + config=[str(self.configdir / "custom")] |
| 342 | + ) |
| 343 | + expected = [self.configdir / "custom", DeprecatedPath(self.configdir / "secondary.testplugin")] |
| 344 | + mock_setup_args.assert_called_once_with(self.parser, expected, ignore_unknown=False) |
| 345 | + self.assertEqual(mock_log.info.mock_calls, [ |
| 346 | + call(f"Loaded plugin config from deprecated path, see CLI docs for how to migrate: {expected[1]}") |
| 347 | + ]) |
| 348 | + |
| 349 | + def test_custom_multiple(self, mock_log): |
| 350 | + mock_setup_args = self.subject( |
| 351 | + [self.configdir / "primary", DeprecatedPath(self.configdir / "secondary")], |
| 352 | + config=[str(self.configdir / "non-existent"), str(self.configdir / "primary"), str(self.configdir / "secondary")] |
| 353 | + ) |
| 354 | + expected = [self.configdir / "secondary", self.configdir / "primary", self.configdir / "primary.testplugin"] |
| 355 | + mock_setup_args.assert_called_once_with(self.parser, expected, ignore_unknown=False) |
| 356 | + self.assertEqual(mock_log.info.mock_calls, []) |
| 357 | + |
| 358 | + |
272 | 359 | class _TestCLIMainLogging(unittest.TestCase):
|
273 | 360 | @classmethod
|
274 | 361 | def subject(cls, argv):
|
|
0 commit comments