-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_parse_value.py
79 lines (68 loc) · 2.49 KB
/
test_parse_value.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
from unittest.mock import Mock
import pytest
from position_statements import get_existing_claim, parse_value
def test_parse_value_item_id():
assert parse_value('Q42') == {
'type': 'wikibase-entityid',
'value': {
'entity-type': 'item', 'id': 'Q42'
}
}
def test_parse_value_string():
assert parse_value('" hello, i\'m a "string" \"') == {
'type': 'string',
'value': 'hello, i\'m a "string"',
}
def test_parse_value_time():
assert parse_value('+2000-01-20T00:04:35Z/11') == {
'type': 'time',
'value': {
'time': '+2000-01-20T00:04:35Z',
'precision': 11
}
}
def test_parse_value_statement_raw_uuid():
assert parse_value('Q42-DD45AFB0-7249-4690-AAE3-86C9FF996CE2') == {
'type': 'x-wikidata-statementid',
'value': 'Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2',
}
def test_parse_value_statement_api_uuid():
assert parse_value('Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2') == {
'type': 'x-wikidata-statementid',
'value': 'Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2',
}
def test_parse_value_statement_wds_uuid():
assert parse_value('wds:Q42-DD45AFB0-7249-4690-AAE3-86C9FF996CE2') == {
'type': 'x-wikidata-statementid',
'value': 'Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2',
}
def test_get_existing_claim_unknown_property():
mock_item = Mock(claims={})
with pytest.raises(Exception) as excinfo:
get_existing_claim(
mock_item,
'P123456',
'Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2'
)
assert 'No property P123456 found in claims of' in str(excinfo.value)
def test_get_claim_missing():
mock_item = Mock(claims={'P123456': []})
mock_item.__str__ = Mock()
mock_item.__str__.return_value = '<Item: Some item or other>'
with pytest.raises(Exception) as excinfo:
get_existing_claim(
mock_item,
'P123456',
'Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2'
)
assert 'The snak Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2 was ' \
'not found for any claim on \'<Item: Some item or other>\' ' \
'with property P123456' in str(excinfo.value)
def test_get_claim_found():
mock_claim = Mock(snak='Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2')
mock_item = Mock(claims={'P123456': [mock_claim]})
assert get_existing_claim(
mock_item,
'P123456',
'Q42$DD45AFB0-7249-4690-AAE3-86C9FF996CE2'
) is mock_claim