[Piglit] [PATCH 17/44] unittests: try to import mock from unittest

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Wed Jan 27 16:06:25 PST 2016


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

As of python 3.3 mock is included in python's stdlib. Try to import the
included version, then the external package version if that fails.

This patch was generated with the following sed command:
sed -i -e 's at import mock at try:\n    from unittest import mock\nexcept ImportError:\n    import mock\n at g' unittests/*py

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 unittests/base_tests.py             | 6 +++++-
 unittests/deqp_tests.py             | 6 +++++-
 unittests/dmesg_tests.py            | 6 +++++-
 unittests/gleantest_tests.py        | 6 +++++-
 unittests/glsl_parser_test_tests.py | 6 +++++-
 unittests/oglconform_tests.py       | 6 +++++-
 unittests/opengl_tests.py           | 6 +++++-
 unittests/options_tests.py          | 6 +++++-
 unittests/piglit_test_tests.py      | 6 +++++-
 unittests/profile_tests.py          | 6 +++++-
 unittests/shader_test_tests.py      | 6 +++++-
 11 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/unittests/base_tests.py b/unittests/base_tests.py
index 37504d9..3235cc6 100644
--- a/unittests/base_tests.py
+++ b/unittests/base_tests.py
@@ -25,7 +25,11 @@ import tempfile
 import textwrap
 import os
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 from nose.plugins.attrib import attr
 
diff --git a/unittests/deqp_tests.py b/unittests/deqp_tests.py
index 9b546b1..ea0a016 100644
--- a/unittests/deqp_tests.py
+++ b/unittests/deqp_tests.py
@@ -27,7 +27,11 @@ tests
 
 from __future__ import absolute_import, division, print_function
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 import six
 
diff --git a/unittests/dmesg_tests.py b/unittests/dmesg_tests.py
index 08e61ef..e6ea4cc 100644
--- a/unittests/dmesg_tests.py
+++ b/unittests/dmesg_tests.py
@@ -29,7 +29,11 @@ from __future__ import absolute_import, division, print_function
 import re
 import warnings
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from . import utils
diff --git a/unittests/gleantest_tests.py b/unittests/gleantest_tests.py
index ca06e3b..b597d69 100644
--- a/unittests/gleantest_tests.py
+++ b/unittests/gleantest_tests.py
@@ -22,7 +22,11 @@
 
 from __future__ import absolute_import, division, print_function
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from framework.options import _Options as Options
diff --git a/unittests/glsl_parser_test_tests.py b/unittests/glsl_parser_test_tests.py
index 629b1d4..818090e 100644
--- a/unittests/glsl_parser_test_tests.py
+++ b/unittests/glsl_parser_test_tests.py
@@ -24,7 +24,11 @@ from __future__ import absolute_import, division, print_function
 import os
 import textwrap
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from . import utils
diff --git a/unittests/oglconform_tests.py b/unittests/oglconform_tests.py
index 4b94a16..a2f2689 100644
--- a/unittests/oglconform_tests.py
+++ b/unittests/oglconform_tests.py
@@ -22,7 +22,11 @@
 
 from __future__ import absolute_import, division, print_function
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 from six.moves import cStringIO as StringIO
 
diff --git a/unittests/opengl_tests.py b/unittests/opengl_tests.py
index 9b1bc4a..4e6656d 100644
--- a/unittests/opengl_tests.py
+++ b/unittests/opengl_tests.py
@@ -24,7 +24,11 @@ from __future__ import absolute_import, division, print_function
 import subprocess
 import textwrap
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from . import utils
diff --git a/unittests/options_tests.py b/unittests/options_tests.py
index 695935d..ffe8e37 100644
--- a/unittests/options_tests.py
+++ b/unittests/options_tests.py
@@ -23,7 +23,11 @@
 from __future__ import absolute_import, division, print_function
 import re
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from . import utils
diff --git a/unittests/piglit_test_tests.py b/unittests/piglit_test_tests.py
index f299af5..6352a01 100644
--- a/unittests/piglit_test_tests.py
+++ b/unittests/piglit_test_tests.py
@@ -22,7 +22,11 @@
 
 from __future__ import absolute_import, division, print_function
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from . import utils
diff --git a/unittests/profile_tests.py b/unittests/profile_tests.py
index ca1aca4..ee48c1b 100644
--- a/unittests/profile_tests.py
+++ b/unittests/profile_tests.py
@@ -24,7 +24,11 @@ from __future__ import absolute_import, division, print_function
 import sys
 import copy
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from . import utils
diff --git a/unittests/shader_test_tests.py b/unittests/shader_test_tests.py
index 5feda63..b176b6f 100644
--- a/unittests/shader_test_tests.py
+++ b/unittests/shader_test_tests.py
@@ -23,7 +23,11 @@
 from __future__ import absolute_import, division, print_function
 import os
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
 import nose.tools as nt
 
 from framework import exceptions
-- 
2.7.0



More information about the Piglit mailing list