summaryrefslogtreecommitdiff
path: root/pystache
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2012-04-08 18:32:07 -0700
committerChris Jerdonek <chris.jerdonek@gmail.com>2012-04-08 18:32:07 -0700
commitb06ea722e284e867dbc31e299bb1a1e9c5ba406c (patch)
tree3694019b02e8f6a461f5382f5ac74fcf111c12f3 /pystache
parentc414a5ca3f974ef5d7063ec024f22cb7f7e9b8ac (diff)
downloadpystache-b06ea722e284e867dbc31e299bb1a1e9c5ba406c.tar.gz
Made a test_context pass in Python 3.
Diffstat (limited to 'pystache')
-rw-r--r--pystache/tests/test_context.py41
1 files changed, 19 insertions, 22 deletions
diff --git a/pystache/tests/test_context.py b/pystache/tests/test_context.py
index 2b6846f..bcf72de 100644
--- a/pystache/tests/test_context.py
+++ b/pystache/tests/test_context.py
@@ -85,9 +85,11 @@ class GetValueTests(unittest.TestCase, AssertIsMixin):
Test that dictionary attributes are not checked.
"""
- item = {}
- attr_name = "keys"
- self.assertEqual(getattr(item, attr_name)(), [])
+ item = {1: 2, 3: 4}
+ # I was not able to find a "public" attribute of dict that is
+ # the same across Python 2/3.
+ attr_name = "__len__"
+ self.assertEqual(getattr(item, attr_name)(), 2)
self.assertNotFound(item, attr_name)
def test_dictionary__dict_subclass(self):
@@ -154,25 +156,20 @@ class GetValueTests(unittest.TestCase, AssertIsMixin):
"""
class MyInt(int): pass
- item1 = MyInt(10)
- item2 = 10
-
- try:
- item2.real
- except AttributeError:
- # Then skip this unit test. The numeric type hierarchy was
- # added only in Python 2.6, in which case integers inherit
- # from complex numbers the "real" attribute, etc:
- #
- # http://docs.python.org/library/numbers.html
- #
- return
-
- self.assertEqual(item1.real, 10)
- self.assertEqual(item2.real, 10)
-
- self.assertEqual(_get_value(item1, 'real'), 10)
- self.assertNotFound(item2, 'real')
+ cust_int = MyInt(10)
+ pure_int = 10
+
+ # We have to use a built-in method like __neg__ because "public"
+ # attributes like "real" were not added to Python until Python 2.6,
+ # when the numeric type hierarchy was added:
+ #
+ # http://docs.python.org/library/numbers.html
+ #
+ self.assertEqual(cust_int.__neg__(), -10)
+ self.assertEqual(pure_int.__neg__(), -10)
+
+ self.assertEqual(_get_value(cust_int, '__neg__'), -10)
+ self.assertNotFound(pure_int, '__neg__')
def test_built_in_type__string(self):
"""