-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_bibmatcher.py
executable file
·150 lines (116 loc) · 5.1 KB
/
test_bibmatcher.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
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
#!/usr/local/bin/python3
import unittest
import marcaroni.output
import marcaroni.ils
import marcaroni.sources
import bibmatcher
class MockOutputRecordHandler(marcaroni.output.OutputRecordHandler):
# noinspection PyMissingConstructor
def __init__(self):
self.calls = []
def __del__(self):
pass
def no_match(self, marc_rec):
self.calls.append(('add', marc_rec))
def ambiguous(self, marc_rec, reason):
self.calls.append(('ambiguous', marc_rec, reason))
def match_is_worse(self, marc_rec, bib_id):
self.calls.append(('update', marc_rec, bib_id))
def match_is_better(self, marc_rec):
self.calls.append(('ignore', marc_rec))
def report_of_ddas_to_hide(self, title, platform, bib_id):
self.calls.append(('report_of_ddas_to_hide', title, platform, bib_id))
class MARCRecord:
pass
class MyTestCase(unittest.TestCase):
@staticmethod
def get_marc_record():
return MARCRecord()
@staticmethod
def get_vectors(better_licensed=True, same_platform=False, odd_bs=False, length=3):
v = {}
for i in range(length):
v[marcaroni.ils.Record(i, '1')] = bibmatcher.PredicateVector(
match_is_better_license = better_licensed,
match_is_dda = False,
match_is_same_platform = same_platform,
match_is_odd_bibsource = odd_bs
)
return v
def test_ignore_if_new_record_is_dda_and_better_is_available_input_not_dda(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'purchased')
output = MockOutputRecordHandler()
self.assertFalse(bibmatcher.ignore_if_new_record_is_dda_and_better_is_available(
self.get_marc_record(),
input_bib_source,
self.get_vectors(),
output
))
def test_ignore_if_new_record_is_dda_and_better_is_available_input_is_dda_better_is_avail(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'dda')
output = MockOutputRecordHandler()
self.assertTrue(bibmatcher.ignore_if_new_record_is_dda_and_better_is_available(
self.get_marc_record(),
input_bib_source,
self.get_vectors(),
output
))
self.assertEqual(len(output.calls), 1)
self.assertEqual(output.calls[0][0], 'ignore')
def test_ignore_if_new_record_is_dda_and_better_is_available_input_is_dda_better_is_not_avail(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'dda')
output = MockOutputRecordHandler()
self.assertFalse(bibmatcher.ignore_if_new_record_is_dda_and_better_is_available(
self.get_marc_record(),
input_bib_source,
self.get_vectors(better_licensed=False),
output
))
def test_update_same_platform_match_if_unambiguous_no_same_plat_match(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'dda')
output = MockOutputRecordHandler()
self.assertFalse(bibmatcher.handle_same_platform_matches(
self.get_marc_record(),
input_bib_source,
self.get_vectors(),
output
))
def test_update_same_platform_match_if_unambiguous_multiple_same_plat_match(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'dda')
output = MockOutputRecordHandler()
self.assertTrue(bibmatcher.handle_same_platform_matches(
self.get_marc_record(),
input_bib_source,
self.get_vectors(same_platform=True),
output
))
self.assertEqual(len(output.calls), 1)
self.assertEqual(output.calls[0][0], 'ambiguous')
def test_update_same_platform_match_if_unambiguous_one_same_plat_match_with_worse(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'dda')
output = MockOutputRecordHandler()
v = self.get_vectors(same_platform=True, better_licensed=False, length=1)
v.update(self.get_vectors(same_platform=False, length=2))
self.assertTrue(bibmatcher.handle_same_platform_matches(
self.get_marc_record(),
input_bib_source,
v,
output
))
self.assertEqual(len(output.calls), 1)
self.assertEqual(output.calls[0][0], 'update')
def test_update_same_platform_match_if_unambiguous_one_same_plat_match_with_better(self):
input_bib_source = marcaroni.sources.BibSource('1', 'test', 'test_plat', 'dda')
output = MockOutputRecordHandler()
v = self.get_vectors(same_platform=True, better_licensed=True, length=1)
v.update(self.get_vectors(same_platform=False, length=2))
self.assertTrue(bibmatcher.handle_same_platform_matches(
self.get_marc_record(),
input_bib_source,
v,
output
))
self.assertEqual(len(output.calls), 1)
self.assertEqual(output.calls[0][0], 'ignore')
if __name__ == '__main__':
unittest.main()