test_git_config.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding:utf-8 -*-
  2. import os
  3. import unittest
  4. import git_config
  5. def fixture(*paths):
  6. """Return a path relative to test/fixtures.
  7. """
  8. return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
  9. class GitConfigUnitTest(unittest.TestCase):
  10. """Tests the GitConfig class.
  11. """
  12. def setUp(self):
  13. """Create a GitConfig object using the test.gitconfig fixture.
  14. """
  15. config_fixture = fixture('test.gitconfig')
  16. self.config = git_config.GitConfig(config_fixture)
  17. def test_GetString_with_empty_config_values(self):
  18. """
  19. Test config entries with no value.
  20. [section]
  21. empty
  22. """
  23. val = self.config.GetString('section.empty')
  24. self.assertEqual(val, None)
  25. def test_GetString_with_true_value(self):
  26. """
  27. Test config entries with a string value.
  28. [section]
  29. nonempty = true
  30. """
  31. val = self.config.GetString('section.nonempty')
  32. self.assertEqual(val, 'true')
  33. def test_GetString_from_missing_file(self):
  34. """
  35. Test missing config file
  36. """
  37. config_fixture = fixture('not.present.gitconfig')
  38. config = git_config.GitConfig(config_fixture)
  39. val = config.GetString('empty')
  40. self.assertEqual(val, None)
  41. if __name__ == '__main__':
  42. unittest.main()