blob: 3d4b99702afe7e0030dce4c4b7f847a3778dc963 [file] [log] [blame]
David Aguilar438c5472009-06-28 15:09:16 -07001import os
2import unittest
3
4import git_config
5
6def fixture(*paths):
David Pursehousec1b86a22012-11-14 11:36:51 +09007 """Return a path relative to test/fixtures.
8 """
9 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
David Aguilar438c5472009-06-28 15:09:16 -070010
11class GitConfigUnitTest(unittest.TestCase):
David Pursehousec1b86a22012-11-14 11:36:51 +090012 """Tests the GitConfig class.
13 """
14 def setUp(self):
15 """Create a GitConfig object using the test.gitconfig fixture.
David Aguilar438c5472009-06-28 15:09:16 -070016 """
David Pursehousec1b86a22012-11-14 11:36:51 +090017 config_fixture = fixture('test.gitconfig')
18 self.config = git_config.GitConfig(config_fixture)
David Aguilar438c5472009-06-28 15:09:16 -070019
David Pursehousec1b86a22012-11-14 11:36:51 +090020 def test_GetString_with_empty_config_values(self):
21 """
22 Test config entries with no value.
David Aguilar438c5472009-06-28 15:09:16 -070023
David Pursehousec1b86a22012-11-14 11:36:51 +090024 [section]
25 empty
David Aguilar438c5472009-06-28 15:09:16 -070026
David Pursehousec1b86a22012-11-14 11:36:51 +090027 """
28 val = self.config.GetString('section.empty')
29 self.assertEqual(val, None)
David Aguilar438c5472009-06-28 15:09:16 -070030
David Pursehousec1b86a22012-11-14 11:36:51 +090031 def test_GetString_with_true_value(self):
32 """
33 Test config entries with a string value.
David Aguilar438c5472009-06-28 15:09:16 -070034
David Pursehousec1b86a22012-11-14 11:36:51 +090035 [section]
36 nonempty = true
David Aguilar438c5472009-06-28 15:09:16 -070037
David Pursehousec1b86a22012-11-14 11:36:51 +090038 """
39 val = self.config.GetString('section.nonempty')
40 self.assertEqual(val, 'true')
David Aguilar438c5472009-06-28 15:09:16 -070041
David Pursehousec1b86a22012-11-14 11:36:51 +090042 def test_GetString_from_missing_file(self):
43 """
44 Test missing config file
45 """
46 config_fixture = fixture('not.present.gitconfig')
47 config = git_config.GitConfig(config_fixture)
48 val = config.GetString('empty')
49 self.assertEqual(val, None)
Shawn O. Pearcec24c7202009-07-02 16:12:57 -070050
David Aguilar438c5472009-06-28 15:09:16 -070051if __name__ == '__main__':
David Pursehousec1b86a22012-11-14 11:36:51 +090052 unittest.main()