mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -79,23 +79,12 @@ def cue_count(path) -> int:
|
||||
return len(re.findall(r"-->", path.read_text("utf8")))
|
||||
|
||||
|
||||
def test_resolve_webvtt_to_srt_order():
|
||||
chain = [b.name for b in sc.resolve_backends(Codec.WebVTT, Codec.SubRip)]
|
||||
assert chain == ["subby", "pysubs2", "pycaption"]
|
||||
|
||||
|
||||
def test_resolve_ass_to_srt_only_pysubs2_without_subtitleedit():
|
||||
# subby and pycaption cannot read ASS, so only pysubs2 remains.
|
||||
chain = [b.name for b in sc.resolve_backends(Codec.SubStationAlphav4, Codec.SubRip)]
|
||||
assert chain == ["pysubs2"]
|
||||
|
||||
|
||||
def test_subtitleedit_ranks_first_when_available(monkeypatch):
|
||||
monkeypatch.setattr(binaries, "SubtitleEdit", "/usr/bin/seconv")
|
||||
chain = [b.name for b in sc.resolve_backends(Codec.WebVTT, Codec.SubRip)]
|
||||
assert chain[0] == "subtitleedit"
|
||||
|
||||
|
||||
def test_styled_ass_to_ttml_vtt_prefers_pysubs2_over_subtitleedit(monkeypatch):
|
||||
# Measured: SE flattens ASS inline styling to TTML/VTT; pysubs2 keeps i/b/u.
|
||||
monkeypatch.setattr(binaries, "SubtitleEdit", "/usr/bin/seconv")
|
||||
@@ -183,14 +172,6 @@ def test_ass_to_ssa_keeps_file_order(tmp_path, monkeypatch):
|
||||
assert text.index("Sign") < text.index("Hello")
|
||||
|
||||
|
||||
def test_webvtt_to_srt_conversion(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False)
|
||||
sub = make_sub(tmp_path, "x.vtt", VTT_SAMPLE, Codec.WebVTT)
|
||||
out = sub.convert(Codec.SubRip, forced=True)
|
||||
assert sub.codec == Codec.SubRip
|
||||
assert cue_count(out) == 2
|
||||
|
||||
|
||||
SCC_SAMPLE = """Scenarist_SCC V1.0
|
||||
|
||||
00:00:00;00 9420 9152 9723 5bc2 4f43 49ce c120 c445 20c2 c152 434f 5d80 9420 942c 942f
|
||||
@@ -205,11 +186,6 @@ SCC_SAMPLE = """Scenarist_SCC V1.0
|
||||
"""
|
||||
|
||||
|
||||
def test_scc_mime_maps_to_the_scc_codec():
|
||||
assert Codec.from_mime("x-scc") is Codec.SCC
|
||||
assert Codec.from_mime("scc") is Codec.SCC
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"sub_format, expected",
|
||||
[
|
||||
@@ -231,44 +207,11 @@ def test_scc_converts_to_the_requested_format_or_srt(tmp_path, monkeypatch, sub_
|
||||
assert "¿Te gusta, Blanca Flor?" in sub.path.read_text("utf8")
|
||||
|
||||
|
||||
def test_scc_to_webvtt_keeps_the_caption_row(tmp_path, monkeypatch):
|
||||
from unshackle.commands.dl import convert_scc
|
||||
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False)
|
||||
sub = make_sub(tmp_path, "x.scc", SCC_SAMPLE, Codec.SCC)
|
||||
convert_scc(sub, Codec.WebVTT)
|
||||
assert "line:" in sub.path.read_text("utf8")
|
||||
|
||||
|
||||
def test_scc_as_srt_converts_on_to_ass(tmp_path, monkeypatch):
|
||||
from unshackle.commands.dl import convert_scc
|
||||
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False)
|
||||
sub = make_sub(tmp_path, "x.scc", SCC_SAMPLE, Codec.SCC)
|
||||
convert_scc(sub, Codec.SubStationAlphav4)
|
||||
assert sub.convert(Codec.SubStationAlphav4, forced=True).read_text("utf8").count("Dialogue:") == 2
|
||||
|
||||
|
||||
def test_scc_without_cc1_captions_warns(tmp_path, monkeypatch, caplog):
|
||||
from unshackle.commands.dl import convert_scc
|
||||
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False)
|
||||
cc3 = "Scenarist_SCC V1.0\n\n00:00:01:00\t1520 1520 1552 1552 c8e5 ecec ef80 152f 152f\n\n00:00:03:00\t152c 152c\n"
|
||||
convert_scc(make_sub(tmp_path, "x.scc", cc3, Codec.SCC), None)
|
||||
assert "has no CC1 captions" in caplog.text
|
||||
|
||||
|
||||
def test_scc_with_a_bad_timecode_is_a_syntax_error():
|
||||
with pytest.raises(SyntaxError):
|
||||
Subtitle.parse(b"Scenarist_SCC V1.0\n\n00:00:xx;00\t9420 942f\n", Codec.SCC)
|
||||
|
||||
|
||||
def test_same_codec_is_noop(tmp_path):
|
||||
sub = make_sub(tmp_path, "x.srt", "1\n00:00:01,000 --> 00:00:02,000\nHi\n", Codec.SubRip)
|
||||
assert sub.convert(Codec.SubRip) == sub.path
|
||||
assert sub.codec == Codec.SubRip
|
||||
|
||||
|
||||
FONT_ASS = """[Script Info]
|
||||
ScriptType: v4.00+
|
||||
|
||||
@@ -345,16 +288,6 @@ Hello there.
|
||||
"""
|
||||
|
||||
|
||||
def test_sdh_stripping_removes_effects_keeps_dialogue(tmp_path, monkeypatch):
|
||||
# subby's SDHStripper runs on SRT without SubtitleEdit installed.
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {"sdh_method": "subby"}, raising=False)
|
||||
sub = make_sub(tmp_path, "x.srt", SDH_SRT, Codec.SubRip)
|
||||
sub.strip_hearing_impaired()
|
||||
out = sub.path.read_text("utf8")
|
||||
assert "Hello there." in out # real dialogue kept
|
||||
assert "door creaks" not in out # bracketed effect removed (subby SDHStripper)
|
||||
|
||||
|
||||
SDH_ASS = """[Script Info]
|
||||
ScriptType: v4.00+
|
||||
|
||||
@@ -457,30 +390,6 @@ def test_segmented_fttml_joins_a_cue_split_at_a_segment_boundary():
|
||||
]
|
||||
|
||||
|
||||
def test_segmented_fttml_parses_and_converts(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False)
|
||||
frag = (
|
||||
'<?xml version="1.0" encoding="utf-8"?>'
|
||||
'<tt xmlns="http://www.w3.org/ns/ttml" xml:lang="en"><body><div>'
|
||||
'<p begin="00:00:0{a}.000" end="00:00:0{b}.000">Line {a}</p>'
|
||||
"</div></body></tt>"
|
||||
)
|
||||
data = build_stpp_mp4(frag.format(a=1, b=2), frag.format(a=3, b=4))
|
||||
|
||||
caption_set = Subtitle.parse(data, Codec.fTTML)
|
||||
assert caption_total(caption_set) == 2
|
||||
|
||||
seg = tmp_path / "seg.stpp"
|
||||
seg.write_bytes(data)
|
||||
sub = Subtitle(url="https://example.test/x", language="en", codec=Codec.fTTML)
|
||||
sub.path = seg
|
||||
# download() converts fTTML -> TTML (only pycaption can read fTTML); then -> SRT.
|
||||
sub.convert(Codec.TimedTextMarkupLang)
|
||||
assert sub.codec == Codec.TimedTextMarkupLang
|
||||
out = sub.convert(Codec.SubRip, forced=True)
|
||||
assert cue_count(out) == 2
|
||||
|
||||
|
||||
def downloaded_subtitle(tmp_path, monkeypatch, codec, data: bytes, descriptor: Track.Descriptor, track_data: dict):
|
||||
"""A Subtitle whose base download is a no-op, so download() runs only the post-processing on data."""
|
||||
monkeypatch.setattr("unshackle.core.config.config.subtitle", {}, raising=False)
|
||||
@@ -688,12 +597,3 @@ def test_ttml_parse_raises_no_bs4_warning(data, codec, cues):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error", XMLParsedAsHTMLWarning)
|
||||
assert caption_total(Subtitle.parse(data, codec)) == cues
|
||||
|
||||
|
||||
def test_ttml_parse_keeps_a_declaration_inside_the_cue_text():
|
||||
cue = ttml_fragment(("00:00:01.000", "00:00:02.000", "<![CDATA[Hi <?xml a?> there]]>"))
|
||||
expected = pycaption.DFXPReader().read(cue)
|
||||
|
||||
caption_set = Subtitle.parse((TTML_DECLARATION + cue).encode(), Codec.TimedTextMarkupLang)
|
||||
|
||||
assert pycaption.DFXPWriter().write(caption_set) == pycaption.DFXPWriter().write(expected)
|
||||
|
||||
Reference in New Issue
Block a user