XZise has submitted this change and it was merged.

Change subject: Fix doctests and enable in jenkins nosetests
......................................................................


Fix doctests and enable in jenkins nosetests

Doctests in these files all failed.
- threadedhttp: incomplete test case
- api: used 'site=mysite' without declaring mysite
- i18n: used a message name which didnt exist, and included a wrong
  response
- tools: used print foo instead of print(foo); used xrange

Also fix api main(), which imported 'logging' from pywikibot, which
is no longer supported.

Bug: 72227
Change-Id: Ie92671e746cc10dab769d0ec4116d0ef0961c41e
---
M pywikibot/comms/threadedhttp.py
M pywikibot/data/api.py
M pywikibot/i18n.py
M pywikibot/tools.py
M tox.ini
5 files changed, 70 insertions(+), 43 deletions(-)

Approvals:
  XZise: Looks good to me, approved



diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index 7d0b632..c63daa4 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -301,15 +301,28 @@
 
     Usage:
 
-    >>> import Queue
+    >>> from .http import Queue
     >>> queue = Queue.Queue()
-    >>> request = HttpRequest('https://www.google.com')
+    >>> cookiejar = LockableCookieJar()
+    >>> connection_pool = ConnectionPool()
+    >>> proc = HttpProcessor(queue, cookiejar, connection_pool)
+    >>> proc.setDaemon(True)
+    >>> proc.start()
+    >>> request = HttpRequest('https://hostname.invalid/')
     >>> queue.put(request)
     >>> request.lock.acquire()
-    >>> print request.data
+    True
+    >>> print(type(request.data))
+    <class 'httplib2.ServerNotFoundError'>
+    >>> print(request.data)
+    Unable to find the server at hostname.invalid
 
     C{request.lock.acquire()} will block until the data is available.
 
+    self.data will be either:
+    * a tuple of (dict, unicode) if the request was successful
+    * an exception
+
     """
     def __init__(self, *args, **kwargs):
         """
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index fff6959..2410fef 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -175,7 +175,7 @@
 
     Example:
 
-    >>> r = Request(site=mysite, action="query", meta="userinfo")
+    >>> r = Request(action="query", meta="userinfo")
     >>> # This is equivalent to
     >>> # https://{path}/api.php?action=query&meta=userinfo&format=json
     >>> # change a parameter
@@ -183,15 +183,23 @@
     >>> # add a new parameter
     >>> r['siprop'] = "namespaces"
     >>> # note that "uiprop" param gets added automatically
-    >>> r._params
-    {'action': [u'query'], 'meta': [u'userinfo', u'siteinfo'], 'siprop': 
[u'namespaces']}
-    >>> data = r.submit()
-    >>> type(data)
-    <type 'dict'>
-    >>> data.keys()
+    >>> r.action  # doctest: +IGNORE_UNICODE
+    u'query'
+    >>> sorted(r._params.keys())  # doctest: +IGNORE_UNICODE
+    [u'action', u'meta', u'siprop']
+    >>> r._params['action']  # doctest: +IGNORE_UNICODE
     [u'query']
-    >>> data[u'query'].keys()
-    [u'userinfo', u'namespaces']
+    >>> r._params['meta']  # doctest: +IGNORE_UNICODE
+    [u'userinfo', u'siteinfo']
+    >>> r._params['siprop']  # doctest: +IGNORE_UNICODE
+    [u'namespaces']
+    >>> data = r.submit()  # doctest: +IGNORE_UNICODE
+    >>> isinstance(data, dict)
+    True
+    >>> sorted(data.keys())  # doctest: +IGNORE_UNICODE
+    ['query']
+    >>> sorted(data[u'query'].keys())  # doctest: +IGNORE_UNICODE
+    ['namespaces', 'userinfo']
 
     @param site: The Site to which the request will be submitted. If not
            supplied, uses the user's configured default Site.
@@ -1425,7 +1433,8 @@
 
 
 if __name__ == "__main__":
-    from pywikibot import Site, logging
+    import logging
+    from pywikibot import Site
     logging.getLogger("pywiki.data.api").setLevel(logging.DEBUG)
     mysite = Site("en", "wikipedia")
     pywikibot.output(u"starting test....")
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 33ad626..180b9f4 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -420,33 +420,35 @@
     msg = {
         'en': {
             # number value as format sting is allowed
-            'test-changing': u'Bot: Changing %(num)s 
{{PLURAL:%(num)d|page|pages}}.',
+            'test-plural': u'Bot: Changing %(num)s 
{{PLURAL:%(num)d|page|pages}}.',
         },
         'nl': {
             # format sting inside PLURAL tag is allowed
-            'test-changing': u'Bot: Pas {{PLURAL:num|1 pagina|%(num)d 
pagina\'s}} aan.',
+            'test-plural': u'Bot: Pas {{PLURAL:num|1 pagina|%(num)d 
pagina\'s}} aan.',
         },
         'fr': {
             # additional sting inside or outside PLURAL tag is allowed
-            'test-changing': u'Robot: Changer %(descr)s {{PLURAL:num|une 
page|quelques pages}}.',
+            'test-plural': u'Robot: Changer %(descr)s {{PLURAL:num|une 
page|quelques pages}}.',
         },
     }
