blob: b735f27f42ee0b815cf1000c3c86671dbb1b40e5 [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
Mike Frysinger87deaef2019-07-26 21:14:55 -040017"""Unittests for the git_config.py module."""
18
19from __future__ import print_function
20
David Aguilar438c5472009-06-28 15:09:16 -070021import os
22import unittest
23
24import git_config
25
26def fixture(*paths):
David Pursehousec1b86a22012-11-14 11:36:51 +090027 """Return a path relative to test/fixtures.
28 """
29 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
David Aguilar438c5472009-06-28 15:09:16 -070030
31class GitConfigUnitTest(unittest.TestCase):
David Pursehousec1b86a22012-11-14 11:36:51 +090032 """Tests the GitConfig class.
33 """
34 def setUp(self):
35 """Create a GitConfig object using the test.gitconfig fixture.
David Aguilar438c5472009-06-28 15:09:16 -070036 """
David Pursehousec1b86a22012-11-14 11:36:51 +090037 config_fixture = fixture('test.gitconfig')
38 self.config = git_config.GitConfig(config_fixture)
David Aguilar438c5472009-06-28 15:09:16 -070039
David Pursehousec1b86a22012-11-14 11:36:51 +090040 def test_GetString_with_empty_config_values(self):
41 """
42 Test config entries with no value.
David Aguilar438c5472009-06-28 15:09:16 -070043
David Pursehousec1b86a22012-11-14 11:36:51 +090044 [section]
45 empty
David Aguilar438c5472009-06-28 15:09:16 -070046
David Pursehousec1b86a22012-11-14 11:36:51 +090047 """
48 val = self.config.GetString('section.empty')
49 self.assertEqual(val, None)
David Aguilar438c5472009-06-28 15:09:16 -070050
David Pursehousec1b86a22012-11-14 11:36:51 +090051 def test_GetString_with_true_value(self):
52 """
53 Test config entries with a string value.
David Aguilar438c5472009-06-28 15:09:16 -070054
David Pursehousec1b86a22012-11-14 11:36:51 +090055 [section]
56 nonempty = true
David Aguilar438c5472009-06-28 15:09:16 -070057
David Pursehousec1b86a22012-11-14 11:36:51 +090058 """
59 val = self.config.GetString('section.nonempty')
60 self.assertEqual(val, 'true')
David Aguilar438c5472009-06-28 15:09:16 -070061
David Pursehousec1b86a22012-11-14 11:36:51 +090062 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. Pearcec24c7202009-07-02 16:12:57 -070070
David Aguilar438c5472009-06-28 15:09:16 -070071if __name__ == '__main__':
David Pursehousec1b86a22012-11-14 11:36:51 +090072 unittest.main()