[gtk-doc] tests/common.py: Make compatible with Python 3



commit 56213947d1551ad29137e5a30923378d811fc14f
Author: Jan Alexander Steffens (heftig) <jan steffens gmail com>
Date:   Fri Aug 11 21:18:33 2017 +0200

    tests/common.py: Make compatible with Python 3
    
    Attempt to load the modules for Python 3 first. If this fails, attempt
    to load the modules for Python 2.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786174

 tests/common.py |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/tests/common.py b/tests/common.py
index 3f78220..8b45f1d 100755
--- a/tests/common.py
+++ b/tests/common.py
@@ -20,7 +20,16 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 
-import mock
+try:
+    from unittest import mock
+except ImportError:
+    import mock
+
+try:
+    import builtins
+except ImportError:
+    import __builtin__ as builtins
+
 import unittest
 
 from gtkdoc import common
@@ -37,7 +46,7 @@ class TestUpdateFileIfChanged(unittest.TestCase):
         self.assertTrue(res)
 
     @mock.patch('os.path.exists')
-    @mock.patch('__builtin__.open', mock.mock_open(read_data='bar'))
+    @mock.patch('builtins.open', mock.mock_open(read_data='bar'))
     @mock.patch('os.unlink')
     def test_FilesAreTheSame(self, os_unlink, os_path_exists):
         os_path_exists.return_value = True


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]