Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 1 | # -*- coding:utf-8 -*- |
Mike Frysinger | 61b2d41 | 2019-06-13 13:23:16 -0400 | [diff] [blame^] | 2 | # |
| 3 | # Copyright (C) 2009 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Mike Frysinger | f601376 | 2019-06-13 02:30:51 -0400 | [diff] [blame] | 16 | |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 17 | import os |
| 18 | import unittest |
| 19 | |
| 20 | import git_config |
| 21 | |
| 22 | def fixture(*paths): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 23 | """Return a path relative to test/fixtures. |
| 24 | """ |
| 25 | return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 26 | |
| 27 | class GitConfigUnitTest(unittest.TestCase): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 28 | """Tests the GitConfig class. |
| 29 | """ |
| 30 | def setUp(self): |
| 31 | """Create a GitConfig object using the test.gitconfig fixture. |
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 | config_fixture = fixture('test.gitconfig') |
| 34 | self.config = git_config.GitConfig(config_fixture) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 35 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 36 | def test_GetString_with_empty_config_values(self): |
| 37 | """ |
| 38 | Test config entries with no value. |
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 | [section] |
| 41 | empty |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 42 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 43 | """ |
| 44 | val = self.config.GetString('section.empty') |
| 45 | self.assertEqual(val, None) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 46 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 47 | def test_GetString_with_true_value(self): |
| 48 | """ |
| 49 | Test config entries with a string value. |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 50 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 51 | [section] |
| 52 | nonempty = true |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 53 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 54 | """ |
| 55 | val = self.config.GetString('section.nonempty') |
| 56 | self.assertEqual(val, 'true') |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 57 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 58 | def test_GetString_from_missing_file(self): |
| 59 | """ |
| 60 | Test missing config file |
| 61 | """ |
| 62 | config_fixture = fixture('not.present.gitconfig') |
| 63 | config = git_config.GitConfig(config_fixture) |
| 64 | val = config.GetString('empty') |
| 65 | self.assertEqual(val, None) |
Shawn O. Pearce | c24c720 | 2009-07-02 16:12:57 -0700 | [diff] [blame] | 66 | |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 67 | if __name__ == '__main__': |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 68 | unittest.main() |