ytdl-sub/tests/integration/cli/test_inspect.py
Jesse Bannon 970c74ba45
[FEATURE] inspect subcommand (#1407)
Subscription file syntax is designed to minimize boiler-plate when authoring new subscriptions.
You can now unpack any subscription using the ``inspect`` sub-command to see its boiler-plate *preset format*.

```
ytdl-sub inspect --config /path/to/config.yaml --match "BBC News" /path/to/subscriptions.yaml
```

This can be utilized for numerous purposes including:

* Ensuring your custom preset is getting applied correctly.
* Figuring out which variables set things like file names, metadata, etc.
* Understanding how subscription syntax translates to preset representation.

The default ``--level`` of inspect will fill in defined variables. Using ``--level original`` will present the subscription's raw layout with no fill.
2026-04-13 10:10:58 -07:00

45 lines
1.5 KiB
Python

from pathlib import Path
import pytest
import yaml
from conftest import mock_run_from_cli
from unit.config.test_subscription_resolution import compare_resolved_yaml
from ytdl_sub.config.validators.variable_validation import ResolutionLevel
from ytdl_sub.utils.system import IS_WINDOWS
class TestInspect:
@pytest.mark.parametrize("config_provided", [True, False])
@pytest.mark.parametrize(
"inspect_level", ["0", "original", "1", "fill", "2", "resolve", "3", "internal"]
)
def test_inspect_command(
self,
capsys,
default_config_path: str,
tv_show_subscriptions_path: Path,
output_directory: str,
config_provided: bool,
inspect_level: str,
):
# TODO: fix mock_run_from_cli in windows to handle file paths correctly
if IS_WINDOWS:
return
# Shares same test fixture as `test_subscription_resolution.py`
args = f"--config {default_config_path} " if config_provided else ""
args += f"inspect {tv_show_subscriptions_path} --match 'NOVA PBS' "
args += f"--level {inspect_level} "
subscriptions = mock_run_from_cli(args=args)
assert len(subscriptions) == 0
out = yaml.safe_load(capsys.readouterr().out)
compare_resolved_yaml(
out=out,
output_directory=output_directory,
subscription_name="NOVA PBS",
preset_type="tv_show",
resolution_level=ResolutionLevel.level_number(resolution_arg=inspect_level),
)