summaryrefslogtreecommitdiffstats
path: root/debian/patches/0002-Add-tests-from-github.patch
blob: a72eae60026b0b89d0741aad645bd788039b8f72 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
From: Scott Kitterman <scott@kitterman.com>
Date: Fri, 4 Jan 2019 16:30:17 -0500
Subject: Add tests from github

---
 test.py | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)
 create mode 100644 test.py

diff --git a/test.py b/test.py
new file mode 100644
index 0000000..858342d
--- /dev/null
+++ b/test.py
@@ -0,0 +1,136 @@
+# This file is part of Pyphen
+#
+# Copyright 2013 - Guillaume Ayoub <guillaume.ayoub@kozea.fr>
+#
+# This library is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Pyphen.  If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+Pyphen Tests
+============
+
+Tests can be launched with:
+
+- Pytest (``py.test test.py``).
+- Nose (``nosetests``).
+
+"""
+
+
+from __future__ import unicode_literals
+
+import pyphen
+
+
+def test_inserted():
+    """Test the ``inserted`` method."""
+    dic = pyphen.Pyphen(lang='nl_NL')
+    assert dic.inserted('lettergrepen') == 'let-ter-gre-pen'
+
+
+def test_wrap():
+    """Test the ``wrap`` method."""
+    dic = pyphen.Pyphen(lang='nl_NL')
+    assert dic.wrap('autobandventieldopje', 11) == (
+        'autoband-', 'ventieldopje')
+
+
+def test_iterate():
+    """Test the ``iterate`` method."""
+    dic = pyphen.Pyphen(lang='nl_NL')
+    assert tuple(dic.iterate('Amsterdam')) == (
+        ('Amster', 'dam'), ('Am', 'sterdam'))
+
+
+def test_fallback_dict():
+    """Test the ``iterate`` method with a fallback dict."""
+    dic = pyphen.Pyphen(lang='nl_NL-variant')
+    assert tuple(dic.iterate('Amsterdam')) == (
+        ('Amster', 'dam'), ('Am', 'sterdam'))
+
+
+def test_missing_dict():
+    """Test a missing dict."""
+    try:
+        pyphen.Pyphen(lang='mi_SS')
+    except KeyError:
+        pass
+    else:  # pragma: no cover
+        raise Exception('Importing a missing dict must raise a KeyError')
+
+
+def test_personal_dict():
+    """Test a personal dict."""
+    dic = pyphen.Pyphen(lang='fr')
+    assert dic.inserted('autobandventieldopje') != 'au-to-band-ven-tiel-dop-je'
+    pyphen.LANGUAGES['fr'] = pyphen.LANGUAGES['nl_NL']
+    dic = pyphen.Pyphen(lang='fr')
+    assert dic.inserted('autobandventieldopje') == 'au-to-band-ven-tiel-dop-je'
+
+
+def test_left_right():
+    """Test the ``left`` and ``right`` parameters."""
+    dic = pyphen.Pyphen(lang='nl_NL')
+    assert dic.inserted('lettergrepen') == 'let-ter-gre-pen'
+    dic = pyphen.Pyphen(lang='nl_NL', left=4)
+    assert dic.inserted('lettergrepen') == 'letter-gre-pen'
+    dic = pyphen.Pyphen(lang='nl_NL', right=4)
+    assert dic.inserted('lettergrepen') == 'let-ter-grepen'
+    dic = pyphen.Pyphen(lang='nl_NL', left=4, right=4)
+    assert dic.inserted('lettergrepen') == 'letter-grepen'
+
+
+def test_filename():
+    """Test the ``filename`` parameter."""
+    dic = pyphen.Pyphen(filename=pyphen.LANGUAGES['nl_NL'])
+    assert dic.inserted('lettergrepen') == 'let-ter-gre-pen'
+
+
+def test_alternative():
+    """Test the alternative parser."""
+    dic = pyphen.Pyphen(lang='hu', left=1, right=1)
+    assert tuple(dic.iterate('kulissza')) == (
+        ('kulisz', 'sza'), ('ku', 'lissza'))
+    assert dic.inserted('kulissza') == 'ku-lisz-sza'
+
+
+def test_upper():
+    """Test uppercase."""
+    dic = pyphen.Pyphen(lang='nl_NL')
+    assert dic.inserted('LETTERGREPEN') == 'LET-TER-GRE-PEN'
+
+
+def test_upper_alternative():
+    """Test uppercase with alternative parser."""
+    dic = pyphen.Pyphen(lang='hu', left=1, right=1)
+    assert tuple(dic.iterate('KULISSZA')) == (
+        ('KULISZ', 'SZA'), ('KU', 'LISSZA'))
+    assert dic.inserted('KULISSZA') == 'KU-LISZ-SZA'
+
+
+def test_all_dictionaries():
+    """Test that all included dictionaries can be parsed."""
+    for lang in pyphen.LANGUAGES:
+        pyphen.Pyphen(lang=lang)
+
+
+def test_fallback():
+    """Test the language fallback algorithm."""
+    assert pyphen.language_fallback('en') == 'en'
+    assert pyphen.language_fallback('en_US') == 'en_US'
+    assert pyphen.language_fallback('en_FR') == 'en'
+    assert pyphen.language_fallback('en-Latn-US') == 'en_Latn_US'
+    assert pyphen.language_fallback('en-Cyrl-US') == 'en'
+    assert pyphen.language_fallback('fr-Latn-FR') == 'fr'
+    assert pyphen.language_fallback('en-US_variant1-x') == 'en_US'