Ejemplo n.º 1
0
 def test_get_func_module_name(self):
     """ Can we get the module in which a function object is defined?
     """
     module = objects.__name__
     self.assertEqual(get_func_module_name(objects.create_foo), module)
     self.assertEqual(get_func_module_name(objects.Foo), module)
     self.assertEqual(get_func_module_name(objects.Foo.do_sum), module)
     self.assertEqual(get_func_module_name(objects.Foo().do_sum), module)
Ejemplo n.º 2
0
    def test_get_object(self):
        """ Can we get a tracked object by ID?
        """
        tracker = ObjectTracker()
        foo = objects.Foo()
        foo_id = tracker.track(foo)
        self.assertTrue(tracker.is_tracked(foo))
        self.assertEqual(tracker.get_object(foo_id), foo)

        other_id = tracker.get_id(foo)
        self.assertEqual(other_id, foo_id)
Ejemplo n.º 3
0
    def test_gc_cleanup(self):
        """ Does the tracker clean up when an object is garbage collected?
        """
        tracker = ObjectTracker()
        foo = objects.Foo()
        foo_id = tracker.track(foo)
        self.assertTrue(tracker.is_tracked(foo))

        del foo
        gc.collect()
        self.assertFalse(tracker.get_object(foo_id))
Ejemplo n.º 4
0
    def test_is_trackable(self):
        """ Are objects correctly identified as trackable or not trackable?
        """
        is_trackable = ObjectTracker.is_trackable
        self.assertFalse(is_trackable(None))
        self.assertFalse(is_trackable(0))
        self.assertFalse(is_trackable('foo'))

        foo = objects.Foo()
        self.assertTrue(is_trackable(foo))
        self.assertFalse(is_trackable(foo.do_sum))