Skip to content

Commit

Permalink
Python 3.2 compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver committed Mar 31, 2015
1 parent 483aa56 commit 0db02f6
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/Acquisition/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@
import operator
from doctest import DocTestSuite, DocFileSuite

import ExtensionClass
import Acquisition


if sys.version_info >= (3,):
PY3 = True
Expand All @@ -359,9 +362,10 @@ def unicode(self):
gc.get_threshold = lambda: ()
gc.set_threshold = lambda *x: None

import ExtensionClass
import Acquisition

AQ_PARENT = unicode('aq_parent')
UNICODE_WAS_CALLED = unicode('unicode was called')
STR_WAS_CALLED = unicode('str was called')
TRUE = unicode('True')

class I(Acquisition.Implicit):

Expand Down Expand Up @@ -3117,7 +3121,7 @@ def test_unwrapped_falls_back_to_default(self):

def test_w_unicode_attr_name(self):
# See https://bugs.launchpad.net/acquisition/+bug/143358
found = self.acquire(self.a.b.c, u'aq_parent')
found = self.acquire(self.a.b.c, AQ_PARENT)
self.assertTrue(found.aq_self is self.a.b.aq_self)


Expand All @@ -3126,33 +3130,33 @@ class TestUnicode(unittest.TestCase):
def test_implicit_aq_unicode_should_be_called(self):
class A(Acquisition.Implicit):
def __unicode__(self):
return u'unicode was called'
return UNICODE_WAS_CALLED
wrapped = A().__of__(A())
self.assertEqual(u'unicode was called', unicode(wrapped))
self.assertEqual(UNICODE_WAS_CALLED, unicode(wrapped))
self.assertEqual(str(wrapped), repr(wrapped))

def test_explicit_aq_unicode_should_be_called(self):
class A(Acquisition.Explicit):
def __unicode__(self):
return u'unicode was called'
return UNICODE_WAS_CALLED
wrapped = A().__of__(A())
self.assertEqual(u'unicode was called', unicode(wrapped))
self.assertEqual(UNICODE_WAS_CALLED, unicode(wrapped))
self.assertEqual(str(wrapped), repr(wrapped))

def test_implicit_should_fall_back_to_str(self):
class A(Acquisition.Implicit):
def __str__(self):
return 'str was called'
wrapped = A().__of__(A())
self.assertEqual(u'str was called', unicode(wrapped))
self.assertEqual(STR_WAS_CALLED, unicode(wrapped))
self.assertEqual('str was called', str(wrapped))

def test_explicit_should_fall_back_to_str(self):
class A(Acquisition.Explicit):
def __str__(self):
return 'str was called'
wrapped = A().__of__(A())
self.assertEqual(u'str was called', unicode(wrapped))
self.assertEqual(STR_WAS_CALLED, unicode(wrapped))
self.assertEqual('str was called', str(wrapped))

def test_str_fallback_should_be_called_with_wrapped_self(self):
Expand All @@ -3161,15 +3165,15 @@ def __str__(self):
return str(self.aq_parent == outer)
outer = A()
inner = A().__of__(outer)
self.assertEqual(u'True', unicode(inner))
self.assertEqual(TRUE, unicode(inner))

def test_unicode_should_be_called_with_wrapped_self(self):
class A(Acquisition.Implicit):
def __unicode__(self):
return str(self.aq_parent == outer)
outer = A()
inner = A().__of__(outer)
self.assertEqual(u'True', unicode(inner))
self.assertEqual(TRUE, unicode(inner))

class TestProxying(unittest.TestCase):

Expand Down

0 comments on commit 0db02f6

Please sign in to comment.