test_wrapper.py 2.9 KB

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