test_wrapper.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright (C) 2015 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.
  16. import os
  17. import unittest
  18. import wrapper
  19. def fixture(*paths):
  20. """Return a path relative to tests/fixtures.
  21. """
  22. return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
  23. class RepoWrapperUnitTest(unittest.TestCase):
  24. """Tests helper functions in the repo wrapper
  25. """
  26. def setUp(self):
  27. """Load the wrapper module every time
  28. """
  29. wrapper._wrapper_module = None
  30. self.wrapper = wrapper.Wrapper()
  31. def test_get_gitc_manifest_dir_no_gitc(self):
  32. """
  33. Test reading a missing gitc config file
  34. """
  35. self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
  36. val = self.wrapper.get_gitc_manifest_dir()
  37. self.assertEqual(val, '')
  38. def test_get_gitc_manifest_dir(self):
  39. """
  40. Test reading the gitc config file and parsing the directory
  41. """
  42. self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
  43. val = self.wrapper.get_gitc_manifest_dir()
  44. self.assertEqual(val, '/test/usr/local/google/gitc')
  45. def test_gitc_parse_clientdir_no_gitc(self):
  46. """
  47. Test parsing the gitc clientdir without gitc running
  48. """
  49. self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
  50. self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
  51. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
  52. def test_gitc_parse_clientdir(self):
  53. """
  54. Test parsing the gitc clientdir
  55. """
  56. self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
  57. self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
  58. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
  59. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/'), 'test')
  60. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), 'test')
  61. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test'), 'test')
  62. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/'), 'test')
  63. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
  64. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
  65. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
  66. if __name__ == '__main__':
  67. unittest.main()