Lokal Profil has uploaded a new change for review.
https://gerrit.wikimedia.org/r/264739
Change subject: Add tests for Wikibase Monolingual text
......................................................................
Add tests for Wikibase Monolingual text
Additionaly raise error if either parameter is empty, or not
a basestring, during object creation.
Bug:T123856
Change-Id: I10cec092bf7444b3d9408972a38b0eb415658bb0
---
M pywikibot/__init__.py
M tests/wikibase_tests.py
2 files changed, 37 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/39/264739/1
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 609d4f8..0b52db5 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -552,6 +552,11 @@
@param language: language code of the string
@type language: str
"""
+ if (not isinstance(text, basestring) or
+ not isinstance(language, basestring)):
+ raise ValueError('invalid input type')
+ if text == '' or language == '':
+ raise ValueError('text and language cannot be empty strings')
self.text = text
self.language = language
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index e7bc61f..1385d84 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -225,6 +225,38 @@
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')
+ self.assertRaises(ValueError, pywikibot.WbMonolingualText,
+ text='Test this!', language=125)
+
class TestItemPageExtensibility(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/264739
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I10cec092bf7444b3d9408972a38b0eb415658bb0
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits