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