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 | |
Mike Frysinger | 87deaef | 2019-07-26 21:14:55 -0400 | [diff] [blame^] | 17 | """Unittests for the git_config.py module.""" |
| 18 | |
| 19 | from __future__ import print_function |
| 20 | |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 21 | import os |
| 22 | import unittest |
| 23 | |
| 24 | import git_config |
| 25 | |
| 26 | def fixture(*paths): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 27 | """Return a path relative to test/fixtures. |
| 28 | """ |
| 29 | return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 30 | |
| 31 | class GitConfigUnitTest(unittest.TestCase): |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 32 | """Tests the GitConfig class. |
| 33 | """ |
| 34 | def setUp(self): |
| 35 | """Create a GitConfig object using the test.gitconfig fixture. |
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 | config_fixture = fixture('test.gitconfig') |
| 38 | self.config = git_config.GitConfig(config_fixture) |
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 | def test_GetString_with_empty_config_values(self): |
| 41 | """ |
| 42 | Test config entries with no value. |
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 | [section] |
| 45 | empty |
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 | """ |
| 48 | val = self.config.GetString('section.empty') |
| 49 | self.assertEqual(val, None) |
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 | def test_GetString_with_true_value(self): |
| 52 | """ |
| 53 | Test config entries with a string value. |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 54 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 55 | [section] |
| 56 | nonempty = 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 | """ |
| 59 | val = self.config.GetString('section.nonempty') |
| 60 | self.assertEqual(val, 'true') |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 61 | |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 62 | def test_GetString_from_missing_file(self): |
| 63 | """ |
| 64 | Test missing config file |
| 65 | """ |
| 66 | config_fixture = fixture('not.present.gitconfig') |
| 67 | config = git_config.GitConfig(config_fixture) |
| 68 | val = config.GetString('empty') |
| 69 | self.assertEqual(val, None) |
Shawn O. Pearce | c24c720 | 2009-07-02 16:12:57 -0700 | [diff] [blame] | 70 | |
David Aguilar | 438c547 | 2009-06-28 15:09:16 -0700 | [diff] [blame] | 71 | if __name__ == '__main__': |
David Pursehouse | c1b86a2 | 2012-11-14 11:36:51 +0900 | [diff] [blame] | 72 | unittest.main() |