jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] tests: Assert number of deprecations ......................................................................
[IMPROV] tests: Assert number of deprecations
To allow only the expected deprecation also assert how many deprecations have been issued.
Change-Id: Ib12d6f757cf843b4b19dc0584138dab11c97c42c --- M tests/aspects.py M tests/exceptions_tests.py M tests/logentry_tests.py M tests/site_tests.py M tests/tools_ip_tests.py 5 files changed, 17 insertions(+), 16 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py index a0209c8..0ab8a13 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -1363,12 +1363,15 @@ if self._do_test_warning_filename: self.assertDeprecationFile(self.expect_warning_filename)
- def assertOneDeprecation(self, msg=None, reset=True): - """Assert that exactly one deprecation happened and reset if wished.""" - self.assertEqual(len(self.deprecation_messages), 1) + def assertOneDeprecation(self, msg=None, count=1): + """Assert that exactly one deprecation message happened and reset.""" self.assertDeprecation(msg) - if reset: - self._reset_messages() + # This is doing such a weird structure, so that it shows any other + # deprecation message from the set. + self.assertCountEqual(set(self.deprecation_messages), + [self.deprecation_messages[0]]) + self.assertEqual(len(self.deprecation_messages), count) + self._reset_messages()
def assertNoDeprecation(self, msg=None): """Assert that no deprecation warning happened.""" diff --git a/tests/exceptions_tests.py b/tests/exceptions_tests.py index 9fa8041..eed0a08 100644 --- a/tests/exceptions_tests.py +++ b/tests/exceptions_tests.py @@ -47,11 +47,9 @@ def test_PageNotFound(self): """Test PageNotFound is deprecated from the package.""" cls = pywikibot.PageNotFound - self.assertDeprecation( + self.assertOneDeprecation( 'pywikibot.PageNotFound is deprecated, and no longer ' 'used by pywikibot; use http.fetch() instead.') - - self._reset_messages()
e = cls('foo') self.assertIsInstance(e, pywikibot.Error) @@ -62,11 +60,9 @@
cls = pywikibot.exceptions.PageNotFound
- self.assertDeprecation( + self.assertOneDeprecation( 'pywikibot.exceptions.PageNotFound is deprecated, and no longer ' 'used by pywikibot; use http.fetch() instead.') - - self._reset_messages()
e = cls('foo') self.assertIsInstance(e, pywikibot.Error) diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py index 0678510..e81a173 100644 --- a/tests/logentry_tests.py +++ b/tests/logentry_tests.py @@ -236,9 +236,10 @@ if 'title' in logentry.data: # title may be missing self.assertIsInstance(logentry.title(), pywikibot.Page) self.assertIs(logentry.title(), logentry.page()) + self.assertOneDeprecation(count=2) else: self.assertRaises(KeyError, logentry.title) - self.assertDeprecation() + self.assertOneDeprecation() self._reset_messages()
def test_getMovedTarget(self, key): diff --git a/tests/site_tests.py b/tests/site_tests.py index 89bc964..f8705bc 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -78,12 +78,12 @@ self.assertIsInstance(ver, tuple) self.assertTrue(all(isinstance(ver[i], int) for i in (0, 1))) self.assertIsInstance(ver[2], basestring) - self.assertDeprecation() + self.assertOneDeprecation()
def test_getcurrenttime(self): """Test live_version.""" self.assertEqual(self.site.getcurrenttime(), self.site.server_time()) - self.assertDeprecation() + self.assertOneDeprecation()
def test_siteinfo_normal_call(self): """Test calling the Siteinfo without setting dump.""" @@ -115,13 +115,13 @@ """Test that filterredir set to 'only' is deprecated to True.""" for page in self.site.allpages(filterredir='only', total=1): self.assertTrue(page.isRedirectPage()) - self.assertDeprecation() + self.assertOneDeprecation()
def test_allpages_filterredir_False(self): """Test that if filterredir's bool is False it's deprecated to False.""" for page in self.site.allpages(filterredir='', total=1): self.assertFalse(page.isRedirectPage()) - self.assertDeprecation() + self.assertOneDeprecation()
def test_ns_index(self): """Test ns_index.""" diff --git a/tests/tools_ip_tests.py b/tests/tools_ip_tests.py index 80cd776..6e9c46f 100644 --- a/tests/tools_ip_tests.py +++ b/tests/tools_ip_tests.py @@ -652,6 +652,7 @@ self.assertEqual(self.fail, 0) self.assertDeprecation( 'page.ip_regexp is deprecated, use tools.ip.is_IP instead.') + self.assertEqual(self.total, len(self.deprecation_messages))
class IPAddressModuleTestCase(TestIPBase):