xcodeproj_unittest.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2011 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions
  5. # are met:
  6. # 1. Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # 2. Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  16. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  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.
  23. """Unit test for xcodeproj.py."""
  24. import xcodeproj
  25. import unittest2 as unittest
  26. class TestErrorHandler(object):
  27. """Error handler for XcodeProjectFileChecker unittests"""
  28. def __init__(self, handler):
  29. self.handler = handler
  30. def turn_off_line_filtering(self):
  31. pass
  32. def __call__(self, line_number, category, confidence, message):
  33. self.handler(self, line_number, category, confidence, message)
  34. return True
  35. class XcodeProjectFileCheckerTest(unittest.TestCase):
  36. """Tests XcodeProjectFileChecker class."""
  37. def assert_no_error(self, lines):
  38. def handler(error_handler, line_number, category, confidence, message):
  39. self.fail('Unexpected error: %d %s %d %s' % (line_number, category, confidence, message))
  40. error_handler = TestErrorHandler(handler)
  41. checker = xcodeproj.XcodeProjectFileChecker('', error_handler)
  42. checker.check(lines)
  43. def assert_error(self, lines, expected_message):
  44. self.had_error = False
  45. def handler(error_handler, line_number, category, confidence, message):
  46. self.assertEqual(expected_message, message)
  47. self.had_error = True
  48. error_handler = TestErrorHandler(handler)
  49. checker = xcodeproj.XcodeProjectFileChecker('', error_handler)
  50. checker.check(lines)
  51. self.assertTrue(self.had_error, '%s should have error: %s.' % (lines, expected_message))
  52. def test_detect_development_region(self):
  53. self.assert_no_error(['developmentRegion = English;'])
  54. self.assert_error([''], 'Missing "developmentRegion = English".')
  55. self.assert_error(['developmentRegion = Japanese;'],
  56. 'developmentRegion is not English.')