test_wrapper.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. """Unittests for the wrapper.py module."""
  17. from __future__ import print_function
  18. import os
  19. import unittest
  20. import wrapper
  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. class RepoWrapperUnitTest(unittest.TestCase):
  26. """Tests helper functions in the repo wrapper
  27. """
  28. def setUp(self):
  29. """Load the wrapper module every time
  30. """
  31. wrapper._wrapper_module = None
  32. self.wrapper = wrapper.Wrapper()
  33. def test_get_gitc_manifest_dir_no_gitc(self):
  34. """
  35. Test reading a missing gitc config file
  36. """
  37. self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
  38. val = self.wrapper.get_gitc_manifest_dir()
  39. self.assertEqual(val, '')
  40. def test_get_gitc_manifest_dir(self):
  41. """
  42. Test reading the gitc config file and parsing the directory
  43. """
  44. self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
  45. val = self.wrapper.get_gitc_manifest_dir()
  46. self.assertEqual(val, '/test/usr/local/google/gitc')
  47. def test_gitc_parse_clientdir_no_gitc(self):
  48. """
  49. Test parsing the gitc clientdir without gitc running
  50. """
  51. self.wrapper.GITC_CONFIG_FILE = fixture('missing_gitc_config')
  52. self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
  53. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
  54. def test_gitc_parse_clientdir(self):
  55. """
  56. Test parsing the gitc clientdir
  57. """
  58. self.wrapper.GITC_CONFIG_FILE = fixture('gitc_config')
  59. self.assertEqual(self.wrapper.gitc_parse_clientdir('/something'), None)
  60. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test'), 'test')
  61. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/'), 'test')
  62. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/test/extra'), 'test')
  63. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test'), 'test')
  64. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/'), 'test')
  65. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/test/extra'), 'test')
  66. self.assertEqual(self.wrapper.gitc_parse_clientdir('/gitc/manifest-rw/'), None)
  67. self.assertEqual(self.wrapper.gitc_parse_clientdir('/test/usr/local/google/gitc/'), None)
  68. if __name__ == '__main__':
  69. unittest.main()