test_git_config.py 1.2 KB

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