[Piglit] [PATCH 2/3] log_tests.py: Add tests to assert that the logger accepts Status objects

Dylan Baker baker.dylan.c at gmail.com
Tue Sep 16 14:46:57 PDT 2014


In the event that a test rapidly fails (such as system misconfiguration)
the logger will be passed the default value of Test.result(), which is
framework.status.FAIL, which is not a string. The logger needs to be
able to handle this.

This also makes the assertions in log.py return a descriptive error
message

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/log.py             | 10 ++++++----
 framework/tests/log_tests.py | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/framework/log.py b/framework/log.py
index d261dbb..e0f8cf6 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -111,24 +111,26 @@ class Log(object):
 
         """
         # Mark running complete
-        assert value in self.__running
+        assert value in self.__running, "Test to finish it not running"
         self.__running.remove(value)
 
         # increment the number of completed tests
         self.__complete += 1
 
-        assert result in self.__summary_keys
+        assert result in self.__summary_keys, 'Result "{0}" not in {1}'.format(
+            result, self.__summary_keys)
         self.__summary[result] += 1
 
     @synchronized_self
     def log(self, name, result):
-        """ Print to the screen 
+        """ 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
+        assert result in self.__summary_keys, 'Result "{0}" not in {1}'.format(
+            result, self.__summary_keys)
         self.__print(name, result)
 
     @synchronized_self
diff --git a/framework/tests/log_tests.py b/framework/tests/log_tests.py
index f04040c..7936a02 100644
--- a/framework/tests/log_tests.py
+++ b/framework/tests/log_tests.py
@@ -24,6 +24,7 @@ import types
 import nose.tools as nt
 from framework.log import Log
 import framework.tests.utils as utils
+import framework.status as status
 
 valid_statuses = ('pass', 'fail', 'crash', 'warn', 'dmesg-warn',
                   'dmesg-fail', 'skip', 'dry-run')
@@ -95,3 +96,24 @@ def test_post_log_increment_summary_bad():
     log = Log(100, False)
     ret = log.pre_log()
     log.post_log(ret, 'fails')
+
+
+def test_post_log_status():
+    """ Log.post_log() handles a status object being passed """
+    log = Log(100, False)
+
+    try:
+        x = log.pre_log()
+        log.post_log(x, status.FAIL)
+    except Exception as e:
+        raise AssertionError(e)
+
+
+def test_log_status():
+    """ Log.post_log() handles a status object being passed """
+    log = Log(100, False)
+
+    try:
+        log.log('foo', status.FAIL)
+    except Exception as e:
+        raise AssertionError(e)
-- 
2.1.0



More information about the Piglit mailing list