當前位置: 首頁>>代碼示例>>Python>>正文


Python runtime.OMetaBase類代碼示例

本文整理匯總了Python中ometa.runtime.OMetaBase的典型用法代碼示例。如果您正苦於以下問題:Python OMetaBase類的具體用法?Python OMetaBase怎麽用?Python OMetaBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了OMetaBase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_listpattern

 def test_listpattern(self):
     """
     L{OMetaBase.rule_listpattern} matches contents of lists.
     """
     o = OMetaBase([["a"]], tree=True)
     v, e = o.listpattern(lambda: o.exactly("a"))
     self.assertEqual((v, e), (["a"], ParseError("a", 0, None)))
開發者ID:jballard1991,項目名稱:software,代碼行數:7,代碼來源:test_runtime.py

示例2: test_predSuccess

    def test_predSuccess(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        v, e = o.pred(lambda: (True, ParseError(o.input, 0, None)))
        self.assertEqual((v, e), (True, ParseError(o.input, 0, None)))
開發者ID:jballard1991,項目名稱:software,代碼行數:8,代碼來源:test_runtime.py

示例3: test_digit

 def test_digit(self):
     """
     L{OMetaBase.rule_digit} matches digits.
     """
     o = OMetaBase("1a")
     v, e = o.rule_digit()
     self.assertEqual((v, e), ("1", ParseError("1a", 0, None)))
     exc = self.assertRaises(ParseError, o.rule_digit)
     self.assertEqual(exc, ParseError(o.input, 1, expected("digit")))
開發者ID:abenassi,項目名稱:parsley,代碼行數:9,代碼來源:test_runtime.py

示例4: test_many

    def test_many(self):
        """
        L{OMetaBase.many} returns a list of parsed values and the error that
        caused the end of the loop.
        """

        data = "ooops"
        o = OMetaBase(data)
        self.assertEqual(o.many(lambda: o.rule_exactly("o")), (["o"] * 3, ParseError(o.input, 3, expected(None, "o"))))
開發者ID:jballard1991,項目名稱:software,代碼行數:9,代碼來源:test_runtime.py

示例5: test_predFailure

    def test_predFailure(self):
        """
        L{OMetaBase.pred} returns True and empty error info on success.
        """

        o = OMetaBase("")
        with self.assertRaises(ParseError) as e:
            o.pred(lambda: (False, ParseError(o.input, 0, None)))
        self.assertEqual(e.exception, ParseError(o.input, 0, None))
開發者ID:jballard1991,項目名稱:software,代碼行數:9,代碼來源:test_runtime.py

示例6: test_letter

 def test_letter(self):
     """
     L{OMetaBase.rule_letter} matches letters.
     """
     o = OMetaBase("a1")
     v, e = o.rule_letter()
     self.assertEqual((v, e), ("a", ParseError(o.input, 0, None)))
     with self.assertRaises(ParseError) as e:
         o.rule_letter()
     self.assertEqual(e.exception, ParseError(o.input, 1, expected("letter")))
開發者ID:jballard1991,項目名稱:software,代碼行數:10,代碼來源:test_runtime.py

示例7: test_spaces

    def test_spaces(self):
        """
        L{OMetaBase.rule_spaces} provides error information.
        """

        data = "  xyz"
        o = OMetaBase(data)
        v, e = o.rule_spaces()

        self.assertEqual(e[0], 2)
開發者ID:jballard1991,項目名稱:software,代碼行數:10,代碼來源:test_runtime.py

示例8: test_end

 def test_end(self):
     """
     L{OMetaBase.rule_end} matches the end of input and raises L{ParseError}
     if input is left.
     """
     o = OMetaBase("abc")
     exc = self.assertRaises(ParseError, o.rule_end)
     self.assertEqual(exc, ParseError(o.input, 1, None))
     o.many(o.rule_anything)
     self.assertEqual(o.rule_end(), (True, ParseError("abc", 3, None)))
開發者ID:abenassi,項目名稱:parsley,代碼行數:10,代碼來源:test_runtime.py

示例9: test_tokenFailed

 def test_tokenFailed(self):
     """
     On failure, L{OMetaBase.rule_token} produces an error indicating the
     position where match failure occurred and the expected character.
     """
     data = "foozle"
     o = OMetaBase(data)
     with self.assertRaises(ParseError) as e:
         o.rule_token("fog")
     self.assertEqual(e.exception[0], 2)
     self.assertEqual(e.exception[1], expected("token", "fog"))
開發者ID:jballard1991,項目名稱:software,代碼行數:11,代碼來源:test_runtime.py

示例10: test_notError

    def test_notError(self):
        """
        When L{OMetaBase._not} fails, its error contains the current
        input position and no error info.
        """

        data = "xy"
        o = OMetaBase(data)
        exc = self.assertRaises(ParseError, o._not, lambda: o.exactly("x"))
        self.assertEqual(exc.args[0], 1)
        self.assertEqual(exc.args[1], None)
開發者ID:abenassi,項目名稱:parsley,代碼行數:11,代碼來源:test_runtime.py

示例11: test_exactly_multi

    def test_exactly_multi(self):
        """
        L{OMetaBase.rule_exactly} returns the requested item from the input
        string along with its position, if it's there.
        """

        data = "foo"
        o = OMetaBase(data)
        v, e = o.rule_exactly("fo")
        self.assertEqual(v, "fo")
        self.assertEqual(e[0], 0)
開發者ID:jballard1991,項目名稱:software,代碼行數:11,代碼來源:test_runtime.py

示例12: test_letterOrDigit

 def test_letterOrDigit(self):
     """
     L{OMetaBase.rule_letterOrDigit} matches alphanumerics.
     """
     o = OMetaBase("[email protected]")
     v, e = o.rule_letterOrDigit()
     self.assertEqual((v, e), ("a", ParseError(None, 0, None)))
     v, e = o.rule_letterOrDigit()
     self.assertEqual((v, e), ("1", ParseError(None, 1, None)))
     with self.assertRaises(ParseError) as e:
         o.rule_letterOrDigit()
     self.assertEqual(e.exception, ParseError(o.input, 2, expected("letter or digit")))
開發者ID:jballard1991,項目名稱:software,代碼行數:12,代碼來源:test_runtime.py

示例13: test_orErrorTie

    def test_orErrorTie(self):
        """
        When branches of L{OMetaBase._or} produce errors that tie for rightmost
        position, they are merged.
        """

        data = "foozle"
        o = OMetaBase(data)

        v, e = o._or([lambda: o.token("fog"), lambda: o.token("foz"), lambda: o.token("f")])
        self.assertEqual(e[0], 2)
        self.assertEqual(e[1], [expected("token", "fog")[0], expected("token", "foz")[0]])
開發者ID:jballard1991,項目名稱:software,代碼行數:12,代碼來源:test_runtime.py

示例14: test_orFalseSuccess

    def test_orFalseSuccess(self):
        """
        When a failing branch of L{OMetaBase._or} gets further than a
        succeeding one, its error is returned instead of the success branch's.
        """

        data = "foozle"
        o = OMetaBase(data)

        v, e = o._or([lambda: o.token("fog"), lambda: o.token("foozik"), lambda: o.token("f")])
        self.assertEqual(e[0], 4)
        self.assertEqual(e[1], expected("token", "foozik"))
開發者ID:jballard1991,項目名稱:software,代碼行數:12,代碼來源:test_runtime.py

示例15: test_anything

    def test_anything(self):
        """
        L{OMetaBase.rule_anything} returns each item from the input
        along with its position.
        """

        data = "foo"
        o = OMetaBase(data)

        for i, c in enumerate(data):
            v, e = o.rule_anything()
            self.assertEqual((c, i), (v, e[0]))
開發者ID:jballard1991,項目名稱:software,代碼行數:12,代碼來源:test_runtime.py


注:本文中的ometa.runtime.OMetaBase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。