XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/231752
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(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/52/231752/1
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)
--
To view, visit https://gerrit.wikimedia.org/r/231752
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie45b1fa024a43f65a9ec8028f2ee194f7a96c470
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits