test_git_config.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright (C) 2009 The Android Open Source Project
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. import os
  17. import unittest
  18. import git_config
  19. def fixture(*paths):
  20. """Return a path relative to test/fixtures.
  21. """
  22. return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
  23. class GitConfigUnitTest(unittest.TestCase):
  24. """Tests the GitConfig class.
  25. """
  26. def setUp(self):
  27. """Create a GitConfig object using the test.gitconfig fixture.
  28. """
  29. config_fixture = fixture('test.gitconfig')
  30. self.config = git_config.GitConfig(config_fixture)
  31. def test_GetString_with_empty_config_values(self):
  32. """
  33. Test config entries with no value.
  34. [section]
  35. empty
  36. """
  37. val = self.config.GetString('section.empty')
  38. self.assertEqual(val, None)
  39. def test_GetString_with_true_value(self):
  40. """
  41. Test config entries with a string value.
  42. [section]
  43. nonempty = true
  44. """
  45. val = self.config.GetString('section.nonempty')
  46. self.assertEqual(val, 'true')
  47. def test_GetString_from_missing_file(self):
  48. """
  49. Test missing config file
  50. """
  51. config_fixture = fixture('not.present.gitconfig')
  52. config = git_config.GitConfig(config_fixture)
  53. val = config.GetString('empty')
  54. self.assertEqual(val, None)
  55. if __name__ == '__main__':
  56. unittest.main()