Ladsgroup has uploaded a new change for review. https://gerrit.wikimedia.org/r/238168
Change subject: Add PropertyPage tests, fix PropertyPage issues ...................................................................... Add PropertyPage tests, fix PropertyPage issues Change-Id: Ic83edd3ab506bb5673d2f4e2de2974fa13774bc6 --- M pywikibase/propertypage.py M tests/test_itempage.py A tests/test_propertypage.py 3 files changed, 34 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/wikibase refs/changes/68/238168/1 diff --git a/pywikibase/propertypage.py b/pywikibase/propertypage.py index 58b4085..d7573be 100644 --- a/pywikibase/propertypage.py +++ b/pywikibase/propertypage.py @@ -25,28 +25,28 @@ PropertyPage('P21') """ - def __init__(self, source=None, title=u""): + def __init__(self, title=u"", datatype=None): """ Constructor. @param title: page name of property, like "P##" @type title: str """ - WikibasePage.__init__(self, source, title) - if not title or not self.id.startswith('P'): + if not title.startswith('P'): raise ValueError( u"'%s' is not an property page title" % title) - Property.__init__(self, source, self.id) + self.id = title + Property.__init__(self, self.id, datatype) - def get(self, force=False, *args): + def get(self, *args): """ Fetch the property entity, and cache it. @param force: override caching @param args: values of props """ - if force or not hasattr(self, '_content'): - WikibasePage.get(self, force=force, *args) + if not hasattr(self, '_content'): + WikibasePage.get(self, *args) def newClaim(self, *args, **kwargs): """ diff --git a/tests/test_itempage.py b/tests/test_itempage.py index 35a3372..cc692d4 100644 --- a/tests/test_itempage.py +++ b/tests/test_itempage.py @@ -10,7 +10,7 @@ basestring = str -class TestWikibasePage(unittest.TestCase): +class TestItemPage(unittest.TestCase): def setUp(self): with open(os.path.join(os.path.split(__file__)[0], diff --git a/tests/test_propertypage.py b/tests/test_propertypage.py new file mode 100644 index 0000000..7ff34c0 --- /dev/null +++ b/tests/test_propertypage.py @@ -0,0 +1,26 @@ +import unittest +from pywikibase import PropertyPage, Claim + +try: + basestring +except NameError: + basestring = str + + +class TestPropertyPage(unittest.TestCase): + + def setUp(self): + self.property_page = PropertyPage('P31', 'wikibase-item') + + def test_init_item(self): + self.assertEqual(self.property_page.getID(), 'P31') + self.assertRaises(ValueError, PropertyPage, title='Null') + self.assertRaises(ValueError, PropertyPage, title='Q15') + + def test_new_claim(self): + claim = self.property_page.newClaim() + self.assertIsInstance(claim, Claim) + self.assertEqual(claim.id, self.property_page.getID()) + +if __name__ == '__main__': + unittest.main() -- To view, visit https://gerrit.wikimedia.org/r/238168 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic83edd3ab506bb5673d2f4e2de2974fa13774bc6 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/wikibase Gerrit-Branch: master Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits