mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 19:05:13 +00:00
style: turn on ruff UP and B rules and fix every finding
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Callable, Optional
|
||||
|
||||
import pytest
|
||||
from langcodes import Language
|
||||
@@ -22,7 +22,7 @@ from unshackle.core.tracks import Audio, Subtitle, Tracks
|
||||
(["en-US"], None, None),
|
||||
],
|
||||
)
|
||||
def test_first_match_index(languages: list[str], preferred: Optional[str], expected: Optional[int]) -> None:
|
||||
def test_first_match_index(languages: list[str], preferred: str | None, expected: int | None) -> None:
|
||||
tracks = [
|
||||
Audio(id_=f"a{i}", url=f"https://x/{i}", language=lang, codec=Audio.Codec.AAC, bitrate=1)
|
||||
for i, lang in enumerate(languages)
|
||||
@@ -55,7 +55,7 @@ def subtitle(index: int, language: str, kind: str) -> Subtitle:
|
||||
(None, [], None),
|
||||
],
|
||||
)
|
||||
def test_default_subtitle_index(language: Optional[str], types: list[str], expected: Optional[int]) -> None:
|
||||
def test_default_subtitle_index(language: str | None, types: list[str], expected: int | None) -> None:
|
||||
kinds = [("pl", "forced"), ("pl", "normal"), ("en", "normal"), ("en", "sdh")]
|
||||
subtitles = [subtitle(i, lang, kind) for i, (lang, kind) in enumerate(kinds)]
|
||||
assert Tracks.default_subtitle_index(subtitles, language, types) == expected
|
||||
@@ -65,7 +65,7 @@ def test_default_subtitle_index(language: Optional[str], types: list[str], expec
|
||||
("audio", "expected"),
|
||||
[("en", 1), ("ar", 0), ("fr", 2), (None, 2)],
|
||||
)
|
||||
def test_a_forced_default_with_no_language_follows_the_audio(audio: Optional[str], expected: int) -> None:
|
||||
def test_a_forced_default_with_no_language_follows_the_audio(audio: str | None, expected: int) -> None:
|
||||
kinds = [("ar", "forced"), ("en", "forced"), ("en", "normal")]
|
||||
subtitles = [subtitle(i, lang, kind) for i, (lang, kind) in enumerate(kinds)]
|
||||
audio_language = Language.get(audio) if audio else None
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Callable, Optional
|
||||
|
||||
import pytest
|
||||
from langcodes import Language
|
||||
@@ -10,7 +10,7 @@ from unshackle.core.tracks import Audio, Subtitle, Tracks, Video
|
||||
from unshackle.core.utilities import language_name, multi_script_languages, with_script
|
||||
|
||||
|
||||
def sub(lang: str, name: Optional[str] = None, sdh: bool = False, original: bool = False) -> Subtitle:
|
||||
def sub(lang: str, name: str | None = None, sdh: bool = False, original: bool = False) -> Subtitle:
|
||||
return Subtitle(
|
||||
id_="s",
|
||||
url="https://x/s",
|
||||
@@ -77,7 +77,7 @@ def test_with_script(tag: str, expected: str) -> None:
|
||||
("x-foo", None),
|
||||
],
|
||||
)
|
||||
def test_language_name(tag: str, expected: Optional[str]) -> None:
|
||||
def test_language_name(tag: str, expected: str | None) -> None:
|
||||
assert language_name(Language.get(tag)) == expected
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ def test_language_name(tag: str, expected: Optional[str]) -> None:
|
||||
("qaa", None),
|
||||
],
|
||||
)
|
||||
def test_native_language_name(tag: str, expected: Optional[str], monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
def test_native_language_name(tag: str, expected: str | None, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(config, "muxing", {"track_names": "native"})
|
||||
assert language_name(Language.get(tag)) == expected
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import subprocess
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -39,7 +40,7 @@ def probe_returns(monkeypatch: pytest.MonkeyPatch, stream: dict[str, Any]) -> No
|
||||
|
||||
|
||||
def pairs(args: list[str]) -> dict[str, str]:
|
||||
return dict(zip(args[::2], args[1::2]))
|
||||
return dict(zip(args[::2], args[1::2], strict=False))
|
||||
|
||||
|
||||
def test_hdr10_vp9_gets_cicp_and_mastering_display(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
@@ -78,7 +79,7 @@ def test_partial_mastering_display_keeps_the_cicp_args(tmp_path: Path, monkeypat
|
||||
],
|
||||
)
|
||||
def test_the_file_transfer_wins_over_the_range(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, transfer: str, range_: Video.Range, expected: Optional[str]
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, transfer: str, range_: Video.Range, expected: str | None
|
||||
) -> None:
|
||||
probe_returns(monkeypatch, {"color_transfer": transfer})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user