jenkins-bot has submitted this change and it was merged.
Change subject: Add fake ParamInfo to DrySite ......................................................................
Add fake ParamInfo to DrySite
The real ParamInfo uses CachedRequest which is not mock-ed under dry tests, due to it having a different __init__ signature.
This meant TestDryPageGenerator and ParamInfoDictTests.test_parameter have been using live paraminfo data.
When there are no API requests, the maintenance script cache.py fails while trying to open the directory tests/apicache.
Change-Id: Ie76a7f3d5fd64767e7ca7eb71445fa67a648430c --- M scripts/maintenance/cache.py M tests/dry_api_tests.py M tests/utils.py 3 files changed, 67 insertions(+), 1 deletion(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py index 0d7ed2e..e9c96ff 100644 --- a/scripts/maintenance/cache.py +++ b/scripts/maintenance/cache.py @@ -195,6 +195,10 @@ if not cache_path: cache_path = os.path.join(pywikibot.config2.base_dir, 'apicache')
+ if not os.path.exists(cache_path): + pywikibot.error('%s: no such file or directory' % cache_path) + return + if os.path.isdir(cache_path): filenames = [os.path.join(cache_path, filename) for filename in os.listdir(cache_path)] diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index 75a384a..eb260c1 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -276,6 +276,12 @@ "querytype": "prop" }
+ def setUp(self): + """Add a real ParamInfo to the DrySite.""" + super(ParamInfoDictTests, self).setUp() + site = self.get_site() + site._paraminfo = ParamInfo(site) + def test_new_format(self): pi = self.get_site()._paraminfo # Set it to the new limited set of keys. @@ -338,6 +344,8 @@ })
pi._paraminfo.update(data) + # Pretend that paraminfo has been loaded + pi._paraminfo['paraminfo'] = {}
param = pi.parameter('info', 'token') self.assertIsInstance(param, dict) diff --git a/tests/utils.py b/tests/utils.py index 06661e0..6698261 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -13,6 +13,8 @@ import sys import time
+from warnings import warn + import pywikibot from pywikibot.tools import SelfCallDict from pywikibot.site import Namespace @@ -27,6 +29,13 @@ SiteTestCase = aspects.TestCase CachedTestCase = aspects.TestCase PywikibotTestCase = aspects.TestCase + + +class DrySiteNote(RuntimeWarning): + + """Information regarding dry site.""" + + pass
def expected_failure_if(expect): @@ -74,6 +83,41 @@ return allowed_failure else: return lambda orig: orig + + +class DryParamInfo(dict): + + """Dummy class to use instead of L{pywikibot.data.api.ParamInfo}.""" + + @property + def modules(self): + """Empty set.""" + return set() + + @property + def action_modules(self): + """Empty set.""" + return set() + + @property + def query_modules(self): + """Empty set.""" + return set() + + @property + def query_modules_with_limits(self): + """Empty set.""" + return set() + + @property + def prefixes(self): + """Empty set.""" + return set() + + def parameter(self, module, param_name): + """Prevented method.""" + raise Exception(u'DryParamInfo.parameter(%r, %r) prevented' + % (module, param_name))
class DummySiteinfo(): @@ -147,16 +191,26 @@ """Constructor.""" super(DrySite, self).__init__(code, fam, user, sysop) self._userinfo = pywikibot.tools.EMPTY_DEFAULT + self._paraminfo = DryParamInfo() self._siteinfo = DummySiteinfo({}) self._siteinfo._cache['lang'] = (code, True) self._namespaces = SelfCallDict(Namespace.builtin_namespaces()) + + def __repr__(self): + """Override default so warnings and errors indicate test is dry.""" + return "%s(%r, %r)" % (self.__class__.__name__, + self.code, + self.family.name)
@property def userinfo(self): return self._userinfo
def version(self): - return self.family.version(self.code) + """Dummy version, with warning to show the callers context.""" + warn('%r returning version 1.24; override if unsuitable.' + % self, DrySiteNote, stacklevel=2) + return '1.24'
def case(self): if self.family.name == 'wiktionary':
pywikibot-commits@lists.wikimedia.org