示例#1
0
    def testObject(self):
        # Test ob() match pattern
        class Book:
            def __init__(self,
                         title,
                         author,
                         year=None,
                         publisher=None,
                         location=None):
                self.title = title
                self.author = author
                self.year = year
                self.publisher = publisher
                self.location = location

        class Film:
            pass

        jazz = Book("Tales of the Jazz Age", "F. Scott Fitzgerald", 1922)
        selfish = Book("The Selfish Gene", "Richard Dawkins", 1976, "Oxford",
                       "London")
        fifth = Book("Fifth Business", "Robertson Davies", 1970, "Penguin",
                     "Toronto")

        cv = CapturedValues()
        assert match(ob(Book, title=cv.title, author=cv.author), jazz)
        self.assertEquals("Tales of the Jazz Age", cv.title)
        self.assertEquals("F. Scott Fitzgerald", cv.author)

        cv = CapturedValues()
        assert not match(ob(Book, abc=cv.abc), jazz)

        cv = CapturedValues()
        assert match(
            ob(Book,
               title=cv.title,
               author="Richard Dawkins",
               year=pred(lambda x: x > 1970)), selfish)
        self.assertEquals("The Selfish Gene", cv.title)

        cv = CapturedValues()
        assert match(ob(title=str, author=str, year=1970), fifth)

        cv = CapturedValues()
        assert not match(
            ob(Book,
               title=cv.title,
               author="Robertson Davies",
               year=pred(lambda x: x > 1970)), selfish)

        assert not match(ob(Book), Film())
    def testObject(self):
        # Test ob() match pattern
        class Book:
            def __init__(self, title, author, year=None, publisher=None,
              location=None):
                self.title = title
                self.author = author
                self.year = year
                self.publisher = publisher
                self.location = location

        class Film:
            pass

        jazz = Book("Tales of the Jazz Age", "F. Scott Fitzgerald", 1922)
        selfish = Book("The Selfish Gene", "Richard Dawkins",
            1976, "Oxford", "London")
        fifth = Book("Fifth Business", "Robertson Davies",
            1970, "Penguin", "Toronto")

        cv = CapturedValues()
        assert match(ob(Book, title=cv.title, author=cv.author), jazz)
        self.assertEquals("Tales of the Jazz Age", cv.title)
        self.assertEquals("F. Scott Fitzgerald", cv.author)
        
        cv = CapturedValues()
        assert not match(ob(Book, abc=cv.abc), jazz)

        cv = CapturedValues()
        assert match(ob(Book, title=cv.title, author="Richard Dawkins",
          year=pred(lambda x: x > 1970)), selfish)
        self.assertEquals("The Selfish Gene", cv.title)

        cv = CapturedValues()
        assert match(ob(title=str, author=str, year=1970), fifth)

        cv = CapturedValues()
        assert not match(ob(Book, title=cv.title, author="Robertson Davies",
          year=pred(lambda x: x > 1970)), selfish)

        assert not match(ob(Book), Film())
 def testPredicate(self):
     # Test pred() match pattern
     assert match(pred(lambda x: x > 4), 7)
     assert not match(pred(lambda x: x > 4), 2)
示例#4
0
 def testPredicate(self):
     # Test pred() match pattern
     assert match(pred(lambda x: x > 4), 7)
     assert not match(pred(lambda x: x > 4), 2)