def test_refcount(self):
        obj = "my very large and random string with numbers 1234"

        rc = sys.getrefcount(obj)

        # Test nest.front. This doesn't involve returning nests
        # from C++ to Python.
        nest.front((None, obj))
        self.assertEqual(rc, sys.getrefcount(obj))

        nest.front(obj)
        self.assertEqual(rc, sys.getrefcount(obj))

        nest.front((obj, ))
        self.assertEqual(rc, sys.getrefcount(obj))

        nest.front((obj, obj, [obj, {"obj": obj}, obj]))
        self.assertEqual(rc, sys.getrefcount(obj))

        # Test returning nests of Nones.
        nest.map(lambda x: None, (obj, obj, [obj, {"obj": obj}, obj]))
        self.assertEqual(rc, sys.getrefcount(obj))

        # Test returning actual nests.
        nest.map(lambda s: s, obj)
        self.assertEqual(rc, sys.getrefcount(obj))

        nest.map(lambda x: x, {"obj": obj})
        self.assertEqual(rc, sys.getrefcount(obj))

        nest.map(lambda x: x, (obj, ))
        self.assertEqual(rc, sys.getrefcount(obj))

        nest.map(lambda s: s, (obj, obj))
        nest.map(lambda s: s, (obj, obj))
        self.assertEqual(rc, sys.getrefcount(obj))

        n = nest.map(lambda s: s, (obj, ))
        self.assertEqual(rc + 1, sys.getrefcount(obj))
        del n
        self.assertEqual(rc, sys.getrefcount(obj))
 def test_front(self):
     self.assertEqual(nest.front((1, 2, 3)), 1)
     self.assertEqual(nest.front((2, 3)), 2)
     self.assertEqual(nest.front((3, )), 3)