|
1
|
|
|
#!/usr/local/bin/python |
|
|
|
|
|
|
2
|
|
|
# coding: utf-8 |
|
3
|
|
|
|
|
4
|
|
|
import unittest |
|
5
|
|
|
|
|
6
|
|
|
from titlesearch.language.detection import matches_language |
|
7
|
|
|
from titlesearch.language.language_settings import * |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class TestLanguageDetection(unittest.TestCase): |
|
|
|
|
|
|
11
|
|
|
titles = [ |
|
12
|
|
|
'Tate no Yuusha no Nariagari', |
|
13
|
|
|
'Tate no Yūsha no Nariagari', |
|
14
|
|
|
'盾の勇者の成り上がり', |
|
15
|
|
|
'방패 용사 성공담', |
|
16
|
|
|
'The Rising of the Shield Hero' |
|
17
|
|
|
] |
|
18
|
|
|
|
|
19
|
|
|
EXPECTED_RESULTS_ENGLISH = [ |
|
20
|
|
|
True, |
|
21
|
|
|
False, |
|
22
|
|
|
False, |
|
23
|
|
|
False, |
|
24
|
|
|
True |
|
25
|
|
|
] |
|
26
|
|
|
|
|
27
|
|
|
EXPECTED_RESULTS_KOREAN = [ |
|
28
|
|
|
False, |
|
29
|
|
|
False, |
|
30
|
|
|
False, |
|
31
|
|
|
True, |
|
32
|
|
|
False |
|
33
|
|
|
] |
|
34
|
|
|
|
|
35
|
|
|
EXPECTED_RESULTS_JAPANESE = [ |
|
36
|
|
|
False, |
|
37
|
|
|
False, |
|
38
|
|
|
True, |
|
39
|
|
|
False, |
|
40
|
|
|
False |
|
41
|
|
|
] |
|
42
|
|
|
|
|
43
|
|
|
def test_korean_results(self): |
|
44
|
|
|
"""Test the titles with the korean language configuration""" |
|
45
|
|
|
results = [] |
|
46
|
|
|
for title in self.titles: |
|
47
|
|
|
results.append(matches_language(title, Korean)) |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
self.assertEqual(self.EXPECTED_RESULTS_KOREAN, results) |
|
50
|
|
|
|
|
51
|
|
|
def test_japanese_detection(self): |
|
52
|
|
|
"""Test the titles with the japanese language configuration""" |
|
53
|
|
|
results = [] |
|
54
|
|
|
for title in self.titles: |
|
55
|
|
|
results.append(matches_language(title, Japanese)) |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
self.assertEqual(self.EXPECTED_RESULTS_JAPANESE, results) |
|
58
|
|
|
|
|
59
|
|
|
def test_english_detection(self): |
|
60
|
|
|
"""Test the titles with the english language configuration""" |
|
61
|
|
|
results = [] |
|
62
|
|
|
for title in self.titles: |
|
63
|
|
|
results.append(matches_language(title, English)) |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
self.assertEqual(self.EXPECTED_RESULTS_ENGLISH, results) |
|
66
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.