jenkins-bot has submitted this change and it was merged.
Change subject: Revert "Revert "[FIX] ParamInfo: Correctly initialize ParamInfo"" ......................................................................
Revert "Revert "[FIX] ParamInfo: Correctly initialize ParamInfo""
This reverts commit e184e8556d29b9a4e69fafb3694db617a5b84ba4.
Change-Id: Ie45b1fa024a43f65a9ec8028f2ee194f7a96c470 --- M pywikibot/data/api.py M tests/api_tests.py 2 files changed, 29 insertions(+), 7 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index c50e46d..a7b7f6d 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -551,13 +551,15 @@ # query modules can be prefixed with 'query+' self._init()
- if 'query' in self._modules: - # It does fetch() while initializing, and this method can't be - # called before it's initialized. - modules = self._normalize_modules(modules) - elif self._action_modules: - # At least we do know the valid action modules and require a subset - assert not modules - self._action_modules - self.root_modules + if self._action_modules: + # The query module may be added before the action modules have been + if 'query' in self._modules: + # It does fetch() while initializing, and this method can't be + # called before it's initialized. + modules = self._normalize_modules(modules) + else: + # At least we do know the valid action modules and require a subset + assert not modules - self._action_modules - self.root_modules
self._fetch(modules)
diff --git a/tests/api_tests.py b/tests/api_tests.py index 213cf3b..2a76405 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -163,6 +163,26 @@ self.assertIn('info', pi.query_modules) self.assertIn('login', pi._action_modules)
+ def test_init_query_first(self): + """Test init where it first adds query and then main.""" + def patched_generate_submodules(modules): + # Change the query such that query is handled before main + modules = set(modules) + if 'main' in modules: + assert 'query' in modules + modules.discard('main') + modules = list(modules) + ['main'] + else: + assert 'query' not in modules + original_generate_submodules(modules) + pi = api.ParamInfo(self.site, set(['query', 'main'])) + self.assertEqual(len(pi), 0) + original_generate_submodules = pi._generate_submodules + pi._generate_submodules = patched_generate_submodules + pi._init() + self.assertIn('main', pi._paraminfo) + self.assertIn('query', pi._paraminfo) + def test_init_pageset(self): site = self.get_site() self.assertNotIn('query', api.ParamInfo.init_modules)
pywikibot-commits@lists.wikimedia.org