blob: ca818f48b1325f58d44989be15df6ec23a900128 [file] [log] [blame]
Mike Frysingerf6013762019-06-13 02:30:51 -04001# -*- coding:utf-8 -*-
Mike Frysinger61b2d412019-06-13 13:23:16 -04002#
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 Frysingerf6013762019-06-13 02:30:51 -040016
David Aguilar438c5472009-06-28 15:09:16 -070017import os
18import unittest
19
20import git_config
21
22def fixture(*paths):
David Pursehousec1b86a22012-11-14 11:36:51 +090023 """Return a path relative to test/fixtures.
24 """
25 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
David Aguilar438c5472009-06-28 15:09:16 -070026
27class GitConfigUnitTest(unittest.TestCase):
David Pursehousec1b86a22012-11-14 11:36:51 +090028 """Tests the GitConfig class.
29 """
30 def setUp(self):
31 """Create a GitConfig object using the test.gitconfig fixture.
David Aguilar438c5472009-06-28 15:09:16 -070032 """
David Pursehousec1b86a22012-11-14 11:36:51 +090033 config_fixture = fixture('test.gitconfig')
34 self.config = git_config.GitConfig(config_fixture)
David Aguilar438c5472009-06-28 15:09:16 -070035
David Pursehousec1b86a22012-11-14 11:36:51 +090036 def test_GetString_with_empty_config_values(self):
37 """
38 Test config entries with no value.
David Aguilar438c5472009-06-28 15:09:16 -070039
David Pursehousec1b86a22012-11-14 11:36:51 +090040 [section]
41 empty
David Aguilar438c5472009-06-28 15:09:16 -070042
David Pursehousec1b86a22012-11-14 11:36:51 +090043 """
44 val = self.config.GetString('section.empty')
45 self.assertEqual(val, None)
David Aguilar438c5472009-06-28 15:09:16 -070046
David Pursehousec1b86a22012-11-14 11:36:51 +090047 def test_GetString_with_true_value(self):
48 """
49 Test config entries with a string value.
David Aguilar438c5472009-06-28 15:09:16 -070050
David Pursehousec1b86a22012-11-14 11:36:51 +090051 [section]
52 nonempty = true
David Aguilar438c5472009-06-28 15:09:16 -070053
David Pursehousec1b86a22012-11-14 11:36:51 +090054 """
55 val = self.config.GetString('section.nonempty')
56 self.assertEqual(val, 'true')
David Aguilar438c5472009-06-28 15:09:16 -070057
David Pursehousec1b86a22012-11-14 11:36:51 +090058 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. Pearcec24c7202009-07-02 16:12:57 -070066
David Aguilar438c5472009-06-28 15:09:16 -070067if __name__ == '__main__':
David Pursehousec1b86a22012-11-14 11:36:51 +090068 unittest.main()