[Piglit] [PATCH 20/44] base_tests.py: Add tests for an exception in Test.execute
baker.dylan.c at gmail.com
baker.dylan.c at gmail.com
Wed Jan 27 16:06:28 PST 2016
From: Dylan Baker <baker.dylan.c at gmail.com>
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
unittests/base_tests.py | 43 +++++++++++++++++++++++++++++++++++++++++++
unittests/results_tests.py | 5 +++++
unittests/utils.py | 5 +++++
3 files changed, 53 insertions(+)
diff --git a/unittests/base_tests.py b/unittests/base_tests.py
index 59c1c8e..2fa13ca 100644
--- a/unittests/base_tests.py
+++ b/unittests/base_tests.py
@@ -30,6 +30,7 @@ try:
except ImportError:
import mock
+import six
import nose.tools as nt
from nose.plugins.attrib import attr
import six
@@ -48,6 +49,7 @@ from framework.test.base import (
WindowResizeMixin,
)
from framework.options import _Options as Options
+from framework import log, dmesg
# pylint: disable=invalid-name
@@ -394,3 +396,44 @@ def test_interpret_result_greater_zero():
test.interpret_result()
nt.eq_(test.result.result, 'fail')
+
+
+class TestExecuteTraceback(object):
+ """Test.execute tests for Traceback handling."""
+ @classmethod
+ @utils.capture_stderr # The exception will be printed
+ def setup_class(cls):
+ test = TestTest(['foo'])
+ test.run = mock.Mock(side_effect=utils.SentinalException)
+
+ test.execute(mock.Mock(spec=six.text_type),
+ mock.Mock(spec=log.BaseLog),
+ mock.Mock(spec=dmesg.BaseDmesg))
+
+ cls.test = test.result
+
+ def test_result(self):
+ """Test.execute (exception): Sets the result to fail"""
+ nt.eq_(self.test.result, 'fail')
+
+ def test_traceback(self):
+ """Test.execute (exception): Sets the traceback
+
+ It's fragile to record the actual traceback, and it's unlikely
+ that it can easily be implemented differently than the way the original
+ code is implimented, so this doesn't do that, it just verifies there is
+ a value.
+
+ """
+ nt.assert_not_equal(self.test.traceback, str)
+ nt.assert_is_instance(self.test.traceback, six.string_types)
+
+ def test_exception(self):
+ """Test.execute (exception): Sets the exception
+
+ This is much like the traceback, it's difficult to get the correct
+ value, so just make sure it's being set
+
+ """
+ nt.assert_not_equal(self.test.exception, str)
+ nt.assert_is_instance(self.test.exception, six.string_types)
diff --git a/unittests/results_tests.py b/unittests/results_tests.py
index 9b03ae8..6870864 100644
--- a/unittests/results_tests.py
+++ b/unittests/results_tests.py
@@ -121,6 +121,7 @@ class TestTestResultFromDictAttributes(object):
'environment': 'environment variables',
'result': 'pass',
'dmesg': 'this is some dmesg',
+ 'exception': 'this is an exception',
}
cls.test = results.TestResult.from_dict(dict_)
@@ -157,6 +158,10 @@ class TestTestResultFromDictAttributes(object):
"""dmesgs.TestResult.from_dict: sets dmesg correctly"""
nt.eq_(self.test.dmesg, 'this is some dmesg')
+ def test_exception(self):
+ """dmesgs.TestResult.from_dict: sets exception correctly"""
+ nt.eq_(self.test.exception, 'this is an exception')
+
def test_TestResult_result_getter():
"""results.TestResult.result: Getter returns the result when there are no subtests"""
diff --git a/unittests/utils.py b/unittests/utils.py
index 2b539b9..4e78ba0 100644
--- a/unittests/utils.py
+++ b/unittests/utils.py
@@ -118,6 +118,11 @@ class UtilsError(Exception):
pass
+class SentinalException(Exception):
+ """An exception to be used as a sentinal."""
+ pass
+
+
class StaticDirectory(object):
""" Helper class providing shared files creation and cleanup
--
2.7.0
More information about the Piglit
mailing list