[Piglit] [PATCH 1/5] framework/log.py: Merge Log.log() and Log.post_log()

Dylan Baker baker.dylan.c at gmail.com
Tue Aug 12 14:34:07 PDT 2014


From: Dylan Baker <baker.dylan.c at gmail.com>

These methods were always called back to back, and required an
overlapping set of arguments. Initially I thought that having a second
method might be useful, but it doesn't really seem that useful at this
point.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/exectest.py        |  6 ++----
 framework/log.py             | 30 +++++++++++++-----------------
 framework/tests/log_tests.py | 37 +++++++++++++++++--------------------
 3 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/framework/exectest.py b/framework/exectest.py
index 90067e4..e325602 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -120,13 +120,11 @@ class Test(object):
                 self.result['traceback'] = "".join(
                     traceback.format_tb(exception[2]))
 
-            log.log(path, self.result['result'])
-            log.post_log(log_current, self.result['result'])
+            log.log(path, self.result['result'], log_current)
 
             json_writer.write_dict_item(path, self.result)
         else:
-            log.log(path, 'dry-run')
-            log.post_log(log_current, 'dry-run')
+            log.log(path, 'dry-run', log_current)
 
     @property
     def command(self):
diff --git a/framework/log.py b/framework/log.py
index d261dbb..97afeb1 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -102,14 +102,21 @@ class Log(object):
                                                    'result': result}))
 
     @synchronized_self
-    def post_log(self, value, result):
-        """ Used to mark a test as complete in the log
+    def log(self, name, result, value):
+        """ Print to the screen
+
+        Works by moving the cursor back to the front of the line and printing
+        over it.
 
         Arguments:
-        value -- the test number to mark complete
-        result -- the result of the completed test
+        name -- the name of the test
+        result -- the result of the test
+        value -- the number of the test to remove
 
         """
+        assert result in self.__summary_keys
+        self.__print(name, result)
+
         # Mark running complete
         assert value in self.__running
         self.__running.remove(value)
@@ -121,27 +128,16 @@ class Log(object):
         self.__summary[result] += 1
 
     @synchronized_self
-    def log(self, name, result):
-        """ Print to the screen 
-
-        Works by moving the cursor back to the front of the line and printing
-        over it.
-
-        """
-        assert result in self.__summary_keys
-        self.__print(name, result)
-
-    @synchronized_self
     def pre_log(self, running=None):
         """ Hook to run before log()
-        
+
         Returns a new number to know what processes are running, if running is
         set it will print a running message for the test
 
         Keyword Arguments:
         running -- the name of a test to print is running. If Falsy then
                    nothing will be printed. Default: None
-        
+
         """
         if running:
             self.__print(running, 'running')
diff --git a/framework/tests/log_tests.py b/framework/tests/log_tests.py
index d2cb336..333ba35 100644
--- a/framework/tests/log_tests.py
+++ b/framework/tests/log_tests.py
@@ -20,8 +20,6 @@
 
 """ Module provides tests for log.py module """
 
-import sys
-import itertools
 from types import *  # This is a special * safe module
 import nose.tools as nt
 from framework.log import Log
@@ -51,21 +49,20 @@ def test_pre_log_return():
                    msg="Log.pre_log() didn't return a numeric type!")
 
 
-def test_post_log_increment_complete():
-    """ Tests that Log.post_log() increments self.__complete """
+def test_log_increment_complete():
+    """ Tests that Log.log() increments self.__complete """
     log = Log(100, False)
     ret = log.pre_log()
-    log.post_log(ret, 'pass')
+    log.log('test', 'pass', ret)
     nt.assert_equal(log._Log__complete, 1,
-                    msg="Log.post_log() did not properly incremented "
-                        "Log.__current")
+                    msg="Log.log() did not properly incremented Log.__current")
 
 
-def check_post_log_increment_summary(stat):
-    """ Test that passing a result to post_log works correctly """
+def check_log_increment_summary(stat):
+    """ Test that passing a result to log works correctly """
     log = Log(100, False)
     ret = log.pre_log()
-    log.post_log(ret, stat)
+    log.log('test', stat, ret)
     print log._Log__summary
     nt.assert_equal(log._Log__summary[stat], 1,
                     msg="Log.__summary[{}] was not properly "
@@ -73,26 +70,26 @@ def check_post_log_increment_summary(stat):
 
 
 @utils.nose_generator
-def test_post_log_increment_summary():
+def test_log_increment_summary():
     """ Generator that creates tests for self.__summary """
     for stat in valid_statuses:
-        check_post_log_increment_summary.description = \
-            "Test that Log.post_log increments self._summary[{}]".format(stat)
-        yield check_post_log_increment_summary, stat
+        check_log_increment_summary.description = \
+            "Test that Log.log increments self._summary[{}]".format(stat)
+        yield check_log_increment_summary, stat
 
 
-def test_post_log_removes_complete():
-    """ Test that Log.post_log() removes finished tests from __running """
+def test_log_removes_complete():
+    """ Test that Log.log() removes finished tests from __running """
     log = Log(100, False)
     ret = log.pre_log()
-    log.post_log(ret, 'pass')
+    log.log('test', 'pass', ret)
     nt.assert_not_in(ret, log._Log__running,
                      msg="Running tests not removed from running list")
 
 
 @nt.raises(AssertionError)
-def test_post_log_increment_summary_bad():
-    """ Only statuses in self.__summary_keys are valid for post_log """
+def test_log_increment_summary_bad():
+    """ Only statuses in self.__summary_keys are valid for log """
     log = Log(100, False)
     ret = log.pre_log()
-    log.post_log(ret, 'fails')
+    log.log('test', 'fails', ret)
-- 
2.0.4



More information about the Piglit mailing list