jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/812872 )
Change subject: [IMPR] Always set uselang=en for parsing parsevalue ......................................................................
[IMPR] Always set uselang=en for parsing parsevalue
Also set defaults for options and validate parameters.
Bug: T312755 Change-Id: I890a83f5b23fb1a40b4ae57701ae8bbfa76e3cbb --- M pywikibot/site/_datasite.py M tests/wikibase_tests.py 2 files changed, 8 insertions(+), 6 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py index 370981d..2966300 100644 --- a/pywikibot/site/_datasite.py +++ b/pywikibot/site/_datasite.py @@ -711,7 +711,8 @@ return gen
def parsevalue(self, datatype: str, values: List[str], - options: Dict[str, Any], validate: bool) -> List[Any]: + options: Optional[Dict[str, Any]] = None, + validate: bool = False) -> List[Any]: """ Send data values to the wikibase parser for interpretation.
@@ -732,8 +733,9 @@ params = { 'datatype': datatype, 'values': values, - 'options': json.dumps(options), + 'options': json.dumps(options or {}), 'validate': validate, + 'uselang': 'en', } req = self.simple_request(action='wbparsevalue', **params) try: diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index 0ebcb854..d0617a8 100755 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -636,13 +636,13 @@ def test_wbparse_strings(self): """Test that strings return unchanged.""" test_list = ['test string', 'second test'] - parsed_strings = self.site.parsevalue('string', test_list, {}, False) + parsed_strings = self.site.parsevalue('string', test_list) self.assertEqual(parsed_strings, test_list)
def test_wbparse_time(self): """Test parsing of a time value.""" parsed_date = self.site.parsevalue( - 'time', ['1994-02-08'], {'precision': 9}, False)[0] + 'time', ['1994-02-08'], {'precision': 9})[0] self.assertEqual(parsed_date['time'], '+1994-02-08T00:00:00Z') self.assertEqual(parsed_date['precision'], 9)
@@ -651,7 +651,7 @@ parsed_quantities = self.site.parsevalue( 'quantity', ['1.90e-9+-0.20e-9', '1000000.00000000054321+-0', '-123+-1', - '2.70e34+-1e32'], {}, False) + '2.70e34+-1e32']) self.assertEqual(parsed_quantities[0]['amount'], '+0.00000000190') self.assertEqual(parsed_quantities[0]['upperBound'], '+0.00000000210') self.assertEqual(parsed_quantities[0]['lowerBound'], '+0.00000000170') @@ -674,7 +674,7 @@ def test_wbparse_raises_valueerror(self): """Test invalid value condition.""" with self.assertRaises(ValueError): - self.site.parsevalue('quantity', ['Not a quantity'], {}, False) + self.site.parsevalue('quantity', ['Not a quantity'])
class TestWbGeoShapeNonDry(WbRepresentationTestCase):
pywikibot-commits@lists.wikimedia.org