diff options
Diffstat (limited to 'tests/test_wrapper.py')
| -rw-r--r-- | tests/test_wrapper.py | 75 |
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 | |||
| 16 | import os | ||
| 17 | import unittest | ||
| 18 | |||
| 19 | import wrapper | ||
| 20 | |||
| 21 | def fixture(*paths): | ||
| 22 | """Return a path relative to tests/fixtures. | ||
| 23 | """ | ||
| 24 | return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) | ||
| 25 | |||
| 26 | class 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 | |||
| 74 | if __name__ == '__main__': | ||
| 75 | unittest.main() | ||
