test_git_command.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding:utf-8 -*-
  2. #
  3. # Copyright 2019 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 git_command.py module."""
  17. from __future__ import print_function
  18. import re
  19. import unittest
  20. import git_command
  21. class GitCallUnitTest(unittest.TestCase):
  22. """Tests the _GitCall class (via git_command.git)."""
  23. def test_version_tuple(self):
  24. """Check git.version_tuple() handling."""
  25. ver = git_command.git.version_tuple()
  26. self.assertIsNotNone(ver)
  27. # We don't dive too deep into the values here to avoid having to update
  28. # whenever git versions change. We do check relative to this min version
  29. # as this is what `repo` itself requires via MIN_GIT_VERSION.
  30. MIN_GIT_VERSION = (1, 7, 2)
  31. self.assertTrue(isinstance(ver.major, int))
  32. self.assertTrue(isinstance(ver.minor, int))
  33. self.assertTrue(isinstance(ver.micro, int))
  34. self.assertGreater(ver.major, MIN_GIT_VERSION[0] - 1)
  35. self.assertGreaterEqual(ver.micro, 0)
  36. self.assertGreaterEqual(ver.major, 0)
  37. self.assertGreaterEqual(ver, MIN_GIT_VERSION)
  38. self.assertLess(ver, (9999, 9999, 9999))
  39. self.assertNotEqual('', ver.full)
  40. class RepoUserAgentUnitTest(unittest.TestCase):
  41. """Tests the RepoUserAgent function."""
  42. def test_smoke(self):
  43. """Make sure it returns something useful."""
  44. ua = git_command.RepoUserAgent()
  45. # We can't dive too deep because of OS/tool differences, but we can check
  46. # the general form.
  47. m = re.match(r'^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+', ua)
  48. self.assertIsNotNone(m)