def test_raises(self): accu = [] def accumulate(key): if key == "fail": raise Exception("noooo") else: accu.append(key) return "|%s|" % key a, b, c = funbind(accumulate) self.assertEqual(a, "|a|") self.assertEqual(b, "|b|") self.assertEqual(c, "|c|") self.assertEqual(accu, ["a", "b", "c"]) accu = [] try: x, fail, z = funbind(accumulate) except Exception: pass else: self.assertTrue(False) self.assertEqual(accu, ["x"]) try: self.assertFalse(x) self.assertTrue(False) except NameError: pass except: self.assertTrue(False) else: self.assertTrue(False) try: self.assertFalse(fail) self.assertTrue(False) except NameError: pass except: self.assertTrue(False) else: self.assertTrue(False) try: self.assertFalse(z) self.assertTrue(False) except NameError: pass except: self.assertTrue(False) else: self.assertTrue(False)
def test_binding(self): accu = [] def accumulate(key): accu.append(key) return "|%s|" % key a, b, c = funbind(accumulate) self.assertEqual(a, "|a|") self.assertEqual(b, "|b|") self.assertEqual(c, "|c|") self.assertEqual(accu, ["a", "b", "c"])
def test_global(self): accu = [] def accumulate(name): accu.append(name) return "|%s|" % name global x a, x = funbind(accumulate) self.assertEqual(accu, ["a", "x"]) self.assertEqual(a, "|a|") self.assertEqual(x, "|x|") self.assertEqual(x, globals()["x"])
def bad_times(): noop(*funbind(bad_data))
def bad_times(): a, (b, c) = funbind(bad_data)
def bad_times(): a = funbind(bad_data)
def bad_times(): return funbind(bad_data)