Esempio n. 1
0
    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)
Esempio n. 2
0
    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"])
Esempio n. 3
0
    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"])
Esempio n. 4
0
 def bad_times():
     noop(*funbind(bad_data))
Esempio n. 5
0
 def bad_times():
     a, (b, c) = funbind(bad_data)
Esempio n. 6
0
 def bad_times():
     a = funbind(bad_data)
Esempio n. 7
0
 def bad_times():
     return funbind(bad_data)