Exemplo n.º 1
0
    def test_fast_run(self):
        statements = [
            wbi_datatype.ExternalID(value='P40095', prop_nr='P352'),
            wbi_datatype.ExternalID(value='YER158C', prop_nr='P705')
        ]

        frc = wbi_fastrun.FastRunContainer(base_filter={'P352': '', 'P703': 'Q27510868'},
                                           base_data_type=wbi_datatype.BaseDataType, engine=wbi_core.ItemEngine)

        fast_run_result = frc.write_required(data=statements)

        if fast_run_result:
            message = 'fastrun failed'
        else:
            message = 'successful fastrun'
        print(fast_run_result, message)
Exemplo n.º 2
0
    def test_qualifier(self):
        # Good
        qualifiers = [wbi_datatype.ExternalID(value='P58742', prop_nr='P352', is_qualifier=True),
                      wbi_datatype.ItemID(value='Q24784025', prop_nr='P527', is_qualifier=True),
                      wbi_datatype.Time(time='+2001-12-31T12:01:13Z', prop_nr='P813', is_qualifier=True)]
        wbi_datatype.ItemID("Q123", "P123", qualifiers=qualifiers)

        qualifiers = wbi_datatype.ExternalID(value='P58742', prop_nr='P352', is_qualifier=True)
        wbi_datatype.ItemID("Q123", "P123", qualifiers=qualifiers)

        # Bad
        qualifiers = wbi_datatype.ExternalID(value='P58742', prop_nr='P352', is_qualifier=False)
        with self.assertRaises(ValueError):
            wbi_datatype.ItemID("Q123", "P123", qualifiers=qualifiers)

        bad_qualifiers = ["not a good qualifier",
                          wbi_datatype.ItemID(value='Q24784025', prop_nr='P527', is_qualifier=True),
                          wbi_datatype.Time(time='+2001-12-31T12:01:13Z', prop_nr='P813', is_qualifier=True)]
        with self.assertRaises(ValueError):
            wbi_datatype.ItemID("Q123", "P123", qualifiers=bad_qualifiers)
Exemplo n.º 3
0
    def test_new_item_creation(self):
        data = [
            wbi_datatype.String(value='test1', prop_nr='P1'),
            wbi_datatype.String(value='test2', prop_nr='1'),
            wbi_datatype.String(value='test3', prop_nr=1),
            wbi_datatype.Math("xxx", prop_nr="P2"),
            wbi_datatype.ExternalID("xxx", prop_nr="P3"),
            wbi_datatype.ItemID("Q123", prop_nr="P4"),
            wbi_datatype.ItemID("123", prop_nr="P4"),
            wbi_datatype.ItemID(123, prop_nr="P4"),
            wbi_datatype.Time(time='-0458-00-00T00:00:00Z', before=1, after=2, precision=3, timezone=4, prop_nr="P5"),
            wbi_datatype.Time(time='458-00-00T00:00:00Z', before=1, after=2, precision=3, timezone=4, prop_nr="P5"),
            wbi_datatype.Time(time='+2021-01-01T15:15:15Z', before=1, after=2, precision=3, timezone=4, prop_nr="P5"),
            wbi_datatype.Url("http://www.wikidata.org", prop_nr="P6"),
            wbi_datatype.Url("https://www.wikidata.org", prop_nr="P6"),
            wbi_datatype.Url("ftp://example.com", prop_nr="P6"),
            wbi_datatype.Url("ssh://user@server/project.git", prop_nr="P6"),
            wbi_datatype.Url("svn+ssh://user@server:8888/path", prop_nr="P6"),
            wbi_datatype.MonolingualText(text="xxx", language="fr", prop_nr="P7"),
            wbi_datatype.Quantity(quantity=-5.04, prop_nr="P8"),
            wbi_datatype.Quantity(quantity=5.06, upper_bound=9.99, lower_bound=-2.22, unit="Q11573", prop_nr="P8"),
            wbi_datatype.CommonsMedia("xxx", prop_nr="P9"),
            wbi_datatype.GlobeCoordinate(latitude=1.2345, longitude=-1.2345, precision=12, prop_nr="P10"),
            wbi_datatype.GeoShape("Data:xxx.map", prop_nr="P11"),
            wbi_datatype.Property("P123", prop_nr="P12"),
            wbi_datatype.Property("123", prop_nr="P12"),
            wbi_datatype.Property(123, prop_nr="P12"),
            wbi_datatype.TabularData("Data:Taipei+Population.tab", prop_nr="P13"),
            wbi_datatype.MusicalNotation("\relative c' { c d e f | g2 g | a4 a a a | g1 |}", prop_nr="P14"),
            wbi_datatype.Lexeme("L123", prop_nr="P15"),
            wbi_datatype.Lexeme("123", prop_nr="P15"),
            wbi_datatype.Lexeme(123, prop_nr="P15"),
            wbi_datatype.Form("L123-F123", prop_nr="P16"),
            wbi_datatype.Sense("L123-S123", prop_nr="P17"),
            wbi_datatype.EDTF("2004-06-~01/2004-06-~20", prop_nr="P18")
        ]
        core_props = {f"P{x}" for x in range(20)}

        for d in data:
            item = wbi_core.ItemEngine(new_item=True, data=[d], core_props=core_props)
            assert item.get_json_representation()
            item = wbi_core.ItemEngine(new_item=True, data=d, core_props=core_props)
            assert item.get_json_representation()
            item = wbi_core.ItemEngine(new_item=True, data=[d], core_props=set())
            assert item.get_json_representation()
            item = wbi_core.ItemEngine(new_item=True, data=d, core_props=set())
            assert item.get_json_representation()

        item = wbi_core.ItemEngine(new_item=True, data=data, core_props=core_props)
        assert item.get_json_representation()
        item = wbi_core.ItemEngine(new_item=True, data=data, core_props=set())
        assert item.get_json_representation()
