Debian Codegraph @

tests/test_unicode_data.py

raw
1 from __future__ import annotations
2
3 import pytest
4
5 from rich._unicode_data import VERSIONS, _parse_version, load
6
7
8 def test_load():
9 """Test all versions may be loaded."""
10 for version in VERSIONS:
11 load(version)
12
13
14 @pytest.mark.parametrize(
15 "version_str,version_tuple",
16 [
17 ("1", (1, 0, 0)),
18 ("1.0", (1, 0, 0)),
19 ("1.2", (1, 2, 0)),
20 ("1.2.3", (1, 2, 3)),
21 ],
22 )
23 def test_parse_version(version_str: str, version_tuple: tuple[str, ...]) -> None:
24 assert _parse_version(version_str) == version_tuple
25
26
27 @pytest.mark.parametrize(
28 "version_in,version_selected",
29 [
30 # Lower versions will pick the first (4.1.0)
31 ("0", "4.1.0"),
32 ("1", "4.1.0"),
33 ("1.0", "4.1.0"),
34 ("1.0.0", "4.1.0"),
35 ("4.0.0", "4.1.0"),
36 ("4.0.2", "4.1.0"),
37 ("4.1.0", "4.1.0"),
38 ("4.1.1", "4.1.0"),
39 ("4.2.1", "4.1.0"),
40 # Nearest version lower
41 ("5", "5.0.0"),
42 ("5.0", "5.0.0"),
43 ("5.0.0", "5.0.0"),
44 ("5.0.1", "5.0.0"),
45 ("5.1.0", "5.1.0"),
46 ("5.1.1", "5.1.0"),
47 # Maximum version if greater than the maximum
48 ("17.0.0", "17.0.0"),
49 ("17.0.1", "17.0.0"),
50 ("17.1.0", "17.0.0"),
51 # Greater than the maximum
52 ("18.0.0", "17.0.0"),
53 ],
54 )
55 def test_load_version(version_in: str, version_selected: str) -> None:
56 """Test that load will pick the nearest lower version if it exists, or the lowest version if below the first available version."""
57 assert load(version_in).unicode_version == version_selected
58
59
60 def test_load_version_invalid() -> None:
61 """Check that invalid versions load the latest unicode data."""
62 assert load("foo").unicode_version == "17.0.0"
63 assert load("a.b.c").unicode_version == "17.0.0"
64 assert load("1.2.3a").unicode_version == "17.0.0"