Debian Codegraph @

tests/test_utils.py

raw symbols SCIP
1 import pytest
2 from fontTools.ttLib import TTFont
3
4
5 @pytest.mark.parametrize(
6 "url,want",
7 [
8 ("https://www.google.com", "google.com"),
9 ("https://google.com", "google.com"),
10 ("http://www.google.com", "google.com"),
11 ("http://google.com", "google.com"),
12 ("google.com", "google.com"),
13 ("", ""),
14 ],
15 )
16 def test_remove_url_prefix(url, want):
17 from gftools.utils import remove_url_prefix
18
19 got = remove_url_prefix(url)
20 assert got == want
21
22
23 def test_format_html():
24 from gftools.utils import format_html
25
26 input = """<p>
27 First sentence. Second sentence.
28 Sentence that uses an abbreviation, e.g. "for example". Sentence that uses an abbreviation, eg. "for example".
29 Sentence that uses another abbreviation, i.e. "for example". Sentence that uses another abbreviation, ie. "for example".
30 Sentence that ends in etc. Another sentence after it.
31 Sentence that uses etc. but then doesn't end.
32 The characters of the film were designed by H.R. Giger. His alien characters became iconic throughout pop culture.
33 The characters of the film were designed by H.R. Giger, a Swiss sculptural artist. His alien characters became iconic throughout pop culture.
34 He was referred to H.R. Giger, who headed the H.R. department at the time, then told them they're fired. <-- Can't have it both ways. Legitimate abbreviations at the end of sentences can only be caught if they are known in advance, e.g. etc.
35 </p>
36 """
37
38 output = """<p>
39 First sentence.
40 Second sentence.
41 Sentence that uses an abbreviation, e.g. "for example".
42 Sentence that uses an abbreviation, eg. "for example".
43 Sentence that uses another abbreviation, i.e. "for example".
44 Sentence that uses another abbreviation, ie. "for example".
45 Sentence that ends in etc.
46 Another sentence after it.
47 Sentence that uses etc. but then doesn't end.
48 The characters of the film were designed by H.R.
49 Giger.
50 His alien characters became iconic throughout pop culture.
51 The characters of the film were designed by H.R.
52 Giger, a Swiss sculptural artist.
53 His alien characters became iconic throughout pop culture.
54 He was referred to H.R.
55 Giger, who headed the H.R. department at the time, then told them they're fired.
56 <-- Can't have it both ways.
57 Legitimate abbreviations at the end of sentences can only be caught if they are known in advance, e.g. etc.
58 </p>
59 """
60 assert format_html(input) == output
61
62
63 @pytest.mark.parametrize(
64 """url,want""",
65 [
66 (
67 "https://github.com/SorkinType/SASchoolHandAustralia",
68 ("SorkinType", "SASchoolHandAustralia"),
69 ),
70 (
71 "https://github.com/SorkinType/SASchoolHandAustralia/",
72 ("SorkinType", "SASchoolHandAustralia"),
73 ),
74 ("https://github.com/googlefonts/MavenPro//", ("googlefonts", "MavenPro")),
75 ("https://github.com/googlefonts/MavenPro.git", ("googlefonts", "MavenPro")),
76 (
77 "https://www.github.com/googlefonts/MavenPro.git",
78 ("googlefonts", "MavenPro"),
79 ),
80 ("http://www.github.com/googlefonts/MavenPro.git", ("googlefonts", "MavenPro")),
81 ("http://www.github.com/NDISCOVER/Exo-2.0.git", ("NDISCOVER", "Exo-2.0")),
82 ],
83 )
84 def test_github_user_repo(url, want):
85 from gftools.utils import github_user_repo
86
87 assert github_user_repo(url) == want
88
89
90 def test_supported_languages():
91 from gftools.util.google_fonts import SupportedLanguages
92
93 ttfont = TTFont("data/test/Nabla[EDPT,EHLT].subset.ttf")
94 langs = [l.id for l in SupportedLanguages(ttfont)]
95 assert langs == []
96
97 ttfont = TTFont("data/test/Lora-Regular.ttf")
98 langs = [l.id for l in SupportedLanguages(ttfont)]
99 assert len(langs) >= 350
100 assert "en_Latn" in langs