jenkins-bot merged this change.

View Change

Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
[cleanup] use subTest with tools_ip_tests.py

- replace hardcoded continuing test capability with subTest
- keep the test result message for Python 2
- keep the total subtest counter
- remove the failing test counter, this is done by subTest in Python 3

Change-Id: I934087e255148a605279bd75d4867155f8e5fa55
---
M tests/tools_ip_tests.py
1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/tests/tools_ip_tests.py b/tests/tools_ip_tests.py
index bc2a4d8..2585091 100644
--- a/tests/tools_ip_tests.py
+++ b/tests/tools_ip_tests.py
@@ -9,7 +9,7 @@

from distutils.version import StrictVersion

-from pywikibot.tools import ip
+from pywikibot.tools import ip, PY2

from tests import unittest_print
from tests.aspects import unittest, TestCase, DeprecationTestCase
@@ -25,30 +25,23 @@
def setUp(self):
"""Set up test."""
self.total = 0
- self.fail = 0
- self.errors = []
super(TestIPBase, self).setUp()

def tearDown(self):
"""Tear down test."""
super(TestIPBase, self).tearDown()
- if not self.fail:
- unittest_print('{0} tests done'.format(self.total))
- else:
- unittest_print(
- '{0} of {1} tests failed:\n{2}'.format(
- self.fail, self.total, '\n'.join(self.errors)))
+ unittest_print('{} subtests done'.format(self.total))

def ipv6test(self, result, ip_address):
"""Perform one ip_address test."""
self.total += 1
- try:
- self.assertEqual(result, self._do_ip_test(ip_address))
- except AssertionError:
- self.fail += 1
- self.errors.append(
- '"{}" match should be {} - not OK'
- .format(ip_address, result))
+ with self.subTest(ip_address=ip_address):
+ msg = '"{}" match should be {} - not OK'.format(
+ ip_address, result) if PY2 else None
+ if result:
+ self.assertTrue(self._do_ip_test(ip_address), msg)
+ else:
+ self.assertFalse(self._do_ip_test(ip_address), msg)

def _run_tests(self):
"""Test various IP."""
@@ -674,7 +667,6 @@
self._run_tests()
self._test_T76286_failures()
self._test_T105443_failures()
- self.assertEqual(self.fail, 0)
self.assertDeprecationParts('page.ip_regexp', 'tools.ip.is_IP')
self.assertLength(self.deprecation_messages, self.total)

@@ -696,23 +688,19 @@

def test_ipaddress_module(self):
"""Test ipaddress module."""
- unittest_print('testing {0}'.format(ip.ip_address.__module__))
self._run_tests()
- self.assertEqual(self.fail, 0)

@expected_failure_if(ip.ip_address.__module__ == 'ipaddress'
or ip.ip_address.__name__ == 'ip_address_patched')
def test_T76286_failures(self):
"""Test known bugs in the ipaddress module."""
self._test_T76286_failures()
- self.assertEqual(self.fail, 0)

@expected_failure_if(ip.ip_address.__module__ == 'ipaddr'
and ip._ipaddr_version == StrictVersion('2.1.10'))
def test_T105443_failures(self):
"""Test known bugs in the ipaddr module."""
self._test_T105443_failures()
- self.assertEqual(self.fail, 0)


if __name__ == '__main__': # pragma: no cover

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I934087e255148a605279bd75d4867155f8e5fa55
Gerrit-Change-Number: 512132
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)