add tests for weakref conversions for type references

This commit is contained in:
Doug Hellmann 2013-01-18 16:17:44 -05:00
parent 1deb93688e
commit 003fed76a3

View File

@ -408,3 +408,22 @@ class TestTypes(unittest.TestCase):
assert types.binary.frombasetype(None) is None
encoded = base64.encodestring('abcdef')
assert types.binary.frombasetype(encoded) == 'abcdef'
def test_wsattr_weakref_datatype(self):
# If the datatype inside the wsattr ends up a weakref, it
# should be converted to the real type when accessed again by
# the property getter.
import weakref
a = types.wsattr(int)
a.datatype = weakref.ref(int)
assert a.datatype is int
def test_wsattr_list_datatype(self):
# If the datatype inside the wsattr ends up a list of weakrefs
# to types, it should be converted to the real types when
# accessed again by the property getter.
import weakref
a = types.wsattr(int)
a.datatype = [weakref.ref(int)]
assert isinstance(a.datatype, list)
assert a.datatype[0] is int