python/mock-1.0.0/tests/support.py

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 import sys
michael@0 2
michael@0 3 info = sys.version_info
michael@0 4 if info[:3] >= (3, 2, 0):
michael@0 5 # for Python 3.2 ordinary unittest is fine
michael@0 6 import unittest as unittest2
michael@0 7 else:
michael@0 8 import unittest2
michael@0 9
michael@0 10
michael@0 11 try:
michael@0 12 callable = callable
michael@0 13 except NameError:
michael@0 14 def callable(obj):
michael@0 15 return hasattr(obj, '__call__')
michael@0 16
michael@0 17
michael@0 18 inPy3k = sys.version_info[0] == 3
michael@0 19 with_available = sys.version_info[:2] >= (2, 5)
michael@0 20
michael@0 21
michael@0 22 def is_instance(obj, klass):
michael@0 23 """Version of is_instance that doesn't access __class__"""
michael@0 24 return issubclass(type(obj), klass)
michael@0 25
michael@0 26
michael@0 27 class SomeClass(object):
michael@0 28 class_attribute = None
michael@0 29
michael@0 30 def wibble(self):
michael@0 31 pass
michael@0 32
michael@0 33
michael@0 34 class X(object):
michael@0 35 pass
michael@0 36
michael@0 37 try:
michael@0 38 next = next
michael@0 39 except NameError:
michael@0 40 def next(obj):
michael@0 41 return obj.next()

mercurial