jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] init: Return valid json in str() for WbTime and WbQuantity ......................................................................
[FIX] init: Return valid json in str() for WbTime and WbQuantity
The test failed if the order was different.
Bug: 64468 Change-Id: I3fa8ddf984a8e91cf3ecbde9a97c7e8933794cf4 --- M pywikibot/__init__.py M tests/wikibase_tests.py 2 files changed, 9 insertions(+), 4 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index e25bdc0..a5b964d 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -16,6 +16,7 @@ import re import sys import threading +import json
if sys.version_info[0] == 2: from Queue import Queue @@ -377,7 +378,7 @@ ts[u'calendarmodel'])
def __str__(self): - return str(self.toWikibase()) + return json.dumps(self.toWikibase(), indent=4, sort_keys=True)
def __eq__(self, other): return self.__dict__ == other.__dict__ @@ -445,7 +446,7 @@ return WbQuantity(amount, wb['unit'], error)
def __str__(self): - return str(self.toWikibase()) + return json.dumps(self.toWikibase(), indent=4, sort_keys=True)
def __eq__(self, other): return self.__dict__ == other.__dict__ diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index 24be9fd..a4d7b6b 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -84,8 +84,12 @@ 'upperBound': 0.044405586, 'unit': '1', }) # test other WbQuantity methods self.assertEqual("%s" % q, - "{'amount': %(val)r, 'lowerBound': %(val)r, " - "'unit': '1', 'upperBound': %(val)r}" % {'val': 0.044405586}) + '{\n' + ' "amount": %(val)r, \n' + ' "lowerBound": %(val)r, \n' + ' "unit": "1", \n' + ' "upperBound": %(val)r\n' + '}' % {'val': 0.044405586}) self.assertEqual("%r" % q, "WbQuantity(amount=%(val)s, " "upperBound=%(val)s, lowerBound=%(val)s, "
pywikibot-commits@lists.wikimedia.org