Commit b06ea722 by Chris Jerdonek

Made a test_context pass in Python 3.

parent c414a5ca
...@@ -85,9 +85,11 @@ class GetValueTests(unittest.TestCase, AssertIsMixin): ...@@ -85,9 +85,11 @@ class GetValueTests(unittest.TestCase, AssertIsMixin):
Test that dictionary attributes are not checked. Test that dictionary attributes are not checked.
""" """
item = {} item = {1: 2, 3: 4}
attr_name = "keys" # I was not able to find a "public" attribute of dict that is
self.assertEqual(getattr(item, attr_name)(), []) # the same across Python 2/3.
attr_name = "__len__"
self.assertEqual(getattr(item, attr_name)(), 2)
self.assertNotFound(item, attr_name) self.assertNotFound(item, attr_name)
def test_dictionary__dict_subclass(self): def test_dictionary__dict_subclass(self):
...@@ -154,25 +156,20 @@ class GetValueTests(unittest.TestCase, AssertIsMixin): ...@@ -154,25 +156,20 @@ class GetValueTests(unittest.TestCase, AssertIsMixin):
""" """
class MyInt(int): pass class MyInt(int): pass
item1 = MyInt(10) cust_int = MyInt(10)
item2 = 10 pure_int = 10
try: # We have to use a built-in method like __neg__ because "public"
item2.real # attributes like "real" were not added to Python until Python 2.6,
except AttributeError: # when the numeric type hierarchy was added:
# Then skip this unit test. The numeric type hierarchy was #
# added only in Python 2.6, in which case integers inherit # http://docs.python.org/library/numbers.html
# from complex numbers the "real" attribute, etc: #
# self.assertEqual(cust_int.__neg__(), -10)
# http://docs.python.org/library/numbers.html self.assertEqual(pure_int.__neg__(), -10)
#
return self.assertEqual(_get_value(cust_int, '__neg__'), -10)
self.assertNotFound(pure_int, '__neg__')
self.assertEqual(item1.real, 10)
self.assertEqual(item2.real, 10)
self.assertEqual(_get_value(item1, 'real'), 10)
self.assertNotFound(item2, 'real')
def test_built_in_type__string(self): def test_built_in_type__string(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment