test_git_config.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. """Unittests for the git_config.py module."""
  17. from __future__ import print_function
  18. import os
  19. import unittest
  20. import git_config
  21. def fixture(*paths):
  22. """Return a path relative to test/fixtures.
  23. """
  24. return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
  25. class GitConfigUnitTest(unittest.TestCase):
  26. """Tests the GitConfig class.
  27. """
  28. def setUp(self):
  29. """Create a GitConfig object using the test.gitconfig fixture.
  30. """
  31. config_fixture = fixture('test.gitconfig')
  32. self.config = git_config.GitConfig(config_fixture)
  33. def test_GetString_with_empty_config_values(self):
  34. """
  35. Test config entries with no value.
  36. [section]
  37. empty
  38. """
  39. val = self.config.GetString('section.empty')
  40. self.assertEqual(val, None)
  41. def test_GetString_with_true_value(self):
  42. """
  43. Test config entries with a string value.
  44. [section]
  45. nonempty = true
  46. """
  47. val = self.config.GetString('section.nonempty')
  48. self.assertEqual(val, 'true')
  49. def test_GetString_from_missing_file(self):
  50. """
  51. Test missing config file
  52. """
  53. config_fixture = fixture('not.present.gitconfig')
  54. config = git_config.GitConfig(config_fixture)
  55. val = config.GetString('empty')
  56. self.assertEqual(val, None)
  57. if __name__ == '__main__':
  58. unittest.main()