jenkins-bot has submitted this change and it was merged. Change subject: [FEAT] logentry tests: Also test simple classes ......................................................................
[FEAT] logentry tests: Also test simple classes Test the LogEntry classes created without a subclass. Change-Id: I4adbbe02bbe14e760f657a514d28973742e909a8 --- M tests/logentry_tests.py 1 file changed, 50 insertions(+), 22 deletions(-) Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py index 17bc02e..20820c9 100644 --- a/tests/logentry_tests.py +++ b/tests/logentry_tests.py @@ -61,6 +61,31 @@ MediaWikiVersion('1.20')) return next(iter(self.site.logevents(logtype=logtype, total=1))) + def _test_logevent(self, logtype): + """Test a single logtype entry.""" + logentry = self._get_logentry(logtype) + if logtype in LogEntryFactory._logtypes: + self.assertEqual(logentry._expectedType, logtype) + else: + self.assertIsNone(logentry._expectedType) + if self.site_key == 'old': + self.assertNotIn('params', logentry.data) + else: + self.assertNotIn(logentry.type(), logentry.data) + self.assertIsInstance(logentry.action(), unicode) + self.assertIsInstance(logentry.comment(), unicode) + self.assertIsInstance(logentry.logid(), int) + self.assertIsInstance(logentry.ns(), int) + self.assertIsInstance(logentry.pageid(), int) + self.assertIsInstance(logentry.timestamp(), pywikibot.Timestamp) + if 'title' in logentry.data: # title may be missing + self.assertIsInstance(logentry.title(), pywikibot.Page) + self.assertEqual(logentry.type(), logtype) + self.assertIsInstance(logentry.user(), unicode) + self.assertGreaterEqual(logentry.logid(), 0) + self.assertGreaterEqual(logentry.ns(), -2) + self.assertGreaterEqual(logentry.pageid(), 0) + class TestLogentriesMeta(MetaTestCaseClass): @@ -69,31 +94,12 @@ def __new__(cls, name, bases, dct): """Create the new class.""" def test_method(logtype): - def test_logevent(self, key): - """Test a single logtype entry.""" - logentry = self._get_logentry(logtype) - self.assertEqual(logtype, logentry._expectedType) - if key == 'old': - self.assertNotIn('params', logentry.data) - else: - self.assertNotIn(logentry.type(), logentry.data) - self.assertIsInstance(logentry.action(), unicode) - self.assertIsInstance(logentry.comment(), unicode) - self.assertIsInstance(logentry.logid(), int) - self.assertIsInstance(logentry.ns(), int) - self.assertIsInstance(logentry.pageid(), int) - self.assertIsInstance(logentry.timestamp(), pywikibot.Timestamp) - if 'title' in logentry.data: # title may be missing - self.assertIsInstance(logentry.title(), pywikibot.Page) - self.assertEqual(logentry.type(), logtype) - self.assertIsInstance(logentry.user(), unicode) - self.assertGreaterEqual(logentry.logid(), 0) - self.assertGreaterEqual(logentry.ns(), -2) - self.assertGreaterEqual(logentry.pageid(), 0) + self._test_logevent(logtype) + return test_logevent - # create test methods for package messages processed by unittest + # create test methods for the support logtype classes for logtype in LogEntryFactory._logtypes: test_name = str('test_%sEntry' % logtype.title()) dct[test_name] = test_method(logtype) @@ -109,6 +115,28 @@ __metaclass__ = TestLogentriesMeta +class TestSimpleLogentries(TestLogentriesBase): + + """Test logentry classes without special classes.""" + + def test_simple_entries(self, key): + """Test those entries which don't have an extra LogEntry subclass.""" + # Unfortunately it's not possible to use the metaclass to create a + # bunch of test methods for this too as the site instances haven't been + # initialized yet. + available_types = set(self.site._paraminfo.parameter( + 'query+logevents', 'type')['type']) + for simple_type in available_types - set(LogEntryFactory._logtypes): + if not simple_type: + # paraminfo also reports an empty string as a type + continue + try: + self._test_logevent(simple_type) + except StopIteration: + print('Unable to test "{0}" on "{1}" because there are no log ' + 'entries with that type.'.format(simple_type, key)) + + class TestLogentryParams(TestLogentriesBase): """Test LogEntry properties specific to their action.""" -- To view, visit https://gerrit.wikimedia.org/r/215015 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4adbbe02bbe14e760f657a514d28973742e909a8 Gerrit-PatchSet: 3 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits