David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 1 | import os |
| 2 | import unittest |
| 3 | |
| 4 | import git_config |
| 5 | |
| 6 | def fixture(*paths): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 7 | """Return a path relative to test/fixtures. |
| 8 | """ |
| 9 | return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 10 | |
| 11 | class GitConfigUnitTest(unittest.TestCase): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 12 | """Tests the GitConfig class. |
| 13 | """ |
| 14 | def setUp(self): |
| 15 | """Create a GitConfig object using the test.gitconfig fixture. |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 16 | """ |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 17 | config_fixture = fixture('test.gitconfig') |
| 18 | self.config = git_config.GitConfig(config_fixture) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 19 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 20 | def test_GetString_with_empty_config_values(self): |
| 21 | """ |
| 22 | Test config entries with no value. |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 23 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 24 | [section] |
| 25 | empty |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 26 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 27 | """ |
| 28 | val = self.config.GetString('section.empty') |
| 29 | self.assertEqual(val, None) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 30 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 31 | def test_GetString_with_true_value(self): |
| 32 | """ |
| 33 | Test config entries with a string value. |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 34 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 35 | [section] |
| 36 | nonempty = true |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 37 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 38 | """ |
| 39 | val = self.config.GetString('section.nonempty') |
| 40 | self.assertEqual(val, 'true') |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 41 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 42 | 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. Pearce | c24c720 | 2009-07-02 16:12:57 -0700 | [diff] [blame] | 50 | |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 51 | if __name__ == '__main__': |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 52 | unittest.main() |