Beispiel #1
0
 def testThrow(self):
     g = AllGenerator((m1, m2), (), {})
     try:
         g.throw(NameError("A"))
         self.fail()
     except NameError, e:
         self.assertEquals("A", str(e))
 def testSendError(self):
     g = AllGenerator((), (), {})
     try:
         g.send("Value")
         self.fail()
     except TypeError, e:
         self.assertEquals("can't send non-None value to a just-started generator", str(e))
 def testSendValueNotAllowed(self):
     g = AllGenerator((m1,m2), (), {})
     g.next()
     try:
         g.send("s1")
         self.fail()
     except AssertionError, e:
         self.assertEquals("%s returned 's1'" % m1, str(e))
Beispiel #4
0
 def testSendError(self):
     g = AllGenerator((), (), {})
     try:
         g.send("Value")
         self.fail()
     except TypeError, e:
         self.assertEquals(
             "can't send non-None value to a just-started generator",
             str(e))
    def testDeclineMessage(self):
        g = AllGenerator((m1, m2), (), {})
        g.next()
        r = g.throw(DeclineMessage) # effectively skips one result
        self.assertEquals("m2", r)

        g = AllGenerator((m1, m3, m2), (), {})
        r = list(g)
        self.assertEquals(["m1", "m2"], r)
Beispiel #6
0
 def testCreateAllGeneratorWithWrongArgs(self):
     try:
         AllGenerator()
         self.fail()
     except TypeError, e:
         self.assertEquals("Required argument 'methods' (pos 1) not found",
                           str(e))
Beispiel #7
0
    def testDeclineMessage(self):
        g = AllGenerator((m1, m2), (), {})
        g.next()
        r = g.throw(DeclineMessage)  # effectively skips one result
        self.assertEquals("m2", r)

        g = AllGenerator((m1, m3, m2), (), {})
        r = list(g)
        self.assertEquals(["m1", "m2"], r)
Beispiel #8
0
    def testAllGeneratorWithCompose(self):
        from weightless.core import compose

        def f1():
            yield 3

        def f2():
            yield f1()

        g = AllGenerator((f2, ), (), {})
        c = compose(g)
        self.assertEquals([3], list(c))
Beispiel #9
0
 def testSendValueNotAllowed(self):
     g = AllGenerator((m1, m2), (), {})
     g.next()
     try:
         g.send("s1")
         self.fail()
     except AssertionError, e:
         self.assertEquals("%s returned 's1'" % m1, str(e))
Beispiel #10
0
class Observable_C_Test(TestCase):
    def testImportAllGenerator(self):
        from weightless.core.ext import AllGenerator
        self.assertTrue(AllGenerator is not None)

    def testCreateAllGeneratorWithWrongArgs(self):
        try:
            AllGenerator()
            self.fail()
        except TypeError, e:
            self.assertEquals("Required argument 'methods' (pos 1) not found",
                              str(e))

        try:
            AllGenerator({})
            self.fail()
        except TypeError, e:
            self.assertEquals("__new__() argument 1 must be tuple, not dict",
                              str(e))
Beispiel #11
0
 def testTwoMethods(self):
     g = AllGenerator((m1, m2), (), {})
     r = list(g)
     self.assertEquals(["m1", "m2"], r)
Beispiel #12
0
 def testOneMethod(self):
     g = AllGenerator((m1, ), (), {})
     r = list(g)
     self.assertEquals(["m1"], r)
Beispiel #13
0
 def testEmpty(self):
     g = AllGenerator((), (), {})
     r = list(g)
     self.assertEquals([], r)
Beispiel #14
0
 def testAllGeneratorIsCallable(self):
     g = AllGenerator((m1, ), (), {})
     r = g()
     self.assertEquals("m1", r)
Beispiel #15
0
 def testArgs(self):
     g = AllGenerator((m4, m5), (1, ), {"a": "A"})
     r = list(g)
     self.assertEquals([1, "A"], r)
 def testThrow(self):
     g = AllGenerator((m1, m2), (), {})
     try: g.throw(NameError("A")); self.fail()
     except NameError, e:
         self.assertEquals("A", str(e))
Beispiel #17
0
 def testCreateAllGenerator(self):
     g = AllGenerator((), (), {})
     self.assertTrue(g)
Beispiel #18
0
 def all(self, *args, **kwargs):
     return AllGenerator(self.methods, args, kwargs)
Beispiel #19
0
        try:
            AllGenerator()
            self.fail()
        except TypeError, e:
            self.assertEquals("Required argument 'methods' (pos 1) not found",
                              str(e))

        try:
            AllGenerator({})
            self.fail()
        except TypeError, e:
            self.assertEquals("__new__() argument 1 must be tuple, not dict",
                              str(e))

        try:
            AllGenerator(())
            self.fail()
        except TypeError, e:
            self.assertEquals("Required argument 'args' (pos 2) not found",
                              str(e))

        try:
            AllGenerator((), {})
            self.fail()
        except TypeError, e:
            self.assertEquals("__new__() argument 2 must be tuple, not dict",
                              str(e))

        try:
            AllGenerator((), ())
            self.fail()