jenkins-bot has submitted this change and it was merged. Change subject: [FIX] logentries test in general ......................................................................
[FIX] logentries test in general It fixes a bug that it didn't actually used the TestCaseMetaClass so that 'self.site' and 'self.sites' weren't initialized. It also incorporates a generic class to get one logentry instead of having a module wide function. And it uses a more specific docstring in the deprecation tests. Change-Id: I6d68c1cd4d1e7e474ee17255fc60fe0913987164 --- M tests/logentry_tests.py 1 file changed, 25 insertions(+), 26 deletions(-) Approvals: John Vandenberg: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py index afa49e5..5c750e5 100644 --- a/tests/logentry_tests.py +++ b/tests/logentry_tests.py @@ -24,9 +24,16 @@ unicode = str -def get_logentry(site, logtype): - """Global method to retriev a single log entry.""" - return next(iter(site.logevents(logtype=logtype, total=1))) +class TestLogentriesBase(TestCase): + + """Base class for log entry tests.""" + + family = 'wikipedia' + code = 'de' + + def _get_logentry(self, logtype): + """Retrieve a single log entry.""" + return next(iter(self.site.logevents(logtype=logtype, total=1))) class TestLogentriesMeta(MetaTestCaseClass): @@ -35,13 +42,11 @@ def __new__(cls, name, bases, dct): """Create the new class.""" - cls.site = pywikibot.Site('de', 'wikipedia') - def test_method(logtype): def test_logevent(self): """Test a single logtype entry.""" - logentry = get_logentry(cls.site, logtype) + logentry = self._get_logentry(logtype) self.assertEqual(logtype, logentry._expectedType) self.assertIsInstance(logentry.action(), unicode) self.assertIsInstance(logentry.comment(), unicode) @@ -63,27 +68,24 @@ test_name = str('test_%sEntry' % logtype.title()) dct[test_name] = test_method(logtype) - return super(MetaTestCaseClass, cls).__new__(cls, name, bases, dct) + return super(TestLogentriesMeta, cls).__new__(cls, name, bases, dct) @add_metaclass -class TestLogentries(TestCase): +class TestLogentries(TestLogentriesBase): - """Test TestLogentries processed by unittest.""" + """Test general LogEntry properties.""" __metaclass__ = TestLogentriesMeta -class TestLogentryParams(TestCase): +class TestLogentryParams(TestLogentriesBase): - """Test Logentry params.""" - - family = 'wikipedia' - code = 'de' + """Test LogEntry properties specific to their action.""" def test_BlockEntry(self): """Test BlockEntry methods.""" - logentry = get_logentry(self.site, 'block') + logentry = self._get_logentry('block') if logentry.action() == 'block': self.assertIsInstance(logentry.flags(), list) if logentry.expiry() is not None: @@ -91,14 +93,14 @@ self.assertIsInstance(logentry.duration(), datetime.timedelta) def test_RightsEntry(self): - """Test MoveEntry methods.""" - logentry = get_logentry(self.site, 'rights') + """Test RightsEntry methods.""" + logentry = self._get_logentry('rights') self.assertIsInstance(logentry.oldgroups, list) self.assertIsInstance(logentry.newgroups, list) def test_MoveEntry(self): """Test MoveEntry methods.""" - logentry = get_logentry(self.site, 'move') + logentry = self._get_logentry('move') self.assertIsInstance(logentry.target_ns, pywikibot.site.Namespace) self.assertEqual(logentry.target_page.namespace(), logentry.target_ns.id) @@ -107,23 +109,20 @@ self.assertIsInstance(logentry.suppressedredirect(), bool) def test_PatrolEntry(self): - """Test MoveEntry methods.""" - logentry = get_logentry(self.site, 'patrol') + """Test PatrolEntry methods.""" + logentry = self._get_logentry('patrol') self.assertIsInstance(logentry.current_id, int) self.assertIsInstance(logentry.previous_id, int) self.assertIsInstance(logentry.auto, bool) -class TestDeprecatedMethods(DeprecationTestCase): +class TestDeprecatedMethods(TestLogentriesBase, DeprecationTestCase): """Test cases for deprecated logentry methods.""" - family = 'wikipedia' - code = 'de' - def test_MoveEntry(self): - """Test MoveEntry methods.""" - logentry = get_logentry(self.site, 'move') + """Test deprecated MoveEntry methods.""" + logentry = self._get_logentry('move') self.assertIsInstance(logentry.new_ns(), int) self.assertEqual(logentry.new_title(), logentry.target_page) -- To view, visit https://gerrit.wikimedia.org/r/214903 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6d68c1cd4d1e7e474ee17255fc60fe0913987164 Gerrit-PatchSet: 4 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