| OLD | NEW |
| 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
| 9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
| 10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 from python import PythonChecker | 28 from python import PythonChecker |
| 29 | 29 |
| 30 | 30 |
| 31 class PythonCheckerTest(unittest.TestCase): | 31 class PythonCheckerTest(unittest.TestCase): |
| 32 | 32 |
| 33 """Tests the PythonChecker class.""" | 33 """Tests the PythonChecker class.""" |
| 34 | 34 |
| 35 def test_init(self): | 35 def test_init(self): |
| 36 """Test __init__() method.""" | 36 """Test __init__() method.""" |
| 37 |
| 37 def _mock_handle_style_error(self): | 38 def _mock_handle_style_error(self): |
| 38 pass | 39 pass |
| 39 | 40 |
| 40 checker = PythonChecker("foo.txt", _mock_handle_style_error) | 41 checker = PythonChecker("foo.txt", _mock_handle_style_error) |
| 41 self.assertEqual(checker._file_path, "foo.txt") | 42 self.assertEqual(checker._file_path, "foo.txt") |
| 42 self.assertEqual(checker._handle_style_error, | 43 self.assertEqual(checker._handle_style_error, |
| 43 _mock_handle_style_error) | 44 _mock_handle_style_error) |
| 44 | 45 |
| 45 def test_check(self): | 46 def test_check(self): |
| 46 """Test check() method.""" | 47 """Test check() method.""" |
| 47 errors = [] | 48 errors = [] |
| 48 | 49 |
| 49 def _mock_handle_style_error(line_number, category, confidence, | 50 def _mock_handle_style_error(line_number, category, confidence, |
| 50 message): | 51 message): |
| 51 error = (line_number, category, confidence, message) | 52 error = (line_number, category, confidence, message) |
| 52 errors.append(error) | 53 errors.append(error) |
| 53 | 54 |
| 54 current_dir = os.path.dirname(__file__) | 55 current_dir = os.path.dirname(__file__) |
| 55 file_path = os.path.join(current_dir, "python_unittest_input.py") | 56 file_path = os.path.join(current_dir, "python_unittest_input.py") |
| 56 | 57 |
| 57 checker = PythonChecker(file_path, _mock_handle_style_error) | 58 checker = PythonChecker(file_path, _mock_handle_style_error) |
| 58 checker.check(lines=[]) | 59 checker.check(lines=[]) |
| 59 | 60 |
| 60 self.assertEqual(errors, [ | 61 self.assertEqual(errors, [ |
| 61 (4, "pep8/W291", 5, "trailing whitespace"), | 62 (4, "pep8/W291", 5, "trailing whitespace"), |
| 62 (4, "pylint/E1601(print-statement)", 5, "[] print statement used"), | 63 (4, "pylint/E1601(print-statement)", 5, "[] print statement used"), |
| 63 (4, "pylint/E0602(undefined-variable)", 5, "[] Undefined variable 'e
rror'"), | 64 (4, "pylint/E0602(undefined-variable)", 5, "[] Undefined variable 'e
rror'"), |
| 64 ]) | 65 ]) |
| OLD | NEW |