ytdl-sub/tests/unit/script/functions/test_print_functions.py
Jesse Bannon 6c180c9478
[BACKEND] Enable throttle protection by default (#1257)
To protect new users, all prebuilt preset (excluding Soundcloud and Bandcamp) will include throttle protection by default.


> How do I disable?

Set the override variable `enable_throttle_protection: False`.
This can be done on a per-subscription basis and/or in the top __preset__ section to apply to all presets:

```
__preset__:
  overrides:
    enable_throttle_protection: False
```

> What if I already use throttle protection?

Your settings will override whatever values are set in the defaults.

Closes:
- https://github.com/jmbannon/ytdl-sub/issues/1121
- https://github.com/jmbannon/ytdl-sub/issues/1186
2025-07-03 00:34:37 -07:00

61 lines
2.4 KiB
Python

import logging
from typing import Any
from typing import Optional
from unittest.mock import patch
import pytest
from unit.script.conftest import single_variable_output
class TestPrintFunctions:
@pytest.mark.parametrize(
"function_str, expected_print, expected_output",
[
# print
("{%print('hi mom', True)}", "hi mom", True),
("{%print('this is great', [1, 2, 3])}", "this is great", [1, 2, 3]),
("{%print([1, 2], [3, 4])}", "[1, 2]", [3, 4]),
("{%print('', True)}", None, True),
# print_if_true
("{%print_if_true('hi mom', True)}", "hi mom", True),
("{%print_if_true('hi mom', False)}", None, False),
("{%print_if_true('', True)}", None, True),
# print_if_false
("{%print_if_false('hi mom', True)}", None, True),
("{%print_if_false('hi mom', False)}", "hi mom", False),
("{%print_if_false('', True)}", None, True),
],
)
def test_print_functions(
self, function_str: str, expected_print: Optional[str], expected_output: Any
):
with patch.object(logging.Logger, "info") as mock_logger:
output = single_variable_output(function_str)
assert output == expected_output
if expected_print is not None:
assert mock_logger.call_count == 1
assert mock_logger.call_args.args[0] == expected_print
else:
assert mock_logger.call_count == 0
@pytest.mark.parametrize(
"function_str, expected_print, expected_output",
[
# print
("{%print('hi mom', True, LEVEL)}", "hi mom", True),
# print_if_true
("{%print_if_true('hi mom', True, LEVEL)}", "hi mom", True),
# print_if_false
("{%print_if_false('hi mom', False, LEVEL)}", "hi mom", False),
],
)
@pytest.mark.parametrize("level", [-1, 0, 1, 2])
def test_levels(self, function_str: str, expected_print: str, expected_output: str, level: int):
level_mapping = {-1: "debug", 0: "info", 1: "warning", 2: "error"}
with patch.object(logging.Logger, level_mapping[level]) as mock_logger:
output = single_variable_output(function_str.replace("LEVEL", str(level)))
assert output == expected_output
assert mock_logger.call_count == 1
assert mock_logger.call_args.args[0] == expected_print