Skip to content

Commit

Permalink
Move the new tests to try to avoid a conflict with the previous PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed May 7, 2015
1 parent 934dc2f commit 0523a7e
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions src/zope/proxy/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,70 @@ def __init__(self, arg):
proxy = MyProxy3('notused')
self.assertEqual(list(proxy), list('another'))

def test_string_to_int(self):
# Strings don't have the tp_number.tp_int pointer
proxy = self._makeOne("14")
self.assertEqual(14, int(proxy))

def test_custom_int_to_int(self):
class CustomClass(object):
def __int__(self):
return 42
proxy = self._makeOne(CustomClass())
self.assertEqual(42, int(proxy))

def test_string_to_float(self):
proxy = self._makeOne("14")
self.assertEqual(float("14"), float(proxy))

def test_incorrect_string_to_int(self):
proxy = self._makeOne("")
self.assertRaises(ValueError, int, proxy)

def test_incorrect_string_to_float(self):
proxy = self._makeOne("")
self.assertRaises(ValueError, float, proxy)

def test_custom_float_to_float(self):
class CustomClass(object):
def __float__(self):
return 42.0
proxy = self._makeOne(CustomClass())
self.assertEqual(42.0, float(proxy))

def test___unicode__of_unicode(self):
from zope.proxy._compat import PY3, _u
if PY3: # Gone in Python 3:
return
s = _u('Hello, \u2603')
proxy = self._makeOne(s)
self.assertEqual(unicode(proxy), s)

def test___unicode__of_custom_class(self):
from zope.proxy._compat import PY3, _u
if PY3: # Gone in Python 3:
return
class CustomClass(object):
def __unicode__(self):
return _u('Hello, \u2603')
cc = CustomClass()
self.assertEqual(unicode(cc), _u('Hello, \u2603'))
proxy = self._makeOne(cc)
self.assertEqual(unicode(proxy), _u('Hello, \u2603'))

def test___unicode__of_custom_class_no_unicode(self):
# The default behaviour should be preserved
from zope.proxy._compat import PY3, _u
if PY3: # Gone in Python 3:
return
class CustomClass(object):
pass
cc = CustomClass()
cc_unicode = unicode(cc)
self.assertEqual(type(cc_unicode), unicode)
proxy = self._makeOne(cc)
self.assertEqual(unicode(proxy), cc_unicode)

def test___call__(self):
def _foo():
return 'FOO'
Expand Down Expand Up @@ -581,71 +645,6 @@ def test___class__(self):
w = self._makeOne(o)
self.assertTrue(w.__class__ is o.__class__)

def test_string_to_int(self):
# Strings don't have the tp_number.tp_int pointer
proxy = self._makeOne("14")
self.assertEqual(14, int(proxy))

def test_custom_int_to_int(self):
class CustomClass(object):
def __int__(self):
return 42
proxy = self._makeOne(CustomClass())
self.assertEqual(42, int(proxy))

def test_string_to_float(self):
proxy = self._makeOne("14")
self.assertEqual(float("14"), float(proxy))

def test_incorrect_string_to_int(self):
proxy = self._makeOne("")
self.assertRaises(ValueError, int, proxy)

def test_incorrect_string_to_float(self):
proxy = self._makeOne("")
self.assertRaises(ValueError, float, proxy)

def test_custom_float_to_float(self):
class CustomClass(object):
def __float__(self):
return 42.0
proxy = self._makeOne(CustomClass())
self.assertEqual(42.0, float(proxy))

def test___unicode__of_unicode(self):
from zope.proxy._compat import PY3, _u
if PY3: # Gone in Python 3:
return
s = _u('Hello, \u2603')
proxy = self._makeOne(s)
self.assertEqual(unicode(proxy), s)

def test___unicode__of_custom_class(self):
from zope.proxy._compat import PY3, _u
if PY3: # Gone in Python 3:
return
class CustomClass(object):
def __unicode__(self):
return _u('Hello, \u2603')
cc = CustomClass()
self.assertEqual(unicode(cc), _u('Hello, \u2603'))
proxy = self._makeOne(cc)
self.assertEqual(unicode(proxy), _u('Hello, \u2603'))

def test___unicode__of_custom_class_no_unicode(self):
# The default behaviour should be preserved
from zope.proxy._compat import PY3, _u
if PY3: # Gone in Python 3:
return
class CustomClass(object):
pass
cc = CustomClass()
cc_unicode = unicode(cc)
self.assertEqual(type(cc_unicode), unicode)
proxy = self._makeOne(cc)
self.assertEqual(unicode(proxy), cc_unicode)


class ProxyBaseTestCase(PyProxyBaseTestCase):

def _getTargetClass(self):
Expand Down

0 comments on commit 0523a7e

Please sign in to comment.