John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/146042

Change subject: Log test start and end, and result
......................................................................

Log test start and end, and result

Add debug log messages for the start and end of each unit test.

Also add PywikibotTestCase.data_filepath so that XmlReaderTestCase
does not need its own setUpClass method.

And fix a few pep8/257 issues.

Change-Id: I701dfa1fbdb21982664c537346986da5f57f6ccd
---
M tests/site_tests.py
M tests/textlib_tests.py
M tests/utils.py
M tests/xmlreader_tests.py
4 files changed, 43 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/42/146042/1

diff --git a/tests/site_tests.py b/tests/site_tests.py
index d70d397..f995d43 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -34,6 +34,7 @@
         mysite = pywikibot.Site(cls.code, cls.family)
         mainpage = pywikibot.Page(pywikibot.Link("Main Page", mysite))
         imagepage = next(iter(mainpage.imagelinks()))  # 1st image on main page
+        super(TestSiteObject, cls).setUpClass()
 
     def testBaseMethods(self):
         """Test cases for BaseSite methods"""
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index ba7da8e..30e78b6 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -97,6 +97,7 @@
         cls.site = pywikibot.Site('en', 'wikipedia')
         cls.catresult = ('[[Category:Cat1]]%(LS)s[[Category:Cat2]]%(LS)s'
                           % {'LS': config.LS})
+        super(TestFormatFunctions, cls).setUpClass()
 
     def test_interwiki_format(self):
         interwikis = {
diff --git a/tests/utils.py b/tests/utils.py
index 9d02bba..da7cb17 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -8,7 +8,9 @@
 __version__ = '$Id$'
 #
 import time
+import os
 import sys
+import inspect
 try:
     # Unittest2 is a backport of python 2.7s unittest module to python 2.6
     # Trying to import unittest2 has to happen first because 2.6 does have a
@@ -33,19 +35,43 @@
     return unittest.loader.defaultTestLoader.discover("tests", "*tests.py")
 
 from tests import patch_request, unpatch_request
+from pywikibot import log
 
 
 class PywikibotTestCase(unittest.TestCase):
+
+    """Super class for pywikibot unit test cases."""
+
+    _tests_dir = os.path.dirname(os.path.abspath(__file__))
+    _data_dir = os.path.join(_tests_dir, 'data')
+
+    def data_filepath(self, filename):
+        """Get the file name of a test data file."""
+        return os.path.join(self._data_dir, filename)
+
+    @classmethod
+    def setUpClass(cls):
+        """Set up the test class."""
+        cls._path = os.path.dirname(os.path.abspath(__file__))
+        cls._log_prefix = inspect.getfile(cls) + ':' + cls.__name__
+
     def assertType(self, obj, cls):
-        """Assert that obj is an instance of type cls"""
+        """Assert that obj is an instance of type cls."""
         return self.assertTrue(isinstance(obj, cls))
 
     def setUp(self):
+        """Set up each unit test."""
         patch_request()
+
+        log('START ' + self._log_prefix + '.' + self._testMethodName)
+
+        self.test_issues = len(self._resultForDoCleanups.failures) + \
+                           len(self._resultForDoCleanups.errors)
 
         self.test_start = time.time()
 
     def tearDown(self):
+        """Tear down each unit test."""
         self.test_completed = time.time()
         duration = self.test_completed - self.test_start
 
@@ -53,4 +79,11 @@
             print(' %0.3fs' % duration, end=' ')
             sys.stdout.flush()
 
+        test_problem = self.test_issues \
+                       != len(self._resultForDoCleanups.failures) + \
+                          len(self._resultForDoCleanups.errors)
+        test_end = ' OK' if test_problem else ' NOT OK'
+
+        log('END ' + self._log_prefix + '.' + self._testMethodName + test_end)
+
         unpatch_request()
diff --git a/tests/xmlreader_tests.py b/tests/xmlreader_tests.py
index e3ac959..c7271a1 100644
--- a/tests/xmlreader_tests.py
+++ b/tests/xmlreader_tests.py
@@ -1,6 +1,8 @@
 # -*- coding: utf-8  -*-
 """
 Tests for xmlreader module.
+
+Uses test data files article-pear.xml and article-pyrus.xml
 """
 #
 # (C) Pywikibot team, 2014
@@ -10,21 +12,15 @@
 __version__ = '$Id$'
 
 
-import os.path
 from pywikibot import xmlreader
 from tests.utils import unittest, PywikibotTestCase
 
 
 class XmlReaderTestCase(PywikibotTestCase):
 
-    @classmethod
-    def setUpClass(cls):
-        cls.path = os.path.dirname(os.path.abspath(__file__))
-
     def test_XmlDumpAllRevs(self):
         pages = [r for r in
-                 xmlreader.XmlDump(os.path.join(self.path, 'data',
-                                                "article-pear.xml"),
+                 xmlreader.XmlDump(self.data_filepath("article-pear.xml"),
                                    allrevisions=True).parse()]
         self.assertEquals(4, len(pages))
         self.assertEquals(u"Automated conversion", pages[0].comment)
@@ -36,8 +32,8 @@
 
     def test_XmlDumpFirstRev(self):
         pages = [r for r in
-                 xmlreader.XmlDump(os.path.join(self.path, 'data',
-                                                "article-pear.xml")).parse()]
+                 xmlreader.XmlDump(self.data_filepath("article-pear.xml"),
+                                   ).parse()]
         self.assertEquals(1, len(pages))
         self.assertEquals(u"Automated conversion", pages[0].comment)
         self.assertEquals(u"Pear", pages[0].title)
@@ -47,8 +43,8 @@
 
     def test_XmlDumpRedirect(self):
         pages = [r for r in
-                 xmlreader.XmlDump(os.path.join(self.path, 'data',
-                                                "article-pyrus.xml")).parse()]
+                 xmlreader.XmlDump(self.data_filepath("article-pyrus.xml"),
+                                   ).parse()]
         self.assertTrue(pages[0].isredirect)
 
 

-- 
To view, visit https://gerrit.wikimedia.org/r/146042
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I701dfa1fbdb21982664c537346986da5f57f6ccd
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to