| OLD | NEW |
| 1 # Copyright (C) 2009 Google Inc. All rights reserved. | 1 # Copyright (C) 2009 Google Inc. All rights reserved. |
| 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 are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| 11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
| 12 # distribution. | 12 # distribution. |
| 13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
| 14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
| 15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
| 16 # | 16 # |
| 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 28 |
| 29 """Unit test for text_style.py.""" | |
| 30 | |
| 31 import unittest | 29 import unittest |
| 32 | 30 |
| 33 import text as text_style | 31 from webkitpy.style.checkers.text import process_file_data, TextChecker |
| 34 from text import TextChecker | |
| 35 | 32 |
| 36 | 33 |
| 37 class TextStyleTestCase(unittest.TestCase): | 34 class TextStyleTestCase(unittest.TestCase): |
| 38 """TestCase for text_style.py""" | 35 """TestCase for text_style.py""" |
| 39 | 36 |
| 40 def assertNoError(self, lines): | 37 def assertNoError(self, lines): |
| 41 """Asserts that the specified lines has no errors.""" | 38 """Asserts that the specified lines has no errors.""" |
| 42 self.had_error = False | 39 self.had_error = False |
| 43 | 40 |
| 44 def error_for_test(line_number, category, confidence, message): | 41 def error_for_test(line_number, category, confidence, message): |
| 45 """Records if an error occurs.""" | 42 """Records if an error occurs.""" |
| 46 self.had_error = True | 43 self.had_error = True |
| 47 | 44 |
| 48 text_style.process_file_data('', lines, error_for_test) | 45 process_file_data('', lines, error_for_test) |
| 49 self.assertFalse(self.had_error, '%s should not have any errors.' % line
s) | 46 self.assertFalse(self.had_error, '%s should not have any errors.' % line
s) |
| 50 | 47 |
| 51 def assertError(self, lines, expected_line_number): | 48 def assertError(self, lines, expected_line_number): |
| 52 """Asserts that the specified lines has an error.""" | 49 """Asserts that the specified lines has an error.""" |
| 53 self.had_error = False | 50 self.had_error = False |
| 54 | 51 |
| 55 def error_for_test(line_number, category, confidence, message): | 52 def error_for_test(line_number, category, confidence, message): |
| 56 """Checks if the expected error occurs.""" | 53 """Checks if the expected error occurs.""" |
| 57 self.assertEqual(expected_line_number, line_number) | 54 self.assertEqual(expected_line_number, line_number) |
| 58 self.assertEqual('whitespace/tab', category) | 55 self.assertEqual('whitespace/tab', category) |
| 59 self.had_error = True | 56 self.had_error = True |
| 60 | 57 |
| 61 text_style.process_file_data('', lines, error_for_test) | 58 process_file_data('', lines, error_for_test) |
| 62 self.assertTrue(self.had_error, '%s should have an error [whitespace/tab
].' % lines) | 59 self.assertTrue(self.had_error, '%s should have an error [whitespace/tab
].' % lines) |
| 63 | 60 |
| 64 def test_no_error(self): | 61 def test_no_error(self): |
| 65 """Tests for no error cases.""" | 62 """Tests for no error cases.""" |
| 66 self.assertNoError(['']) | 63 self.assertNoError(['']) |
| 67 self.assertNoError(['abc def', 'ggg']) | 64 self.assertNoError(['abc def', 'ggg']) |
| 68 | 65 |
| 69 def test_error(self): | 66 def test_error(self): |
| 70 """Tests for error cases.""" | 67 """Tests for error cases.""" |
| 71 self.assertError(['2009-12-16\tKent Tamura\t<tkent@chromium.org>'], 1) | 68 self.assertError(['2009-12-16\tKent Tamura\t<tkent@chromium.org>'], 1) |
| 72 self.assertError(['2009-12-16 Kent Tamura <tkent@chromium.org>', | 69 self.assertError(['2009-12-16 Kent Tamura <tkent@chromium.org>', |
| 73 '', | 70 '', |
| 74 '\tReviewed by NOBODY.'], 3) | 71 '\tReviewed by NOBODY.'], 3) |
| 75 | 72 |
| 76 | 73 |
| 77 class TextCheckerTest(unittest.TestCase): | 74 class TextCheckerTest(unittest.TestCase): |
| 78 | 75 |
| 79 """Tests TextChecker class.""" | 76 """Tests TextChecker class.""" |
| 80 | 77 |
| 81 def mock_handle_style_error(self): | 78 def mock_handle_style_error(self): |
| 82 pass | 79 pass |
| 83 | 80 |
| 84 def test_init(self): | 81 def test_init(self): |
| 85 """Test __init__ constructor.""" | 82 """Test __init__ constructor.""" |
| 86 checker = TextChecker("foo.txt", self.mock_handle_style_error) | 83 checker = TextChecker("foo.txt", self.mock_handle_style_error) |
| 87 self.assertEqual(checker.file_path, "foo.txt") | 84 self.assertEqual(checker.file_path, "foo.txt") |
| 88 self.assertEqual(checker.handle_style_error, self.mock_handle_style_erro
r) | 85 self.assertEqual(checker.handle_style_error, self.mock_handle_style_erro
r) |
| OLD | NEW |