jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Improvement for test_tests

- Add UtilsTests to test fixed_generator and entered_loop
- Explain the HttpServerProblemTestCase
- Explain expected_failure of TestLengthAssertion
- Add documentation to fixed_generator

Change-Id: Ie7481ac3a05e945105806fbc793077fc785fa9c5
---
M tests/tests_tests.py
M tests/utils.py
2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/tests/tests_tests.py b/tests/tests_tests.py
index e69df36..47c1974 100755
--- a/tests/tests_tests.py
+++ b/tests/tests_tests.py
@@ -8,6 +8,7 @@
from contextlib import suppress

from tests.aspects import TestCase
+from tests import utils


class HttpServerProblemTestCase(TestCase):
@@ -21,13 +22,18 @@
}

def test_502(self):
- """Test a HTTP 502 response using http://httpbin.org/status/502."""
- self.fail('The test framework should skip this test.')
+ """Test that framework is skipping this test due to HTTP status 502."""
+ self.fail("The test framework should skip this test but it hasn't.")


-class TestLengthAssert(TestCase):
+class TestLengthAssertion(TestCase):

- """Test length assertion methods."""
+ """Test length assertion methods.
+
+ ``@unittest.expectedFailure`` is used to test the failure of a test;
+ this is intentional. If the decorated test passes unexpectedly the
+ test will fail.
+ """

net = False

@@ -70,6 +76,24 @@
self.assertLength(None, self.seq)


+class UtilsTests(TestCase):
+
+ """Tests for tests.utils."""
+
+ net = False
+ pattern = 'Hello World'
+
+ def test_fixed_generator(self):
+ """Test utils.fixed_generator."""
+ gen = utils.fixed_generator(self.pattern)
+ self.assertEqual(list(gen(1, 'foo', bar='baz')), list(self.pattern))
+
+ def test_entered_loop(self):
+ """Test utils.entered_loop."""
+ self.assertTrue(utils.entered_loop(self.pattern))
+ self.assertFalse(utils.entered_loop(''))
+
+
if __name__ == '__main__': # pragma: no cover
with suppress(SystemExit):
unittest.main()
diff --git a/tests/utils.py b/tests/utils.py
index 536adcb..9b8b815 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -42,7 +42,23 @@


def fixed_generator(iterable):
- """Return a dummy generator ignoring all parameters."""
+ """Return a dummy generator ignoring all parameters.
+
+ This can be used to overwrite a generator method and yield
+ predefined items:
+
+ >>> from tests.utils import fixed_generator
+ >>> site = pywikibot.Site()
+ >>> page = pywikibot.Page(site, 'Any page')
+ >>> list(page.linkedPages(total=1))
+ []
+ >>> gen = fixed_generator([
+ ... pywikibot.Page(site, 'User:BobBot/Redir'),
+ ... pywikibot.Page(site, 'Main Page')])
+ >>> page.linkedPages = gen
+ >>> list(page.linkedPages(total=1))
+ [Page('Benutzer:BobBot/Redir'), Page('Main Page')]
+ """
def gen(*args, **kwargs):
yield from iterable


To view, visit change 832276. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie7481ac3a05e945105806fbc793077fc785fa9c5
Gerrit-Change-Number: 832276
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged