Skip to content

Commit d9e6e67

Browse files
committed
Implement new version of FastRun
1 parent 7330804 commit d9e6e67

32 files changed

+771
-883
lines changed

.idea/inspectionProfiles/WikibaseIntegrator.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ for entrez_id, ensembl in raw_data.items():
567567

568568
Note: Fastrun mode checks for equality of property/value pairs, qualifiers (not including qualifier attributes), labels,
569569
aliases and description, but it ignores references by default!
570-
References can be checked in fast run mode by setting `use_refs` to `True`.
570+
References can be checked in fast run mode by setting `use_references` to `True`.
571571

572572
# Debugging #
573573

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ disable = [
3434

3535
[tool.pytest.ini_options]
3636
log_cli = true
37+
log_cli_level = 'DEBUG'

test/test_all.py

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import copy
2+
import logging
23
import unittest
34

45
from wikibaseintegrator import WikibaseIntegrator, datatypes, wbi_fastrun
56
from wikibaseintegrator.datatypes import BaseDataType, Item
6-
from wikibaseintegrator.entities import ItemEntity
7+
from wikibaseintegrator.entities import BaseEntity, ItemEntity
78
from wikibaseintegrator.wbi_config import config as wbi_config
8-
from wikibaseintegrator.wbi_enums import ActionIfExists
9-
from wikibaseintegrator.wbi_fastrun import get_fastrun_container
109

1110
wbi_config['USER_AGENT'] = 'WikibaseIntegrator-pytest/1.0 (test_all.py)'
1211

@@ -53,66 +52,24 @@ class TestFastRun(unittest.TestCase):
5352
"""
5453
some basic tests for fastrun mode
5554
"""
55+
logging.basicConfig(level=logging.DEBUG)
5656

5757
def test_fastrun(self):
5858
statements = [
59-
datatypes.ExternalID(value='P40095', prop_nr='P352'),
59+
datatypes.ExternalID(value='A0A023PZB3', prop_nr='P352'),
6060
datatypes.ExternalID(value='YER158C', prop_nr='P705')
6161
]
6262

6363
frc = wbi_fastrun.FastRunContainer(base_filter=[BaseDataType(prop_nr='P352'), datatypes.Item(prop_nr='P703', value='Q27510868')], base_data_type=datatypes.BaseDataType)
6464

65-
fastrun_result = frc.write_required(data=statements)
65+
entity = BaseEntity().add_claims(statements)
6666

67-
if fastrun_result:
68-
message = 'fastrun failed'
69-
else:
70-
message = 'successful fastrun'
67+
fastrun_result = frc.write_required(entity=entity)
7168

7269
# here, fastrun should succeed, if not, test failed
7370
if fastrun_result:
7471
raise ValueError
7572

76-
def test_fastrun_label(self):
77-
# tests fastrun label, description and aliases, and label in another language
78-
frc = get_fastrun_container(base_filter=[datatypes.ExternalID(value='/m/02j71', prop_nr='P646')])
79-
item = WikibaseIntegrator().item.get('Q2')
80-
81-
assert item.labels.get(language='en') == "Earth"
82-
descr = item.descriptions.get(language='en')
83-
assert len(descr) > 3
84-
assert "the Earth" in item.aliases.get()
85-
86-
assert list(frc.get_language_data("Q2", 'en', 'label'))[0] == item.labels.get(language='en')
87-
assert frc.check_language_data("Q2", ['not the Earth'], 'en', 'label')
88-
assert "the Earth" in item.aliases.get()
89-
assert "planet" in item.descriptions.get()
90-
91-
assert item.labels.get('es') == "Tierra"
92-
93-
item.descriptions.set(value=descr)
94-
item.descriptions.set(value="fghjkl")
95-
assert item.get_json()['descriptions']['en'] == {'language': 'en', 'value': 'fghjkl'}
96-
item.labels.set(value="Earth")
97-
item.labels.set(value="xfgfdsg")
98-
assert item.get_json()['labels']['en'] == {'language': 'en', 'value': 'xfgfdsg'}
99-
item.aliases.set(values=["fake alias"], action_if_exists=ActionIfExists.APPEND)
100-
assert {'language': 'en', 'value': 'fake alias'} in item.get_json()['aliases']['en']
101-
102-
# something thats empty (for now.., can change, so this just makes sure no exception is thrown)
103-
frc.check_language_data("Q2", ['Ewiase'], 'ak', 'label')
104-
frc.check_language_data("Q2", ['not Ewiase'], 'ak', 'label')
105-
frc.check_language_data("Q2", [''], 'ak', 'description')
106-
frc.check_language_data("Q2", [], 'ak', 'aliases')
107-
frc.check_language_data("Q2", ['sdf', 'sdd'], 'ak', 'aliases')
108-
109-
item.labels.get(language="ak")
110-
item.descriptions.get(language='ak')
111-
item.aliases.get(language="ak")
112-
item.labels.set(value="label", language="ak")
113-
item.descriptions.set(value="d", language="ak")
114-
item.aliases.set(values=["a"], language="ak", action_if_exists=ActionIfExists.APPEND)
115-
11673

11774
def test_sitelinks():
11875
item = wbi.item.get('Q622901')

test/test_entity_item.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def test_write(self):
4848
def test_write_not_required(self):
4949
assert not wbi.item.get('Q582').write_required(base_filter=[BaseDataType(prop_nr='P1791')])
5050

51+
def test_write_not_required_ref(self):
52+
assert not wbi.item.get('Q582').write_required(base_filter=[BaseDataType(prop_nr='P1464')], use_references=True)
53+
5154
def test_write_required(self):
5255
item = wbi.item.get('Q582')
5356
item.claims.add(Item(prop_nr='P1791', value='Q42'))
5457
assert item.write_required([BaseDataType(prop_nr='P1791')])
5558

56-
def test_write_not_required_ref(self):
57-
assert not wbi.item.get('Q582').write_required(base_filter=[BaseDataType(prop_nr='P2581')], use_refs=True)
58-
5959
def test_write_required_ref(self):
6060
item = wbi.item.get('Q582')
61-
item.claims.get('P2581')[0].references.references.pop()
62-
assert item.write_required(base_filter=[BaseDataType(prop_nr='P2581')], use_refs=True)
61+
item.claims.get('P1464')[0].references.references.pop()
62+
assert item.write_required(base_filter=[BaseDataType(prop_nr='P1464')], use_references=True)

test/test_wbi_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def test_new_item_creation(self):
231231
MonolingualText(text="xxx", language="fr", prop_nr="P7"),
232232
Quantity(amount=-5.04, prop_nr="P8"),
233233
Quantity(amount=5.06, upper_bound=9.99, lower_bound=-2.22, unit="Q11573", prop_nr="P8"),
234-
CommonsMedia(value="xxx", prop_nr="P9"),
234+
CommonsMedia(value="Place lazare goujon.jpg", prop_nr="P9"),
235235
GlobeCoordinate(latitude=1.2345, longitude=-1.2345, precision=12, prop_nr="P10"),
236236
GeoShape(value="Data:xxx.map", prop_nr="P11"),
237237
Property(value="P123", prop_nr="P12"),

test/test_wbi_fastrun.py

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)