1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
# Copyright 2014-2018 by Christopher C. Little. |
4
|
|
|
# This file is part of Abydos. |
5
|
|
|
# |
6
|
|
|
# Abydos is free software: you can redistribute it and/or modify |
7
|
|
|
# it under the terms of the GNU General Public License as published by |
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
# (at your option) any later version. |
10
|
|
|
# |
11
|
|
|
# Abydos is distributed in the hope that it will be useful, |
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
# GNU General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU General Public License |
17
|
|
|
# along with Abydos. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
"""abydos.tests. |
21
|
|
|
|
22
|
|
|
This module contains unit tests for Abydos |
23
|
|
|
""" |
24
|
|
|
|
25
|
|
|
from __future__ import unicode_literals |
26
|
|
|
|
27
|
|
|
import os |
28
|
|
|
import unittest |
29
|
|
|
from random import random |
30
|
|
|
|
31
|
|
|
CORPORA = os.path.join(os.path.dirname(__file__), 'corpora') |
32
|
|
|
|
33
|
|
|
EXTREME_TEST = False # Set to True to test EVERY single case (NB: takes hours) |
34
|
|
|
ALLOW_RANDOM = True # Set to False to skip all random tests |
35
|
|
|
|
36
|
|
|
if not EXTREME_TEST and os.path.isfile(os.path.join(os.path.dirname(__file__), |
37
|
|
|
'EXTREME_TEST')): |
38
|
|
|
# EXTREME_TEST file detected -- switching to EXTREME_TEST mode... |
39
|
|
|
EXTREME_TEST = True |
40
|
|
|
|
41
|
|
|
NIALL = ('Niall', 'Neal', 'Neil', 'Njall', 'Njáll', 'Nigel', 'Neel', 'Nele', |
42
|
|
|
'Nigelli', 'Nel', 'Kneale', 'Uí Néill', 'O\'Neill', 'MacNeil', |
43
|
|
|
'MacNele', 'Niall Noígíallach') |
44
|
|
|
|
45
|
|
|
COLIN = ('Colin', 'Collin', 'Cullen', 'Cuilen', 'Cailean', 'MacCailean', |
46
|
|
|
'Cuilén', 'Colle', 'Calum', 'Callum', 'Colinn', 'Colon', 'Colynn', |
47
|
|
|
'Col', 'Cole', 'Nicolas', 'Nicholas', 'Cailean Mór Caimbeul') |
48
|
|
|
|
49
|
|
|
NONQ_FROM = 'The quick brown fox jumped over the lazy dog.' |
50
|
|
|
NONQ_TO = 'That brown dog jumped over the fox.' |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
def _corpus_file(name, corpora_dir=CORPORA): |
54
|
|
|
"""Return the path to a corpus file. |
55
|
|
|
|
56
|
|
|
:param str name: corpus file |
57
|
|
|
:param str corpora_dir: the directory containing the corpora |
58
|
|
|
:return: path |
59
|
|
|
""" |
60
|
|
|
return os.path.join(corpora_dir, name) |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
def _one_in(inverse_probability): |
64
|
|
|
"""Return whether to run a test. |
65
|
|
|
|
66
|
|
|
Return True if: |
67
|
|
|
EXTREME_TEST is True |
68
|
|
|
OR |
69
|
|
|
(ALLOW_RANDOM is True |
70
|
|
|
AND |
71
|
|
|
random.random() * inverse_probability < 1) |
72
|
|
|
Otherwise return False |
73
|
|
|
|
74
|
|
|
:param int inverse_probability: the inverse of the probability |
75
|
|
|
:returns: whether to run a test |
76
|
|
|
:rtype: bool |
77
|
|
|
""" |
78
|
|
|
if EXTREME_TEST: |
79
|
|
|
return True |
80
|
|
|
elif ALLOW_RANDOM and random() * inverse_probability < 1: # noqa: S311 |
81
|
|
|
return True |
82
|
|
|
else: |
83
|
|
|
return False |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
if __name__ == '__main__': |
87
|
|
|
unittest.main() |
88
|
|
|
|