-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathimport_wikidata_test.py
More file actions
45 lines (39 loc) · 1.38 KB
/
import_wikidata_test.py
File metadata and controls
45 lines (39 loc) · 1.38 KB
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
#!/usr/bin/env python
import json
import unittest
from import_wikidata import parse_wikidata, map_value
class TestImportWikidata(unittest.TestCase):
def test_parse_wikidata(self):
objs = [{'hello': 'world'}, {'all': 'ok?'}, {'or': ['something', 'with', 'more']}]
lines = ['[\n']
for idx, obj in enumerate(objs):
lines.append(json.dumps(obj) + (',' if idx < len(objs) - 1 else '') + '\n')
lines.append(']\n')
parsed = list(parse_wikidata(lines))
self.assertEqual(parsed, objs)
def test_map_value(self):
coo = {
'value': {
'latitude': 52,
'longitude': 13,
'altitude': None,
'precision': 0.016666666666667,
'globe': 'http://www.wikidata.org/entity/Q2',
},
'type': 'globecoordinate',
}
self.assertEqual(map_value(coo, {}), {'lat': 52, 'lng': 13})
time = {
'value': {
'time': '+2001-12-00T00:00:00Z',
'timezone': 0,
'before': 0,
'after': 0,
'precision': 11,
'calendarmodel': 'http:\/\/www.wikidata.org\/entity\/Q1985727',
},
'type': 'time',
}
self.assertEqual(map_value(time, {}), '2001-12-01T00:00:00')
if __name__ == '__main__':
unittest.main()