Spaces:
Sleeping
Sleeping
Download backend/tests/test_laugh_split.py from stylevoice/talk: direct link, hf CLI and curl.
- Browser
- Download file 3.93 kB
-
https://huggingface.co/spaces/stylevoice/talk/resolve/main/backend/tests/test_laugh_split.py
- Command line
-
hf download hf://spaces/stylevoice/talk/backend/tests/test_laugh_split.py
-
curl -L -o test_laugh_split.py https://huggingface.co/spaces/stylevoice/talk/resolve/main/backend/tests/test_laugh_split.py
3.93 kB
| """laugh_split unit tests β μμ ν ν° μ κ·μ + span κ°μ§ νκ· λ°©μ§.""" | |
| from __future__ import annotations | |
| import sys | |
| from pathlib import Path | |
| # allow `from services import laugh_split` from this test file | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| from services.laugh_split import ( # noqa: E402 | |
| classify_laugh_length, | |
| find_laugh_spans, | |
| is_pure_laughter, | |
| ) | |
| # ----- is_pure_laughter -------------------------------------------------- | |
| def test_pure_laughter_basic() -> None: | |
| assert is_pure_laughter("νΈνν") | |
| assert is_pure_laughter("νΈνννν!") | |
| assert is_pure_laughter("γ γ γ γ ") | |
| assert is_pure_laughter("νν ννν") | |
| assert is_pure_laughter("μΌννν") | |
| assert is_pure_laughter("ν¬ν¬ν¬") | |
| assert is_pure_laughter("ννν") | |
| assert is_pure_laughter("κΉκΉ") | |
| # μ λ 곡백/ꡬλμ νμ© | |
| assert is_pure_laughter(" νΈνν! ") | |
| assert is_pure_laughter("νΈνν.") | |
| def test_pure_laughter_negative() -> None: | |
| assert not is_pure_laughter("μ€λΉ μ§μ§ μκΈ΄λ€!") | |
| assert not is_pure_laughter("μ μ λ§?") | |
| assert not is_pure_laughter("μΌννν λ무 μ겨") # μμ λΆλΆ < 70% | |
| assert not is_pure_laughter("ν") # λ무 μ§§μ | |
| assert not is_pure_laughter("") | |
| assert not is_pure_laughter(" ") | |
| # ----- find_laugh_spans -------------------------------------------------- | |
| def test_spans_basic() -> None: | |
| spans = find_laugh_spans("νΈνν") | |
| assert len(spans) == 1 | |
| s, e = spans[0] | |
| assert (s, e) == (0, 3) | |
| def test_spans_in_sentence() -> None: | |
| text = "μ΄κ±° μ§μ§ λλ°μ΄μΌ. λ°λλκ° μμΌλ©΄ λ°λλν₯. νΈνν μ΄κ±° μμ μ΅κ³ μλμΌ?" | |
| spans = find_laugh_spans(text) | |
| assert len(spans) >= 1 | |
| # "νΈνν" μμΉλ₯Ό μ νν μ‘λκ°? | |
| found = any(text[s:e].strip() == "νΈνν" for s, e in spans) | |
| assert found, f"νΈνν span λ―Έκ°μ§: spans={spans!r}, text={text!r}" | |
| def test_spans_skip_single_char() -> None: | |
| # 1κΈμ (λ¨μ "ν") λ μ§μ§ μμμ΄ μλλ―λ‘ μ μΈ | |
| spans = find_laugh_spans("λλ μΌ κ·Έλ μ λ μμ§ ν κ·Έλλ") | |
| # "ν" λ¨λ κΈμλ λ§€μΉ μ λμ΄μΌ ν¨ | |
| one_char_spans = [(s, e) for s, e in spans if e - s == 1] | |
| assert not one_char_spans, f"1κΈμ λ§€μΉ λ°μ: {one_char_spans}" | |
| def test_spans_skip_single_char_with_trailing_space() -> None: | |
| # "ν " μ²λΌ λ¨μΌ κΈμ + 곡백 μ‘°ν©λ strip ν 1κΈμλΌ μ μΈλΌμΌ ν¨. | |
| # (regex group 3 μ \s κ° λ§€μΉλ₯Ό 2μλ‘ λ§λ€μ΄ νκ·νλ λ²κ·Έ.) | |
| for sample in ["ν ", " ν ", "λ§μ΄μΌ. ν κ·Έλ¬λκΉ", "μ. ν. μκ² μ΄"]: | |
| spans = find_laugh_spans(sample) | |
| single_core = [(s, e) for s, e in spans | |
| if sample[s:e].strip() == "ν"] | |
| assert not single_core, f"λ¨μΌ 'ν' span λ°μ: {sample!r} β {spans}" | |
| def test_spans_merge_adjacent() -> None: | |
| # μΈμ ν μ¬λ¬ λ§€μΉκ° νλμ span μΌλ‘ λ³ν©λλκ°? | |
| text = "νΈνν γ γ " | |
| spans = find_laugh_spans(text) | |
| # 곡백 1κ° κ°μ λ³ν© β λ¨μΌ span | |
| assert len(spans) <= 2 # λ³ν© λλ λΆλ¦¬ λ λ€ OK; 0κ°λ μ λ¨ | |
| assert spans, "μμ span 0κ°" | |
| # ----- classify_laugh_length --------------------------------------------- | |
| def test_classify_short() -> None: | |
| assert classify_laugh_length("νΈν") == "short" | |
| assert classify_laugh_length("νν") == "short" | |
| assert classify_laugh_length("γ γ γ ") == "short" | |
| def test_classify_medium() -> None: | |
| assert classify_laugh_length("νΈννν") == "medium" | |
| assert classify_laugh_length("μΌννν!") == "medium" | |
| def test_classify_long() -> None: | |
| assert classify_laugh_length("νΈνννν λ무 μ겨") == "long" | |
| assert classify_laugh_length("μΌννννννν") == "long" # 8 chars | |