[Piglit] [PATCH 14/14] unittests/core_tests.py: Add tests that only apply to python3

Dylan Baker dylan at pnwbakers.com
Fri May 6 20:07:24 UTC 2016


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

There are some Exceptions that changed in python 3.x, this adds a test
that will only by run on python 3

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 unittests/core_tests.py | 12 +++++++++++-
 unittests/utils.py      | 25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/unittests/core_tests.py b/unittests/core_tests.py
index 8cbac8e..825fb73 100644
--- a/unittests/core_tests.py
+++ b/unittests/core_tests.py
@@ -295,7 +295,7 @@ def test_check_dir_stat_ENOENT():
 
 
 def test_check_dir_stat_ENOTDIR():
-    """core.check_dir: if the directory exists (ENOTDIR) and failifexsits is False continue"""
+    """core.check_dir: if a file exists (ENOTDIR) and failifexsits is False continue"""
     with mock.patch('framework.core.os.stat',
                     mock.Mock(side_effect=OSError('foo', errno.ENOTDIR))):
         with mock.patch('framework.core.os.makedirs') as makedirs:
@@ -330,3 +330,13 @@ def test_check_dir_handler():
                     mock.Mock(side_effect=OSError('foo', errno.ENOTDIR))):
         core.check_dir('foo',
                        handler=mock.Mock(side_effect=utils.SentinalException))
+
+
+ at utils.skip(not six.PY3, 'Test is only relevant on python 3.x')
+def test_check_dir_stat_FileNotFoundError():
+    """core.check_dir: FileNotFoundError is raised and failifexsits is False continue"""
+    with mock.patch('framework.core.os.stat',
+                    mock.Mock(side_effect=FileNotFoundError)):
+        with mock.patch('framework.core.os.makedirs') as makedirs:
+            core.check_dir('foo', False)
+            nt.eq_(makedirs.called, 1)
diff --git a/unittests/utils.py b/unittests/utils.py
index 255f253..99cf482 100644
--- a/unittests/utils.py
+++ b/unittests/utils.py
@@ -541,3 +541,28 @@ def unset_compression():
         os.environ['PIGLIT_COMPRESSION'] = _SAVED_COMPRESSION
     else:
         del os.environ['PIGLIT_COMPRESSION']
+
+
+def skip(condition, description):
+    """Skip a test if the condition is met.
+
+    Arguments:
+    condition -- If this is truthy then the test will be skippped
+    description -- the message that SkipTest will display if the test is
+                   skipped
+
+    """
+
+    def _wrapper(func):
+        """The function that acutally does the wrapping."""
+
+        @functools.wraps(func)
+        def _inner(*args, **kwargs):
+            """The function that is actually called."""
+            if condition:
+                raise SkipTest(description)
+            return func(*args, **kwargs)
+
+        return _inner
+
+    return _wrapper
-- 
2.8.2



More information about the Piglit mailing list