Exemplo n.º 4
0
def test_ref_equals():
    # statements are identical
    oldref = [wbi_datatype.ExternalID(value='P58742', prop_nr='P352', is_reference=True),
              wbi_datatype.ItemID(value='Q24784025', prop_nr='P527', is_reference=True),
              wbi_datatype.Time(time='+2001-12-31T12:01:13Z', prop_nr='P813', is_reference=True)]
    olditem = wbi_datatype.ItemID("Q123", "P123", references=[oldref])
    newitem = copy.deepcopy(olditem)
    assert olditem.equals(newitem, include_ref=False)
    assert olditem.equals(newitem, include_ref=True)

    # dates are a month apart
    newitem = copy.deepcopy(olditem)
    newitem.references[0][2] = wbi_datatype.Time(time='+2002-01-31T12:01:13Z', prop_nr='P813')
    assert olditem.equals(newitem, include_ref=False)
    assert not olditem.equals(newitem, include_ref=True)

    # multiple refs
    newitem = copy.deepcopy(olditem)
    newitem.references.append([wbi_datatype.ExternalID(value='99999', prop_nr='P352')])
    assert olditem.equals(newitem, include_ref=False)
    assert not olditem.equals(newitem, include_ref=True)
    olditem.references.append([wbi_datatype.ExternalID(value='99999', prop_nr='P352')])
    assert olditem.equals(newitem, include_ref=True)
Exemplo n.º 5
0
    def test_fastrun_label(self):
        # tests fastrun label, description and aliases, and label in another language
        data = [wbi_datatype.ExternalID('/m/02j71', 'P646')]
        fast_run_base_filter = {'P361': 'Q18589965'}
        item = wbi_core.ItemEngine(item_id="Q2", data=data, fast_run=True, fast_run_base_filter=fast_run_base_filter)

        frc = wbi_core.ItemEngine.fast_run_store[0]
        frc.debug = True

        assert item.get_label('en') == "Earth"
        descr = item.get_description('en')
        assert len(descr) > 3
        aliases = item.get_aliases()
        assert "globe" in aliases

        assert list(item.fast_run_container.get_language_data("Q2", 'en', 'label'))[0] == "Earth"
        assert item.fast_run_container.check_language_data("Q2", ['not the Earth'], 'en', 'label')
        assert "globe" in item.get_aliases()
        assert "planet" in item.get_description()

        assert item.get_label("es") == "Tierra"

        item.set_description(descr)
        item.set_description("fghjkl")
        assert item.json_representation['descriptions']['en'] == {'language': 'en', 'value': 'fghjkl'}
        item.set_label("Earth")
        item.set_label("xfgfdsg")
        assert item.json_representation['labels']['en'] == {'language': 'en', 'value': 'xfgfdsg'}
        item.set_aliases(["fake alias"], if_exists='APPEND')
        assert {'language': 'en', 'value': 'fake alias'} in item.json_representation['aliases']['en']

        # something thats empty (for now.., can change, so this just makes sure no exception is thrown)
        frc.check_language_data("Q2", ['Ewiase'], 'ak', 'label')
        frc.check_language_data("Q2", ['not Ewiase'], 'ak', 'label')
        frc.check_language_data("Q2", [''], 'ak', 'description')
        frc.check_language_data("Q2", [], 'ak', 'aliases')
        frc.check_language_data("Q2", ['sdf', 'sdd'], 'ak', 'aliases')

        item.get_label("ak")
        item.get_description("ak")
        item.get_aliases("ak")
        item.set_label("label", lang="ak")
        item.set_description("d", lang="ak")
        item.set_aliases(["a"], lang="ak", if_exists='APPEND')