当前位置: 首页>>代码示例>>Python>>正文


Python testutils.tokenize_str函数代码示例

本文整理汇总了Python中pylint.testutils.tokenize_str函数的典型用法代码示例。如果您正苦于以下问题:Python tokenize_str函数的具体用法?Python tokenize_str怎么用?Python tokenize_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了tokenize_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testTrailingCommaGood

    def testTrailingCommaGood(self):
        with self.assertNoMessages():
            self.checker.process_tokens(tokenize_str('(a, )\n'))
            self.checker.process_tokens(tokenize_str('(a,)\n'))

        self.checker.config.no_space_check = []
        with self.assertNoMessages():
            self.checker.process_tokens(tokenize_str('(a,)\n'))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:8,代码来源:unittest_checker_format.py

示例2: testEmptyLines

    def testEmptyLines(self):
        self.checker.config.no_space_check = []
        with self.assertAddsMessages(
            Message('trailing-whitespace', line=2)):
            self.checker.process_tokens(tokenize_str('a = 1\n  \nb = 2\n'))

        self.checker.config.no_space_check = ['empty-line']
        with self.assertNoMessages():
            self.checker.process_tokens(tokenize_str('a = 1\n  \nb = 2\n'))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:9,代码来源:unittest_checker_format.py

示例3: test_check_bad_coment

 def test_check_bad_coment(self):
     with self.assertAddsMessages(
         Message('wrong-spelling-in-comment', line=1,
                 args=('coment', '# bad coment',
                       '      ^^^^^^',
                       "comet' or 'comment' or 'moment' or 'foment"))):
         self.checker.process_tokens(tokenize_str("# bad coment"))
开发者ID:glennmatthews,项目名称:pylint,代码行数:7,代码来源:unittest_checker_spelling.py

示例4: test_check_bad_coment

 def test_check_bad_coment(self):
     suggestions = self.checker.spelling_dict.suggest('coment')[:4]
     with self.assertAddsMessages(
         Message('wrong-spelling-in-comment', line=1,
                 args=('coment', '# bad coment',
                       '      ^^^^^^',
                       "'{0}'".format("' or '".join(suggestions))))):
         self.checker.process_tokens(tokenize_str("# bad coment"))
开发者ID:pennyarcade,项目名称:py_pov,代码行数:8,代码来源:unittest_checker_spelling.py

示例5: testFuturePrintStatementWithoutParensWarning

    def testFuturePrintStatementWithoutParensWarning(self):
        code = """from __future__ import print_function
print('Hello world!')
"""
        tree = astroid.parse(code)
        with self.assertNoMessages():
            self.checker.process_module(tree)
            self.checker.process_tokens(tokenize_str(code))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:8,代码来源:unittest_checker_format.py

示例6: test_old_octal_literal

    def test_old_octal_literal(self):
        for octal in ("045", "055", "075", "077", "076543"):
            self._test_token_message(octal, "old-octal-literal")

        # Make sure we are catching only octals.
        for non_octal in ("45", "00", "085", "08", "1"):
            tokens = testutils.tokenize_str(non_octal)
            with self.assertNoMessages():
                self.checker.process_tokens(tokens)
开发者ID:Vauxoo,项目名称:pylint,代码行数:9,代码来源:unittest_checker_python3.py

示例7: testOperatorSpacingGood

 def testOperatorSpacingGood(self):
     good_cases = [
         'a = b\n'
         'a < b\n'
         'a\n< b\n',
         ]
     with self.assertNoMessages():
         for code in good_cases:
             self.checker.process_tokens(tokenize_str(code))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:9,代码来源:unittest_checker_format.py

示例8: testParenthesesGood

 def testParenthesesGood(self):
     good_cases = [
         '(a)\n',
         '(a * (b + c))\n',
         '(#\n    a)\n',
         ]
     with self.assertNoMessages():
         for code in good_cases:
             self.checker.process_tokens(tokenize_str(code))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:9,代码来源:unittest_checker_format.py

示例9: testKeywordSpacingBad

    def testKeywordSpacingBad(self):
        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'before', 'keyword argument assignment',
                          '(foo =bar)\n     ^'))):
            self.checker.process_tokens(tokenize_str('(foo =bar)\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'after', 'keyword argument assignment',
                          '(foo= bar)\n    ^'))):
            self.checker.process_tokens(tokenize_str('(foo= bar)\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'around', 'keyword argument assignment',
                          '(foo = bar)\n     ^'))):
            self.checker.process_tokens(tokenize_str('(foo = bar)\n'))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:18,代码来源:unittest_checker_format.py

示例10: testOperatorSpacingBad

    def testOperatorSpacingBad(self):
        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('Exactly one', 'required', 'before', 'comparison', 'a< b\n ^'))):
            self.checker.process_tokens(tokenize_str('a< b\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('Exactly one', 'required', 'after', 'comparison', 'a <b\n  ^'))):
            self.checker.process_tokens(tokenize_str('a <b\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('Exactly one', 'required', 'around', 'comparison', 'a<b\n ^'))):
            self.checker.process_tokens(tokenize_str('a<b\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('Exactly one', 'required', 'around', 'comparison', 'a<  b\n ^'))):
            self.checker.process_tokens(tokenize_str('a<  b\n'))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:20,代码来源:unittest_checker_format.py

示例11: testParenthesesBad

    def testParenthesesBad(self):
        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'after', 'bracket', '( a)\n^'))):
            self.checker.process_tokens(tokenize_str('( a)\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'before', 'bracket', '(a )\n   ^'))):
            self.checker.process_tokens(tokenize_str('(a )\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'before', 'bracket', 'foo (a)\n    ^'))):
            self.checker.process_tokens(tokenize_str('foo (a)\n'))

        with self.assertAddsMessages(
            Message('bad-whitespace', line=1,
                    args=('No', 'allowed', 'before', 'bracket', '{1: 2} [1]\n       ^'))):
            self.checker.process_tokens(tokenize_str('{1: 2} [1]\n'))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:20,代码来源:unittest_checker_format.py

示例12: testSpacesAllowedInsideSlices

 def testSpacesAllowedInsideSlices(self):
     good_cases = [
         '[a:b]\n',
         '[a : b]\n',
         '[a : ]\n',
         '[:a]\n',
         '[:]\n',
         '[::]\n',
         ]
     with self.assertNoMessages():
         for code in good_cases:
             self.checker.process_tokens(tokenize_str(code))
开发者ID:DonJayamanne,项目名称:pylint,代码行数:12,代码来源:unittest_checker_format.py

示例13: testKeywordSpacingGood

 def testKeywordSpacingGood(self):
     with self.assertNoMessages():
         self.checker.process_tokens(tokenize_str('foo(foo=bar)\n'))
         self.checker.process_tokens(tokenize_str('foo(foo: int = bar)\n'))
         self.checker.process_tokens(tokenize_str('foo(foo: Dict[int, str] = bar)\n'))
         self.checker.process_tokens(tokenize_str('foo(foo: \'int\' = bar)\n'))
         self.checker.process_tokens(tokenize_str('foo(foo: Dict[int, \'str\'] = bar)\n'))
         self.checker.process_tokens(tokenize_str('lambda x=1: x\n'))
开发者ID:vauxoo-dev,项目名称:pylint,代码行数:8,代码来源:unittest_checker_format.py

示例14: testCheckKeywordParensHandlesValidCases

 def testCheckKeywordParensHandlesValidCases(self):
     self.checker._keywords_with_parens = set()
     cases = [
         'if foo:',
         'if foo():',
         'if (x and y) or z:',
         'assert foo()',
         'assert ()',
         'if (1, 2) in (3, 4):',
         'if (a or b) in c:',
         'return (x for x in x)',
         'if (x for x in x):',
         'for x in (x for x in x):',
         'not (foo or bar)',
         'not (foo or bar) and baz',
         ]
     with self.assertNoMessages():
         for code in cases:
             self.checker._check_keyword_parentheses(tokenize_str(code), 0)
开发者ID:DonJayamanne,项目名称:pylint,代码行数:19,代码来源:unittest_checker_format.py

示例15: testCheckKeywordParensHandlesUnnecessaryParens

 def testCheckKeywordParensHandlesUnnecessaryParens(self):
     self.checker._keywords_with_parens = set()
     cases = [
         (Message('superfluous-parens', line=1, args='if'),
          'if (foo):', 0),
         (Message('superfluous-parens', line=1, args='if'),
          'if ((foo, bar)):', 0),
         (Message('superfluous-parens', line=1, args='if'),
          'if (foo(bar)):', 0),
         (Message('superfluous-parens', line=1, args='return'),
          'return ((x for x in x))', 0),
         (Message('superfluous-parens', line=1, args='not'),
          'not (foo)', 0),
         (Message('superfluous-parens', line=1, args='not'),
          'if not (foo):', 1),
         (Message('superfluous-parens', line=1, args='if'),
          'if (not (foo)):', 0),
         (Message('superfluous-parens', line=1, args='not'),
          'if (not (foo)):', 2),
         ]
     for msg, code, offset in cases:
         with self.assertAddsMessages(msg):
             self.checker._check_keyword_parentheses(tokenize_str(code), offset)
开发者ID:DonJayamanne,项目名称:pylint,代码行数:23,代码来源:unittest_checker_format.py


注:本文中的pylint.testutils.tokenize_str函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。