summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Fladischer <FladischerMichael@fladi.at>2015-07-28 17:54:54 +0200
committerMichael Fladischer <FladischerMichael@fladi.at>2015-07-29 11:51:09 +0200
commitc97d8fe84bb7ca0b8bfa500f5864e7a3d0c0a75f (patch)
treeeb166387ec76f9cef0b92a11cead6c577e9486ea
parente34a7cb293a40f03b8d5a5e7d95f60429233c471 (diff)
downloadmock-c97d8fe84bb7ca0b8bfa500f5864e7a3d0c0a75f.tar.gz
Use six to detect python2/3 in test modules.
-rw-r--r--mock/tests/support.py1
-rw-r--r--mock/tests/testhelpers.py11
-rw-r--r--mock/tests/testmagicmethods.py17
-rw-r--r--mock/tests/testmock.py7
-rw-r--r--mock/tests/testpatch.py5
5 files changed, 21 insertions, 20 deletions
diff --git a/mock/tests/support.py b/mock/tests/support.py
index 0cbdb2c..8e2082f 100644
--- a/mock/tests/support.py
+++ b/mock/tests/support.py
@@ -11,7 +11,6 @@ except NameError:
return hasattr(obj, '__call__')
-inPy3k = sys.version_info[0] == 3
with_available = sys.version_info[:2] >= (2, 5)
diff --git a/mock/tests/testhelpers.py b/mock/tests/testhelpers.py
index 99316e5..14dbfe3 100644
--- a/mock/tests/testhelpers.py
+++ b/mock/tests/testhelpers.py
@@ -2,8 +2,9 @@
# E-mail: fuzzyman AT voidspace DOT org DOT uk
# http://www.voidspace.org.uk/python/mock/
+import six
+
import unittest2 as unittest
-from mock.tests.support import inPy3k
from mock import (
call, create_autospec, MagicMock,
@@ -403,7 +404,7 @@ class SpecSignatureTest(unittest.TestCase):
m = create_autospec(Foo, a='3')
self.assertEqual(m.a, '3')
- @unittest.skipUnless(inPy3k, "Keyword only arguments Python 3 specific")
+ @unittest.skipUnless(six.PY3, "Keyword only arguments Python 3 specific")
def test_create_autospec_keyword_only_arguments(self):
func_def = "def foo(a, *, b=None):\n pass\n"
namespace = {}
@@ -558,7 +559,7 @@ class SpecSignatureTest(unittest.TestCase):
mock.g.assert_called_once_with(3, 4)
- @unittest.skipIf(inPy3k, "No old style classes in Python 3")
+ @unittest.skipIf(six.PY3, "No old style classes in Python 3")
def test_old_style_classes(self):
class Foo:
def f(self, a, b):
@@ -745,7 +746,7 @@ class SpecSignatureTest(unittest.TestCase):
mock.assert_called_with(4, 5)
- @unittest.skipIf(inPy3k, 'no old style classes in Python 3')
+ @unittest.skipIf(six.PY3, 'no old style classes in Python 3')
def test_signature_old_style_class(self):
class Foo:
def __init__(self, a, b=3):
@@ -773,7 +774,7 @@ class SpecSignatureTest(unittest.TestCase):
create_autospec(Foo)
- @unittest.skipIf(inPy3k, 'no old style classes in Python 3')
+ @unittest.skipIf(six.PY3, 'no old style classes in Python 3')
def test_old_style_class_with_no_init(self):
# this used to raise an exception
# due to Foo.__init__ raising an AttributeError
diff --git a/mock/tests/testmagicmethods.py b/mock/tests/testmagicmethods.py
index 5e39770..20b0e9f 100644
--- a/mock/tests/testmagicmethods.py
+++ b/mock/tests/testmagicmethods.py
@@ -6,8 +6,6 @@ from __future__ import division
import unittest2 as unittest
-from mock.tests.support import inPy3k
-
try:
unicode
except NameError:
@@ -15,6 +13,7 @@ except NameError:
unicode = str
long = int
+import six
import inspect
import sys
import textwrap
@@ -86,7 +85,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(str(mock), 'foo')
- @unittest.skipIf(inPy3k, "no unicode in Python 3")
+ @unittest.skipIf(six.PY3, "no unicode in Python 3")
def test_unicode(self):
mock = Mock()
self.assertEqual(unicode(mock), unicode(str(mock)))
@@ -166,7 +165,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(mock.value, 16)
del mock.__truediv__
- if inPy3k:
+ if six.PY3:
def itruediv(mock):
mock /= 4
self.assertRaises(TypeError, itruediv, mock)
@@ -198,7 +197,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertTrue(bool(m))
nonzero = lambda s: False
- if not inPy3k:
+ if six.PY2:
m.__nonzero__ = nonzero
else:
m.__bool__ = nonzero
@@ -216,7 +215,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self. assertTrue(mock <= 3)
self. assertTrue(mock >= 3)
- if not inPy3k:
+ if six.PY2:
# incomparable in Python 3
self.assertEqual(Mock() < 3, object() < 3)
self.assertEqual(Mock() > 3, object() > 3)
@@ -294,7 +293,7 @@ class TestMockingMagicMethods(unittest.TestCase):
name = '__nonzero__'
other = '__bool__'
- if inPy3k:
+ if six.PY3:
name, other = other, name
getattr(mock, name).return_value = False
self.assertFalse(hasattr(mock, other))
@@ -330,7 +329,7 @@ class TestMockingMagicMethods(unittest.TestCase):
self.assertEqual(unicode(mock), object.__str__(mock))
self.assertIsInstance(unicode(mock), unicode)
self.assertTrue(bool(mock))
- if not inPy3k:
+ if six.PY2:
self.assertEqual(oct(mock), '1')
else:
# in Python 3 oct and hex use __index__
@@ -340,7 +339,7 @@ class TestMockingMagicMethods(unittest.TestCase):
# how to test __sizeof__ ?
- @unittest.skipIf(inPy3k, "no __cmp__ in Python 3")
+ @unittest.skipIf(six.PY3, "no __cmp__ in Python 3")
def test_non_default_magic_methods(self):
mock = MagicMock()
self.assertRaises(AttributeError, lambda: mock.__cmp__)
diff --git a/mock/tests/testmock.py b/mock/tests/testmock.py
index d956064..ddecfe1 100644
--- a/mock/tests/testmock.py
+++ b/mock/tests/testmock.py
@@ -4,9 +4,10 @@
import unittest2 as unittest
from mock.tests.support import (
- callable, inPy3k, is_instance, next
+ callable, is_instance, next
)
+import six
import copy
import pickle
import sys
@@ -663,7 +664,7 @@ class MockTest(unittest.TestCase):
copy.copy(Mock())
- @unittest.skipIf(inPy3k, "no old style classes in Python 3")
+ @unittest.skipIf(six.PY3, "no old style classes in Python 3")
def test_spec_old_style_classes(self):
class Foo:
bar = 7
@@ -677,7 +678,7 @@ class MockTest(unittest.TestCase):
self.assertRaises(AttributeError, lambda: mock.foo)
- @unittest.skipIf(inPy3k, "no old style classes in Python 3")
+ @unittest.skipIf(six.PY3, "no old style classes in Python 3")
def test_spec_set_old_style_classes(self):
class Foo:
bar = 7
diff --git a/mock/tests/testpatch.py b/mock/tests/testpatch.py
index ce84df2..208e97a 100644
--- a/mock/tests/testpatch.py
+++ b/mock/tests/testpatch.py
@@ -4,11 +4,12 @@
import os
import sys
+import six
import unittest2 as unittest
from mock.tests import support
-from mock.tests.support import inPy3k, SomeClass, is_instance, callable
+from mock.tests.support import SomeClass, is_instance, callable
from mock import (
NonCallableMock, CallableMixin, patch, sentinel,
@@ -18,7 +19,7 @@ from mock import (
from mock.mock import _patch, _get_target
builtin_string = '__builtin__'
-if inPy3k:
+if six.PY3:
builtin_string = 'builtins'
unicode = str