示例#1
0
 def test_long_length_good(self):
     long_line = '1234 56189' * 7 + '12345678' + '\n'
     self.file.write(long_line)
     self.file.flush()
     checker = PythonChecker(self.file.name, long_line, self.reporter)
     checker.check_pep8()
     self.assertEqual([], self.reporter.messages)
示例#2
0
 def test_windows_code_without_issues(self):
     self.reporter.call_count = 0
     checker = PythonChecker(
         'bogus', good_python_on_windows, self.reporter)
     checker.check_flakes()
     self.assertEqual([], self.reporter.messages)
     self.assertEqual(0, self.reporter.call_count)
示例#3
0
 def test_code_with_comments(self):
     self.file.write(ugly_style_lines_python)
     self.file.flush()
     checker = PythonChecker(
         self.file.name, ugly_style_lines_python, self.reporter)
     checker.check_pep8()
     self.assertEqual([], self.reporter.messages)
示例#4
0
 def test_code_with_very_bad_SyntaxError(self):
     checker = PythonChecker(
         'bogus', bad_syntax2_python, self.reporter)
     checker.check_flakes()
     expected = [(
         2, 'Could not compile; invalid syntax: def __init__(self, val):')]
     self.assertEqual(expected, self.reporter.messages)
示例#5
0
 def test_code_without_issues(self):
     self.file.write(good_python)
     self.file.flush()
     checker = PythonChecker(
         self.file.name, good_python, self.reporter)
     checker.check_pep8()
     self.assertEqual([], self.reporter.messages)
示例#6
0
 def test_code_ascii_is_not_utf8(self):
     utf8_python = u"a = 'this is utf-8 [\u272a]'"
     checker = PythonChecker('bogus', utf8_python, self.reporter)
     checker.check_text()
     self.assertEqual(
         [(1, 'Non-ascii characer at position 21.')],
         self.reporter.messages)
示例#7
0
 def test_code_with_IndentationError(self):
     checker = PythonChecker(
         'bogus', bad_indentation_python, self.reporter)
     checker.check_flakes()
     expected = [
         (4, 'Could not compile; unindent does not match any '
             'outer indentation level: b = 1')]
     self.assertEqual(expected, self.reporter.messages)
示例#8
0
 def test_code_with_issues(self):
     self.file.write(ugly_style_python)
     self.file.flush()
     checker = PythonChecker(
         self.file.name, ugly_style_python, self.reporter)
     checker.check_pep8()
     self.assertEqual(
         [(4, 'E222 multiple spaces after operator')],
         self.reporter.messages)
示例#9
0
 def test_code_with_IndentationError(self):
     self.file.write(bad_indentation_python)
     self.file.flush()
     checker = PythonChecker(
         self.file.name, bad_indentation_python, self.reporter)
     checker.check_pep8()
     expected = [(
         4, 'unindent does not match any outer indentation level: b = 1')]
     self.assertEqual(expected, self.reporter.messages)
示例#10
0
 def test_bad_syntax(self):
     self.file.write(bad_syntax2_python)
     self.file.flush()
     checker = PythonChecker(
         self.file.name, ugly_style_python, self.reporter)
     checker.check_pep8()
     self.assertEqual(
         [(4, 'EOF in multi-line statement')],
         self.reporter.messages)
示例#11
0
 def test_code_with_warnings(self):
     self.reporter.call_count = 0
     checker = PythonChecker('bogus', ugly_python, self.reporter)
     checker.check_flakes()
     self.assertEqual(
         [(3, "undefined name 'b'"),
         (3, "local variable 'a' is assigned to but never used")],
         self.reporter.messages)
     self.assertEqual(2, self.reporter.call_count)
示例#12
0
 def test_long_length_bad(self):
     long_line = '1234 56189' * 8 + '\n'
     self.file.write(long_line)
     self.file.flush()
     checker = PythonChecker(self.file.name, long_line, self.reporter)
     checker.check_pep8()
     self.assertEqual(
         [(1, 'E501 line too long (80 characters)')],
         self.reporter.messages)
示例#13
0
 def test_code_with_SyntaxError(self):
     self.reporter.call_count = 0
     checker = PythonChecker(
         'bogus', bad_syntax_python, self.reporter)
     checker.check_flakes()
     expected = [(
         2, 'Could not compile; non-default argument follows '
            'default argument: ')]
     self.assertEqual(expected, self.reporter.messages)
     self.assertEqual(1, self.reporter.call_count)
示例#14
0
 def test_pyflakes_ignore(self):
     pyflakes_ignore = (
         'def something():\n'
         '    unused_variable = 1  # pyflakes:ignore\n'
         )
     self.reporter.call_count = 0
     checker = PythonChecker('bogus', pyflakes_ignore, self.reporter)
     checker.check_flakes()
     self.assertEqual([], self.reporter.messages)
     self.assertEqual(0, self.reporter.call_count)
示例#15
0
 def test_long_length_options(self):
     long_line = '1234 56189' * 7 + '\n'
     parser = get_option_parser()
     (options, sources) = parser.parse_args(['-m', '60'])
     self.file.write(long_line)
     self.file.flush()
     checker = PythonChecker(
         self.file.name, long_line, self.reporter, options)
     checker.check_pep8()
     self.assertEqual(
         [(1, 'E501 line too long (70 characters)')],
         self.reporter.messages)
示例#16
0
 def test_code_utf8(self):
     utf8_python = u"a = 'this is utf-8 [\u272a]'"
     checker = PythonChecker('bogus', utf8_python, self.reporter)
     checker.encoding = 'utf-8'
     checker.check_text()
示例#17
0
 def _test_encoding(self, python, expected_encoding='foo-encoding'):
     checker = PythonChecker(
        'bogus', python % dict(encoding=expected_encoding), self.reporter)
     checker.check_text()
     self.assertEqual(expected_encoding, checker.encoding)
示例#18
0
 def test_code_with_pdb(self):
     pdb_python = "import pdb; pdb." + "set_trace()"
     checker = PythonChecker('bogus', pdb_python, self.reporter)
     checker.check_text()
     self.assertEqual(
         [(1, 'Line contains a call to pdb.')], self.reporter.messages)
示例#19
0
 def test_code_without_issues(self):
     checker = PythonChecker('bogus', good_python, self.reporter)
     checker.check_text()
     self.assertEqual([], self.reporter.messages)
示例#20
0
 def create_and_check(self, file_name, text):
     """Used by the TestAnyTextMixin tests."""
     checker = PythonChecker(file_name, text, self.reporter)
     checker.check_text()