forked from fmfi/citacie
/
tests.py
executable file
·64 lines (56 loc) · 2.29 KB
/
tests.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from model import Author
author_parse_test_cases = [
(u'Surname, First', Author(u'Surname', [u'First'])),
(u'Surname, First Second', Author(u'Surname', [u'First', u'Second'])),
(u'Smith JD', Author(u'Smith', [u'J.', u'D.'])),
(u'Smith J.D.', Author(u'Smith', [u'J.', u'D.'])),
(u'Smith, J.D.', Author(u'Smith', [u'J.', u'D.'])),
(u'Smith J. D.', Author(u'Smith', [u'J.', u'D.'])),
(u'Smith, J. D.', Author(u'Smith', [u'J.', u'D.'])),
(u'Cheng Kai-Tei', Author(u'Cheng', [u'Kai', u'Tei'])),
(u'Cheng K-T', Author(u'Cheng', [u'K.', u'T.'])),
(u'Cheng K.-T.', Author(u'Cheng', [u'K.', u'T.'])),
(u'Cheng K-T', Author(u'Cheng', [u'K.', u'T.'])),
(u'Cheng K-T', Author(u'Cheng', [u'K.', u'T.'])),
(u'Nobrega de Sousa, V.', Author(u'Nobrega de Sousa', [u'V.'])),
(u'Nobrega de Sousa V.', Author(u'Nobrega de Sousa', [u'V.'])),
(u'Nobrega de Sousa V', Author(u'Nobrega de Sousa', [u'V.'])),
(u'Nobrega de Sousa V', Author(u'Nobrega de Sousa', [u'V.'])),
(u'de Sousa V.', Author(u'de Sousa', [u'V.'])),
(u'de Sousa Vito', Author(u'de Sousa', [u'Vito'])),
(u'de Menezes Neto, R.', Author(u'de Menezes Neto', [u'R.'])),
(u'de Menezes Neto R.', Author(u'de Menezes Neto', [u'R.'])),
(u'McDonald R.', Author(u'McDonald', [u'R.'])),
]
author_short_name_test_cases = [
(Author(u'MCDONALD', [u'R.']), u'McDonald, R.'),
(Author(u'NOBREGA DE SOUSA', [u'V.']), u'Nobrega de Sousa, V.'),
]
def check_parsed_author(source, expected):
parsed = Author.parse_sn_first(source)
try:
assert parsed.surname == expected.surname
assert len(parsed.names) == len(expected.names)
for i in range(len(parsed.names)):
assert parsed.names[i] == expected.names[i], i
except AssertionError:
print "{!r} != {!r}".format(parsed, expected)
raise
def test_parsing_author():
for args in author_parse_test_cases:
yield check_parsed_author, args[0], args[1]
def check_author_short_name(author, expected):
short_name = author.short_name
try:
assert short_name == expected
except AssertionError:
print "{!r} != {!r}".format(short_name, expected)
raise
def test_author_short_name():
for args in author_short_name_test_cases:
yield check_author_short_name, args[0], args[1]
if __name__ == "__main__":
import nose
nose.main()