jenkins-bot has submitted this change and it was merged.
Change subject: Add tests for Wikibase Monolingual text ......................................................................
Add tests for Wikibase Monolingual text
Additionaly raise error if either parameter is empty, during object creation.
Bug:T123856 Change-Id: I10cec092bf7444b3d9408972a38b0eb415658bb0 --- M pywikibot/__init__.py M tests/wikibase_tests.py 2 files changed, 32 insertions(+), 0 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved Smalyshev: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 609d4f8..62f177f 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -552,6 +552,8 @@ @param language: language code of the string @type language: str """ + if not text or not language: + raise ValueError('text and language cannot be empty') self.text = text self.language = language
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index e7bc61f..53d7cee 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -225,6 +225,36 @@ self.assertRaises(ValueError, pywikibot.WbQuantity, amount=None, error=1)
+ def test_WbMonolingualText_string(self): + q = pywikibot.WbMonolingualText(text='Test that basics work', language='en') + q_dict = {'text': 'Test that basics work', 'language': 'en'} + self.assertEqual(q.toWikibase(), q_dict) + + def test_WbMonolingualText_unicode(self): + q = pywikibot.WbMonolingualText(text='Testa det här', language='sv') + q_dict = {'text': 'Testa det här', 'language': 'sv'} + self.assertEqual(q.toWikibase(), q_dict) + + def test_WbMonolingualText_equality(self): + q = pywikibot.WbMonolingualText(text='Thou shall test this!', language='en-gb') + self.assertEqual(q, q) + + def test_WbMonolingualText_fromWikibase(self): + # test WbMonolingualText.fromWikibase() instantiating + q = pywikibot.WbMonolingualText.fromWikibase({'text': 'Test this!', + 'language': u'en'}) + self.assertEqual(q.toWikibase(), + {'text': 'Test this!', 'language': 'en', }) + + def test_WbMonolingualText_errors(self): + # test WbMonolingualText error handling + self.assertRaises(ValueError, pywikibot.WbMonolingualText, + text='', language='sv') + self.assertRaises(ValueError, pywikibot.WbMonolingualText, + text='Test this!', language='') + self.assertRaises(ValueError, pywikibot.WbMonolingualText, + text=None, language='sv') +
class TestItemPageExtensibility(TestCase):
pywikibot-commits@lists.wikimedia.org