File: test_compounds.py

package info (click to toggle)
python-inflect 7.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 496 kB
  • sloc: python: 4,807; makefile: 3
file content (90 lines) | stat: -rw-r--r-- 2,979 bytes parent folder | download | duplicates (2)
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
82
83
84
85
86
87
88
89
90
import inflect

p = inflect.engine()


def test_compound_1():
    assert p.singular_noun("hello-out-there") == "hello-out-there"


def test_compound_2():
    assert p.singular_noun("hello out there") == "hello out there"


def test_compound_3():
    assert p.singular_noun("continue-to-operate") == "continue-to-operate"


def test_compound_4():
    assert p.singular_noun("case of diapers") == "case of diapers"


def test_unit_handling_degree():
    test_cases = {
        "degree celsius": "degrees celsius",
        # 'degree Celsius': 'degrees Celsius',
        "degree fahrenheit": "degrees fahrenheit",
        "degree rankine": "degrees rankine",
        "degree fahrenheit second": "degree fahrenheit seconds",
    }
    for singular, plural in test_cases.items():
        assert p.plural(singular) == plural


def test_unit_handling_fractional():
    test_cases = {
        "pound per square inch": "pounds per square inch",
        "metre per second": "metres per second",
        "kilometre per hour": "kilometres per hour",
        "cubic metre per second": "cubic metres per second",
        "dollar a year": "dollars a year",
        # Correct pluralization of denominator
        "foot per square second": "feet per square second",
        "mother-in-law per lifetime": "mothers-in-law per lifetime",
        "pound-force per square inch": "pounds-force per square inch",
    }
    for singular, plural in test_cases.items():
        assert p.plural(singular) == plural


def test_unit_handling_combined():
    test_cases = {
        # Heat transfer coefficient unit
        "watt per square meter degree celsius": "watts per square meter degree celsius",
        "degree celsius per hour": "degrees celsius per hour",
        "degree fahrenheit hour square foot per btuit inch": (
            "degree fahrenheit hour square feet per btuit inch"
        ),
        # 'degree Celsius per hour': 'degrees Celsius per hour',
        # 'degree Fahrenheit hour square foot per BtuIT inch':
        #   'degree Fahrenheit hour square feet per BtuIT inch'
    }
    for singular, plural in test_cases.items():
        assert p.plural(singular) == plural


def test_unit_open_compound_nouns():
    test_cases = {
        "high school": "high schools",
        "master genie": "master genies",
        "MASTER genie": "MASTER genies",
        "Blood brother": "Blood brothers",
        "prima donna": "prima donnas",
        "prima DONNA": "prima DONNAS",
    }
    for singular, plural in test_cases.items():
        assert p.plural(singular) == plural


def test_unit_open_compound_nouns_classical():
    p.classical(all=True)
    test_cases = {
        "master genie": "master genii",
        "MASTER genie": "MASTER genii",
        "Blood brother": "Blood brethren",
        "prima donna": "prime donne",
        "prima DONNA": "prime DONNE",
    }
    for singular, plural in test_cases.items():
        assert p.plural(singular) == plural
    p.classical(all=False)