forked from ChelseaKR/power-content-check
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_normalize.py
More file actions
72 lines (51 loc) · 2.8 KB
/
Copy pathtest_normalize.py
File metadata and controls
72 lines (51 loc) · 2.8 KB
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
"""Normalisation must widen matching, never narrow it."""
from __future__ import annotations
from power_content_check.normalize import (
contains,
contains_ignoring_spaces,
normalize,
normalize_lines,
)
class TestNormalize:
def test_ampersand_becomes_and(self) -> None:
assert normalize("Biomass & Biogas") == "biomass and biogas"
assert normalize("Coal & Petroleum") == "coal and petroleum"
def test_hyphenation_folds(self) -> None:
assert normalize("Zero-Carbon") == "zero carbon"
assert normalize("firmed-and-shaped") == "firmed and shaped"
def test_typographic_quotes_fold(self) -> None:
assert normalize("\u201cUnbundled RECs\u201d") == '"unbundled recs"'
assert normalize("California\u2019s") == "california's"
def test_non_breaking_space_folds(self) -> None:
nbsp = "\u00a0"
assert normalize(f"100{nbsp}%") == "100 %"
def test_runs_of_whitespace_collapse(self) -> None:
assert normalize("Solar 14%\n\n 65%") == "solar 14% 65%"
def test_case_folds(self) -> None:
assert normalize("2024 POWER CONTENT LABEL") == "2024 power content label"
def test_the_issued_rendering_matches_the_regulation_wording(self) -> None:
"""The point of the ampersand rule, stated as a test."""
assert normalize("Biomass & Biogas") == normalize("Biomass and biogas")
assert normalize("Coal & Petroleum") == normalize("Coal and petroleum")
class TestNormalizeLines:
def test_blank_lines_are_dropped(self) -> None:
assert normalize_lines("a\n\n \nb") == ["a", "b"]
def test_each_line_is_folded_separately(self) -> None:
assert normalize_lines("Solar 14%\nWind 4%") == ["solar 14%", "wind 4%"]
class TestContains:
def test_needle_is_normalised_too(self) -> None:
assert contains(normalize("Coal & Petroleum 0%"), "Coal and petroleum")
def test_absent_needle(self) -> None:
assert not contains(normalize("Solar 14%"), "Geothermal")
class TestContainsIgnoringSpaces:
"""A subscript, a ligature or a kerned pair splits one word into two runs."""
def test_a_split_word_still_matches(self) -> None:
extracted = normalize("figures exclude biogenic CO\n2 and emissions")
assert contains_ignoring_spaces(extracted, "biogenic CO2 and emissions")
def test_a_word_that_is_genuinely_missing_does_not_match(self) -> None:
extracted = normalize("figures exclude emissions")
assert not contains_ignoring_spaces(extracted, "biogenic CO2 and emissions")
def test_intervening_words_are_not_ignored(self) -> None:
"""It ignores where the spaces are, not what sits between the words."""
extracted = normalize("CA Utility Power Mix Average")
assert not contains_ignoring_spaces(extracted, "CA Utility Average")