def test_exception_during_destruction(self): # In experiments, the order of items in the dict was 'a', 'c', 'b', 'd'. # The expected output of this test will change if this does not hold. self.assertEquals(["a", "c", "b", "d"], {"a": 0, "b": 0, "c": 0, "d": 0}.keys()) TestObj.clear_instances() objects = { "a": wrapper.defname(ThrowsOnClose, args=["a"], method_on_close="close"), "c": wrapper.defname(TestObj, args=["c"], method_on_close="close"), "b": wrapper.defname(TestObj, args=["b"], method_on_close="close"), "d": wrapper.defname(TestObj, args=["d"]), } self.assertEquals(0, len(wrapper._local.key_stack)) env = Environment(objects, {}) with self.assertRaises(RuntimeError) as cm: env.close() self.assertEquals("ThrowsOnClose", cm.exception.args[0]) self.assertEquals(0, len(wrapper._local.key_stack)) self.assertEquals(True, env.globals["a"].initialized) self.assertEquals(False, env.globals["a"].closed) self.assertEquals(True, env.globals["c"].initialized) self.assertEquals(True, env.globals["c"].closed) self.assertEquals(True, env.globals["b"].initialized) self.assertEquals(True, env.globals["b"].closed) self.assertEquals(True, env.globals["d"].initialized) self.assertEquals(False, env.globals["d"].closed)
def test_basic(self): self.assertEquals(0, len(wrapper._local.key_stack)) environment = Environment({}, {"x": 5}) self.assertEquals(1, len(wrapper._local.key_stack)) environment.close() self.assertTrue("Good. No exceptions thrown.") self.assertEquals(0, len(wrapper._local.key_stack)) self.assertEquals(5, environment.globals["x"])
def test_simple_objects(self): objects = {"a": wrapper.defname(TestObj), "b": wrapper.defname(TestObj, method_on_close="close")} self.assertEquals(0, len(wrapper._local.key_stack)) environment = Environment(objects, {}) self.assertEquals(True, environment.globals["a"].initialized) self.assertEquals(False, environment.globals["a"].closed) self.assertEquals(True, environment.globals["b"].initialized) self.assertEquals(False, environment.globals["b"].closed) environment.close() self.assertEquals(True, environment.globals["a"].initialized) self.assertEquals(False, environment.globals["a"].closed) self.assertEquals(True, environment.globals["b"].initialized) self.assertEquals(True, environment.globals["b"].closed) self.assertEquals(0, len(wrapper._local.key_stack))