summaryrefslogtreecommitdiffstats
path: root/tests/test_wrapper.py
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2015-10-06 15:23:19 -0700
committerDan Willemsen <dwillemsen@google.com>2015-10-07 15:43:22 -0700
commit745b4ad660f8050045b521c4e15b7d3ac0b3d70e (patch)
tree643e836eafdde0c08e1eec540eab6ae23b2ef29e /tests/test_wrapper.py
parent4c5f74e4521679d1dcc31c575d417387b9c51c87 (diff)
downloadgit-repo-745b4ad660f8050045b521c4e15b7d3ac0b3d70e.tar.gz
Fix gitc-init behaviorv1.12.32
With gitc-init, a gitc client may be specified using '-c'. If we're not currently in that client, we need to change directories so that we don't affect the local checkout, and to ensure that repo is checked out in the new client. This also makes '-c' optional if already in a gitc client, to match the rest of the init options. Change-Id: Ib514ad9fd101698060ae89bb035499800897e9bd
Diffstat (limited to 'tests/test_wrapper.py')
-rw-r--r--tests/test_wrapper.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py
new file mode 100644
index 00000000..fb32e38a
--- /dev/null
+++ b/tests/test_wrapper.py
@@ -0,0 +1,75 @@
1#
2# Copyright (C) 2015 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import unittest
18
19import wrapper
20
21def fixture(*paths):
22 """Return a path relative to tests/fixtures.
23 """
24 return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
25
26class RepoWrapperUnitTest(unittest.TestCase):
27 """Tests helper functions in the repo wrapper
28 """
29 def setUp(self):
30 """Load the wrapper module every time
31 """
32 wrapper._wrapper_module = None
33 self.wrapper = wrapper.Wrapper()
34
35 def test_get_gitc_manifest_dir_no_gitc(self):
36 """
37 Test reading a missing gitc config file
38 """
39 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
40 val = self.wrapper.get_gitc_manifest_dir()
41 self.assertEqual(val, '')
42
43 def test_get_gitc_manifest_dir(self):
44 """
45 Test reading the gitc config file and parsing the directory
46 """
47 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
48 val = self.wrapper.get_gitc_manifest_dir()
49 self.assertEqual(val, '/test/usr/local/google/gitc')
50
51 def test_gitc_parse_clientdir_no_gitc(self):
52 """
53 Test parsing the gitc clientdir without gitc running
54 """
55 self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
56 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
57 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
58
59 def test_gitc_parse_clientdir(self):
60 """
61 Test parsing the gitc clientdir
62 """
63 self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
64 self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
65 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
66 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/'), 'test')
67 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), 'test')
68 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test'), 'test')
69 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/'), 'test')
70 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
71 self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
72 self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
73
74if __name__ == '__main__':
75 unittest.main()