File size: 3,139 Bytes
253292a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46bb905
253292a
 
 
 
 
 
 
 
 
 
 
 
 
 
46bb905
253292a
 
 
 
 
 
 
 
 
 
 
 
 
 
46bb905
253292a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Sprint A14-S9 — migration de ``normalization`` vers ``formats/text/``.

Vérifie que :

1. Le nouveau module ``picarones.formats.text.normalization`` expose
   les 11 profils canoniques.
2. L'ancien re-export ``picarones.measurements.normalization`` continue
   à fonctionner sans erreur (compat ascendante stricte).
3. Les symboles privés utilisés downstream (``_parse_exclude_chars``,
   ``_apply_diplomatic_table``) sont ré-exposés via le re-export.
4. Les deux chemins d'import retournent **le même objet** (pas une
   copie) — preuve que c'est un vrai re-export, pas une duplication.
"""

from __future__ import annotations


def test_new_path_exposes_all_eleven_profiles() -> None:
    from picarones.formats.text.normalization import NORMALIZATION_PROFILES
    expected = {
        "nfc", "caseless", "minimal",
        "medieval_french", "early_modern_french",
        "medieval_latin", "early_modern_english", "medieval_english",
        "secretary_hand", "sans_ponctuation", "sans_apostrophes",
    }
    assert set(NORMALIZATION_PROFILES.keys()) == expected


def test_old_reexport_works() -> None:
    """Compat ascendante : ~50 consommateurs importent depuis l'ancien
    chemin."""
    from picarones.evaluation.metrics.normalization import (
        DEFAULT_DIPLOMATIC_PROFILE,
        NORMALIZATION_PROFILES,
        NormalizationProfile,
        get_builtin_profile,
    )
    assert NormalizationProfile is not None
    assert "medieval_french" in NORMALIZATION_PROFILES
    assert get_builtin_profile("nfc") is not None
    assert DEFAULT_DIPLOMATIC_PROFILE.name == "medieval_french"


def test_private_symbols_reexported() -> None:
    """Les symboles préfixés ``_`` utilisés en aval doivent rester
    importables depuis l'ancien chemin."""
    from picarones.evaluation.metrics.normalization import (
        _apply_diplomatic_table,
        _parse_exclude_chars,
    )
    assert callable(_parse_exclude_chars)
    assert callable(_apply_diplomatic_table)


def test_old_and_new_paths_share_same_objects() -> None:
    """Preuve que c'est un vrai re-export, pas une duplication."""
    from picarones.formats.text.normalization import (
        NORMALIZATION_PROFILES as new_profiles,
        NormalizationProfile as NewProfile,
        get_builtin_profile as new_get,
    )
    from picarones.evaluation.metrics.normalization import (
        NORMALIZATION_PROFILES as old_profiles,
        NormalizationProfile as OldProfile,
        get_builtin_profile as old_get,
    )
    assert new_profiles is old_profiles  # même dict
    assert NewProfile is OldProfile      # même classe
    assert new_get is old_get            # même fonction


def test_apply_profile_works_via_new_path() -> None:
    """Test fonctionnel : un profil chargé depuis le nouveau chemin
    applique bien la normalisation."""
    from picarones.formats.text.normalization import get_builtin_profile
    profile = get_builtin_profile("medieval_french")
    # ſ → s, u → v dans le profil médiéval français.
    normalized = profile.normalize("aſpre")
    assert "ſ" not in normalized
    assert "s" in normalized