jenkins-bot has submitted this change and it was merged. Change subject: Add async_request test ......................................................................
Add async_request test Use Queue.mark_done so that tests can use Queue.join. Bug: T98439 Change-Id: I8e80d26e8a8a09cddbf26b47c27ffb61a8b0d7e4 --- M pywikibot/__init__.py M tests/api_tests.py A tests/edit_tests.py M tests/site_tests.py M tox.ini 5 files changed, 78 insertions(+), 0 deletions(-) Approvals: XZise: Looks good to me, approved VcamX: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 615589e..ea8304a 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -721,6 +721,7 @@ if request is None: break request(*args, **kwargs) + page_put_queue.task_done() def async_request(request, *args, **kwargs): diff --git a/tests/api_tests.py b/tests/api_tests.py index 46319f1..dde46f5 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -16,6 +16,7 @@ import pywikibot.family import pywikibot.login import pywikibot.site + from pywikibot.tools import MediaWikiVersion from tests.aspects import ( diff --git a/tests/edit_tests.py b/tests/edit_tests.py new file mode 100644 index 0000000..7a99297 --- /dev/null +++ b/tests/edit_tests.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +"""Tests for editing pages.""" +# +# (C) Pywikibot team, 2015 +# +# Distributed under the terms of the MIT license. +# +from __future__ import unicode_literals + +__version__ = '$Id$' +# + +import time + +import pywikibot + +from pywikibot import page_put_queue + +from tests.aspects import unittest, TestCase + +called_back = False + + +class TestGeneralWrite(TestCase): + + """Run general write tests.""" + + family = 'test' + code = 'test' + + user = True + write = True + + def test_async(self): + """Test writing to a page.""" + global called_back + + def callback(page, err): + global called_back + self.assertEqual(page, p) + self.assertIsNone(err) + called_back = True + + self.assertTrue(page_put_queue.empty()) + called_back = False + ts = str(time.time()) + p = pywikibot.Page(self.site, 'User:John Vandenberg/async test write') + p.text = ts + p.save(async=True, callback=callback) + + page_put_queue.join() + + p = pywikibot.Page(self.site, 'User:John Vandenberg/async test write') + self.assertEqual(p.text, ts) + self.assertTrue(called_back) + +if __name__ == '__main__': + try: + unittest.main() + except SystemExit: + pass diff --git a/tests/site_tests.py b/tests/site_tests.py index 0810f95..d9bd295 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -17,7 +17,9 @@ import re import pywikibot + from pywikibot import config +from pywikibot import async_request, page_put_queue from pywikibot.comms import http from pywikibot.tools import MediaWikiVersion from pywikibot.data import api @@ -1637,6 +1639,18 @@ self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).keys())) +class TestSiteinfoAsync(DefaultSiteTestCase): + + """Test asynchronous siteinfo fetch.""" + + def test_async_request(self): + self.assertTrue(page_put_queue.empty()) + self.assertTrue('statistics' not in self.site.siteinfo) + async_request(self.site.siteinfo.get, 'statistics') + page_put_queue.join() + self.assertIn('statistics', self.site.siteinfo) + + class TestSiteLoadRevisions(TestCase): """Test cases for Site.loadrevision() method.""" diff --git a/tox.ini b/tox.ini index 67e1655..cb3ca7e 100644 --- a/tox.ini +++ b/tox.ini @@ -111,6 +111,7 @@ tests/cache_tests.py \ tests/cosmetic_changes_tests.py \ tests/date_tests.py \ + tests/edit_tests.py \ tests/edit_failure_tests.py \ tests/exceptions_tests.py \ tests/family_tests.py \ -- To view, visit https://gerrit.wikimedia.org/r/215302 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8e80d26e8a8a09cddbf26b47c27ffb61a8b0d7e4 Gerrit-PatchSet: 3 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: VcamX <vca...@gmail.com> Gerrit-Reviewer: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits