mocks maybe working
This commit is contained in:
parent
893c6be9e9
commit
6ad0165368
4 changed files with 24 additions and 15 deletions
|
|
@ -15,7 +15,7 @@ from ytdl_sub.cli.output_transaction_log import (
|
||||||
)
|
)
|
||||||
from ytdl_sub.cli.parsers.cli_to_sub import print_cli_to_sub
|
from ytdl_sub.cli.parsers.cli_to_sub import print_cli_to_sub
|
||||||
from ytdl_sub.cli.parsers.dl import DownloadArgsParser
|
from ytdl_sub.cli.parsers.dl import DownloadArgsParser
|
||||||
from ytdl_sub.cli.parsers.main import DEFAULT_CONFIG_FILE_NAME, parser, InspectArguments
|
from ytdl_sub.cli.parsers.main import DEFAULT_CONFIG_FILE_NAME, InspectArguments, parser
|
||||||
from ytdl_sub.config.config_file import ConfigFile
|
from ytdl_sub.config.config_file import ConfigFile
|
||||||
from ytdl_sub.subscriptions.subscription import Subscription
|
from ytdl_sub.subscriptions.subscription import Subscription
|
||||||
from ytdl_sub.utils.exceptions import ExperimentalFeatureNotEnabled, ValidationException
|
from ytdl_sub.utils.exceptions import ExperimentalFeatureNotEnabled, ValidationException
|
||||||
|
|
@ -215,10 +215,10 @@ def _parse_inspect_mocks(mocks: Optional[List[str]]) -> Dict[str, str]:
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def _parse_inspect_level(inspect_level: str) -> str:
|
def _parse_inspect_level(inspect_level: str) -> int:
|
||||||
for val, name in InspectArguments.LevelChoices.items():
|
for val, name in InspectArguments.LevelChoices.items():
|
||||||
if inspect_level == val or inspect_level == name:
|
if inspect_level == val or inspect_level == name:
|
||||||
return name
|
return int(val)
|
||||||
|
|
||||||
raise ValueError("should not reach here")
|
raise ValueError("should not reach here")
|
||||||
|
|
||||||
|
|
@ -228,7 +228,7 @@ def _inspect(
|
||||||
subscription_paths: List[str],
|
subscription_paths: List[str],
|
||||||
subscription_matches: List[str],
|
subscription_matches: List[str],
|
||||||
subscription_override_dict: Dict,
|
subscription_override_dict: Dict,
|
||||||
inspection_level: str,
|
inspection_level: int,
|
||||||
mocks: Dict[str, str],
|
mocks: Dict[str, str],
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
|
|
@ -243,12 +243,11 @@ def _inspect(
|
||||||
|
|
||||||
if len(subscriptions) > 1:
|
if len(subscriptions) > 1:
|
||||||
print(
|
print(
|
||||||
"inspect can only inspect a single subscription. "
|
"inspect can only inspect a single subscription. Use --match to filter for a single one"
|
||||||
"Use --match to filter for a single one"
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
print(subscriptions[0].resolved_yaml())
|
print(subscriptions[0].resolved_yaml(resolution_level=inspection_level, mocks=mocks))
|
||||||
|
|
||||||
|
|
||||||
def main() -> List[Subscription]:
|
def main() -> List[Subscription]:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
import dataclasses
|
import dataclasses
|
||||||
from typing import Dict
|
from typing import Dict, List
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from ytdl_sub import __local_version__
|
from ytdl_sub import __local_version__
|
||||||
from ytdl_sub.utils.logger import LoggerLevels
|
from ytdl_sub.utils.logger import LoggerLevels
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Dict, List, Set
|
from typing import Dict, List, Optional, Set
|
||||||
|
|
||||||
from ytdl_sub.config.overrides import Overrides
|
from ytdl_sub.config.overrides import Overrides
|
||||||
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
|
from ytdl_sub.config.plugin.plugin_mapping import PluginMapping
|
||||||
|
|
@ -52,7 +52,7 @@ class VariableValidation:
|
||||||
if name not in self.unresolved_variables and not name.endswith("_sanitized")
|
if name not in self.unresolved_variables and not name.endswith("_sanitized")
|
||||||
}
|
}
|
||||||
|
|
||||||
def _apply_resolution_level(self) -> None:
|
def _apply_resolution_level(self, mocks: Optional[Dict[str, str]]) -> None:
|
||||||
if self._resolution_level == ResolutionLevel.FILL:
|
if self._resolution_level == ResolutionLevel.FILL:
|
||||||
self.unresolved_variables |= VARIABLES.variable_names(include_sanitized=True)
|
self.unresolved_variables |= VARIABLES.variable_names(include_sanitized=True)
|
||||||
# Only partial resolve definitions that are already resolved
|
# Only partial resolve definitions that are already resolved
|
||||||
|
|
@ -70,6 +70,12 @@ class VariableValidation:
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid resolution level for validation")
|
raise ValueError("Invalid resolution level for validation")
|
||||||
|
|
||||||
|
if mocks is not None:
|
||||||
|
self.script.add(
|
||||||
|
variables=mocks,
|
||||||
|
unresolvable=self.unresolved_variables,
|
||||||
|
)
|
||||||
|
|
||||||
self.script = self.script.resolve_partial(
|
self.script = self.script.resolve_partial(
|
||||||
unresolvable=self.unresolved_variables,
|
unresolvable=self.unresolved_variables,
|
||||||
output_filter=self._get_resolve_partial_filter(),
|
output_filter=self._get_resolve_partial_filter(),
|
||||||
|
|
@ -82,6 +88,7 @@ class VariableValidation:
|
||||||
output_options: OutputOptions,
|
output_options: OutputOptions,
|
||||||
plugins: PresetPlugins,
|
plugins: PresetPlugins,
|
||||||
resolution_level: int = ResolutionLevel.RESOLVE,
|
resolution_level: int = ResolutionLevel.RESOLVE,
|
||||||
|
mocks: Optional[Dict[str, str]] = None,
|
||||||
):
|
):
|
||||||
self.overrides = overrides
|
self.overrides = overrides
|
||||||
self.downloader_options = downloader_options
|
self.downloader_options = downloader_options
|
||||||
|
|
@ -99,8 +106,7 @@ class VariableValidation:
|
||||||
additional_options=[self.output_options, self.downloader_options]
|
additional_options=[self.output_options, self.downloader_options]
|
||||||
)
|
)
|
||||||
self._resolution_level = resolution_level
|
self._resolution_level = resolution_level
|
||||||
|
self._apply_resolution_level(mocks=mocks)
|
||||||
self._apply_resolution_level()
|
|
||||||
|
|
||||||
def _add_runtime_variables(self, plugin_op: PluginOperation, options: OptionsValidator) -> None:
|
def _add_runtime_variables(self, plugin_op: PluginOperation, options: OptionsValidator) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
from ytdl_sub.config.config_validator import ConfigOptions
|
from ytdl_sub.config.config_validator import ConfigOptions
|
||||||
from ytdl_sub.config.overrides import Overrides
|
from ytdl_sub.config.overrides import Overrides
|
||||||
|
|
@ -254,7 +254,11 @@ class BaseSubscription(ABC):
|
||||||
"""
|
"""
|
||||||
return self._preset_options.yaml(subscription_only=False)
|
return self._preset_options.yaml(subscription_only=False)
|
||||||
|
|
||||||
def resolved_yaml(self, resolution_level: int = ResolutionLevel.RESOLVE) -> str:
|
def resolved_yaml(
|
||||||
|
self,
|
||||||
|
resolution_level: int = ResolutionLevel.RESOLVE,
|
||||||
|
mocks: Optional[Dict[str, str]] = None,
|
||||||
|
) -> str:
|
||||||
"""
|
"""
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
|
|
@ -269,5 +273,6 @@ class BaseSubscription(ABC):
|
||||||
output_options=self.output_options,
|
output_options=self.output_options,
|
||||||
plugins=self.plugins,
|
plugins=self.plugins,
|
||||||
resolution_level=resolution_level,
|
resolution_level=resolution_level,
|
||||||
|
mocks=mocks,
|
||||||
).ensure_proper_usage(partial_resolve_formatters=True)
|
).ensure_proper_usage(partial_resolve_formatters=True)
|
||||||
return dump_yaml(out)
|
return dump_yaml(out)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue