コード例 #1
0
ファイル: test.py プロジェクト: johnthagen/flake8-strings
class StringCheckerTestCase(unittest.TestCase):
    def setUp(self):
        file_name = 'tests/S800.py'
        with open(file_name, mode='rt') as file:
            tree = ast.parse(file.read())
            self.checker = StringChecker(tree, file_name)

    def test_single(self):
        self.checker.string_quote = StringQuotes.single
        errors = []
        for error in self.checker.run():
            errors.append(error[:2])

        self.assertEqual(
            errors,
            [(1, 9), (7, 15), (16, 13), (19, 21), (22, 14), (25, 22), (28, 17), (31, 25)])

    def test_double(self):
        self.checker.string_quote = StringQuotes.double
        errors = []
        for error in self.checker.run():
            errors.append(error[:2])

        self.assertEqual(
            errors,
            [(2, 9), (8, 15), (17, 13), (20, 21), (23, 14), (26, 22), (29, 17), (32, 25)])
コード例 #2
0
ファイル: test.py プロジェクト: johnthagen/flake8-strings
def line_is_valid(physical_line,  # type: str
                  string_quotes  # type: str
                  ):
    # type: () -> bool
    """Validates the string and bytes nodes in a line have correct string quotes.

    Returns:
        Whether the node's in the line have valid string quotes.
    """
    module = ast.parse(physical_line)
    for node in ast.walk(module):
        if isinstance(node, ast.Str) or isinstance(node, ast.Bytes):
            return StringChecker.string_quotes_are_valid(node,
                                                         string_quotes,
                                                         physical_line)
コード例 #3
0
ファイル: test.py プロジェクト: johnthagen/flake8-strings
 def setUp(self):
     file_name = 'tests/S800.py'
     with open(file_name, mode='rt') as file:
         tree = ast.parse(file.read())
         self.checker = StringChecker(tree, file_name)