예제 #1
0
    def test_require_double_docstring_double_present(self):
        options = ['--inline-quotes=single', '--multiline-quotes=single', '--docstring-quotes=double']

        result = run_flake8(get_absolute_path('data/docstring_doubles.py'), options)
        self.assertEqual(result, [
            {'col': 1, 'line': 5, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 5, 'line': 16, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 21, 'line': 21, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        result = run_flake8(get_absolute_path('data/docstring_doubles_module_multiline.py'), options)
        self.assertEqual(result, [
            {'col': 1, 'line': 4, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        result = run_flake8(get_absolute_path('data/docstring_doubles_module_singleline.py'), options)
        self.assertEqual(result, [
            {'col': 1, 'line': 2, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        result = run_flake8(get_absolute_path('data/docstring_doubles_class.py'), options)
        self.assertEqual(result, [
            {'col': 5, 'line': 3, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 23, 'line': 5, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        result = run_flake8(get_absolute_path('data/docstring_doubles_function.py'), options)
        self.assertEqual(result, [
            {'col': 5, 'line': 3, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 5, 'line': 11, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 39, 'line': 15, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 5, 'line': 17, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 5, 'line': 21, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])
예제 #2
0
    def test_require_double_docstring_double_present(self):
        class Options():
            inline_quotes = 'single'
            multiline_quotes = 'single'
            docstring_quotes = 'double'
        QuoteChecker.parse_options(Options)

        multiline_checker = QuoteChecker(
            None,
            filename=get_absolute_path('data/docstring_doubles.py')
        )
        self.assertEqual(list(multiline_checker.get_quotes_errors(multiline_checker.get_file_contents())), [
            {'col': 0, 'line': 5, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 4, 'line': 16, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 20, 'line': 21, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 8, 'line': 30, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 12, 'line': 35, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        multiline_checker = QuoteChecker(
            None,
            filename=get_absolute_path('data/docstring_doubles_module_multiline.py')
        )
        self.assertEqual(list(multiline_checker.get_quotes_errors(multiline_checker.get_file_contents())), [
            {'col': 0, 'line': 4, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 0, 'line': 9, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        multiline_checker = QuoteChecker(
            None,
            filename=get_absolute_path('data/docstring_doubles_module_singleline.py')
        )
        self.assertEqual(list(multiline_checker.get_quotes_errors(multiline_checker.get_file_contents())), [
            {'col': 0, 'line': 2, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 0, 'line': 6, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        multiline_checker = QuoteChecker(
            None,
            filename=get_absolute_path('data/docstring_doubles_class.py')
        )
        self.assertEqual(list(multiline_checker.get_quotes_errors(multiline_checker.get_file_contents())), [
            {'col': 4, 'line': 3, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 22, 'line': 5, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])

        multiline_checker = QuoteChecker(
            None,
            filename=get_absolute_path('data/docstring_doubles_function.py')
        )
        self.assertEqual(list(multiline_checker.get_quotes_errors(multiline_checker.get_file_contents())), [
            {'col': 4, 'line': 3, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 4, 'line': 11, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 38, 'line': 15, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 4, 'line': 17, 'message': 'Q001 Remove bad quotes from multiline string'},
            {'col': 4, 'line': 21, 'message': 'Q001 Remove bad quotes from multiline string'},
        ])
예제 #3
0
 def test_get_docstring_tokens_singles(self):
     with open(get_absolute_path('data/docstring_singles.py'), 'r') as f:
         docstring_tokens = {t.string for t in get_docstring_tokens([], tokenize.generate_tokens(f.readline))}
     self.assertEqual(docstring_tokens, {
         "'''\nSingle quotes multiline module docstring\n'''",
         "'''\n    Single quotes multiline class docstring\n    '''",
         "'''\n        Single quotes multiline function docstring\n        '''",
     })
 def test_get_docstring_tokens_singles(self):
     with open(get_absolute_path('data/docstring_singles.py'), 'r') as f:
         tokens = [Token(t) for t in tokenize.generate_tokens(f.readline)]
     docstring_tokens = {t.string for t in get_docstring_tokens(tokens)}
     self.assertEqual(docstring_tokens, {
         "'''\nSingle quotes multiline module docstring\n'''",
         "'''\n    Single quotes multiline class docstring\n    '''",
         "'''\n        Single quotes multiline function docstring\n        '''",
     })
예제 #5
0
 def test_get_docstring_tokens_doubles(self):
     with open(get_absolute_path('data/docstring_doubles.py'), 'r') as f:
         tokens = [Token(t) for t in tokenize.generate_tokens(f.readline)]
     docstring_tokens = {t.string for t in get_docstring_tokens(tokens)}
     self.assertEqual(
         docstring_tokens, {
             '"""\nDouble quotes multiline module docstring\n"""',
             '"""\n    Double quotes multiline class docstring\n    """',
             '"""\n        Double quotes multiline function docstring\n        """',
         })
 def _get_docstring_tokens(self, filename):
     with open(get_absolute_path(filename), 'r') as f:
         tokens = [Token(t) for t in tokenize.generate_tokens(f.readline)]
     return get_docstring_tokens(tokens)
예제 #7
0
 def _get_docstring_tokens(self, filename):
     with open(get_absolute_path(filename), 'r') as f:
         tokens = [Token(t) for t in tokenize.generate_tokens(f.readline)]
     return get_docstring_tokens(tokens)
예제 #8
0
 def _get_docstring_tokens(self, filename):
     with open(get_absolute_path(filename), 'r') as f:
         return get_docstring_tokens([], tokenize.generate_tokens(f.readline))