| OLD | NEW |
| 1 # Copyright (C) 2011 Google Inc. All rights reserved. | 1 # Copyright (C) 2011 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 | 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 10 matching lines...) Expand all Loading... |
| 21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | 23 |
| 24 """Unit test for xcodeproj.py.""" | 24 """Unit test for xcodeproj.py.""" |
| 25 import unittest | 25 import unittest |
| 26 | 26 |
| 27 import xcodeproj | 27 import xcodeproj |
| 28 | 28 |
| 29 | 29 |
| 30 class TestErrorHandler(object): | 30 class TestErrorHandler(object): |
| 31 |
| 31 """Error handler for XcodeProjectFileChecker unittests""" | 32 """Error handler for XcodeProjectFileChecker unittests""" |
| 32 | 33 |
| 33 def __init__(self, handler): | 34 def __init__(self, handler): |
| 34 self.handler = handler | 35 self.handler = handler |
| 35 | 36 |
| 36 def turn_off_line_filtering(self): | 37 def turn_off_line_filtering(self): |
| 37 pass | 38 pass |
| 38 | 39 |
| 39 def __call__(self, line_number, category, confidence, message): | 40 def __call__(self, line_number, category, confidence, message): |
| 40 self.handler(self, line_number, category, confidence, message) | 41 self.handler(self, line_number, category, confidence, message) |
| 41 return True | 42 return True |
| 42 | 43 |
| 43 | 44 |
| 44 class XcodeProjectFileCheckerTest(unittest.TestCase): | 45 class XcodeProjectFileCheckerTest(unittest.TestCase): |
| 46 |
| 45 """Tests XcodeProjectFileChecker class.""" | 47 """Tests XcodeProjectFileChecker class.""" |
| 46 | 48 |
| 47 def assert_no_error(self, lines): | 49 def assert_no_error(self, lines): |
| 48 def handler(error_handler, line_number, category, confidence, message): | 50 def handler(error_handler, line_number, category, confidence, message): |
| 49 self.fail('Unexpected error: %d %s %d %s' % (line_number, category,
confidence, message)) | 51 self.fail('Unexpected error: %d %s %d %s' % (line_number, category,
confidence, message)) |
| 50 | 52 |
| 51 error_handler = TestErrorHandler(handler) | 53 error_handler = TestErrorHandler(handler) |
| 52 checker = xcodeproj.XcodeProjectFileChecker('', error_handler) | 54 checker = xcodeproj.XcodeProjectFileChecker('', error_handler) |
| 53 checker.check(lines) | 55 checker.check(lines) |
| 54 | 56 |
| 55 def assert_error(self, lines, expected_message): | 57 def assert_error(self, lines, expected_message): |
| 56 self.had_error = False | 58 self.had_error = False |
| 57 | 59 |
| 58 def handler(error_handler, line_number, category, confidence, message): | 60 def handler(error_handler, line_number, category, confidence, message): |
| 59 self.assertEqual(expected_message, message) | 61 self.assertEqual(expected_message, message) |
| 60 self.had_error = True | 62 self.had_error = True |
| 61 error_handler = TestErrorHandler(handler) | 63 error_handler = TestErrorHandler(handler) |
| 62 checker = xcodeproj.XcodeProjectFileChecker('', error_handler) | 64 checker = xcodeproj.XcodeProjectFileChecker('', error_handler) |
| 63 checker.check(lines) | 65 checker.check(lines) |
| 64 self.assertTrue(self.had_error, '%s should have error: %s.' % (lines, ex
pected_message)) | 66 self.assertTrue(self.had_error, '%s should have error: %s.' % (lines, ex
pected_message)) |
| 65 | 67 |
| 66 def test_detect_development_region(self): | 68 def test_detect_development_region(self): |
| 67 self.assert_no_error(['developmentRegion = English;']) | 69 self.assert_no_error(['developmentRegion = English;']) |
| 68 self.assert_error([''], 'Missing "developmentRegion = English".') | 70 self.assert_error([''], 'Missing "developmentRegion = English".') |
| 69 self.assert_error(['developmentRegion = Japanese;'], | 71 self.assert_error(['developmentRegion = Japanese;'], |
| 70 'developmentRegion is not English.') | 72 'developmentRegion is not English.') |
| OLD | NEW |