-    #use a number
     >>> from pywikibot import i18n
-    >>> i18n.twntranslate('en', 'test-changing', 0) % {'num': 'no'}
-    Bot: Changing no pages.
-    #use a string
-    >>> i18n.twntranslate('en', 'test-changing', '1') % {'num': 'one'}
-    Bot: Changing one page.
-    #use a dictionary
-    >>> i18n.twntranslate('en', 'test-changing', {'num':2})
-    Bot: Changing 2 pages.
-    #use additional format strings
-    >>> i18n.twntranslate('fr', 'test-changing', {'num': 1, 'descr': 
'seulement'})
-    Robot: Changer seulement une pages.
-    #use format strings also outside
-    >>> i18n.twntranslate('fr', 'test-changing', 10) % {'descr': 'seulement'}
-    Robot: Changer seulement quelques pages.
+    >>> i18n.messages_package_name = 'tests.i18n'
+    >>> # use a number
+    >>> str(i18n.twntranslate('en', 'test-plural', 0) % {'num': 'no'})
+    'Bot: Changing no pages.'
+    >>> # use a string
+    >>> str(i18n.twntranslate('en', 'test-plural', '1') % {'num': 'one'})
+    'Bot: Changing one page.'
+    >>> # use a dictionary
+    >>> str(i18n.twntranslate('en', 'test-plural', {'num':2}))
+    'Bot: Changing 2 pages.'
+    >>> # use additional format strings
+    >>> str(i18n.twntranslate('fr', 'test-plural', {'num': 1, 'descr': 
'seulement'}))
+    'Robot: Changer seulement une page.'
+    >>> # use format strings also outside
+    >>> str(i18n.twntranslate('fr', 'test-plural', 10) % {'descr': 
'seulement'})
+    'Robot: Changer seulement quelques pages.'
+    >>> i18n.messages_package_name = 'scripts.i18n'
 
     The translations are retrieved from i18n.<package>, based on the callers
     import table.
diff --git a/pywikibot/tools.py b/pywikibot/tools.py
index e7c0bec..6064d86 100644
--- a/pywikibot/tools.py
+++ b/pywikibot/tools.py
@@ -142,13 +142,13 @@
     all the generated values, it must call the generator's stop() method to
     stop the background thread.  Example usage:
 
-    >>> gen = ThreadedGenerator(target=xrange, args=(20,))
+    >>> gen = ThreadedGenerator(target=range, args=(20,))
     >>> try:
     ...     for data in gen:
-    ...         print data,
+    ...         print(data, end=',')
     ... finally:
     ...     gen.stop()
-    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
+    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
 
     """
 
@@ -217,14 +217,14 @@
 
     Example:
 
-    >>> i = itergroup(xrange(25), 10)
-    >>> print next(i)
+    >>> i = itergroup(range(25), 10)
+    >>> print(next(i))
     [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-    >>> print next(i)
+    >>> print(next(i))
     [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
-    >>> print next(i)
+    >>> print(next(i))
     [20, 21, 22, 23, 24]
-    >>> print next(i)
+    >>> print(next(i))
     Traceback (most recent call last):
      ...
     StopIteration
@@ -253,7 +253,7 @@
     >>> def work():
     ...     time.sleep(1)
     ...
-    >>> for x in xrange(20):
+    >>> for x in range(20):
     ...     pool.append(threading.Thread(target=work))
     ...
 
diff --git a/tox.ini b/tox.ini
index f722b37..6ee3910 100644
--- a/tox.ini
+++ b/tox.ini
@@ -72,15 +72,18 @@
 
 [testenv:nose]
 setenv = PYWIKIBOT2_NO_USER_CONFIG=1
-commands = nosetests -v -a "!site,!net" tests
-deps = nose
+commands = nosetests --with-doctest --with-doctest-ignore-unicode -v -a 
"!site,!net" tests pywikibot --ignore-files=gui.py --ignore-files=botirc.py
+deps =
+    nose
+    doctest-ignore-unicode
 
 [testenv:nose34]
 basepython = python3
 setenv = PYWIKIBOT2_NO_USER_CONFIG=1
-commands = nosetests -v -a "!site,!net" tests
+commands = nosetests --with-doctest --with-doctest-ignore-unicode -v -a 
"!site,!net" tests pywikibot --ignore-files=gui.py --ignore-files=botirc.py
 deps =
     nose
+    doctest-ignore-unicode
     six
 
 [testenv:venv]

-- 
To view, visit https://gerrit.wikimedia.org/r/167434
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie92671e746cc10dab769d0ec4116d0ef0961c41e
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to