Mike Frysinger | ca540ae | 2019-07-10 15:42:30 -0400 | [diff] [blame] | 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 | |
Mike Frysinger | 87deaef | 2019-07-26 21:14:55 -0400 | [diff] [blame] | 17 | """Unittests for the git_command.py module.""" |
| 18 | |
| 19 | from __future__ import print_function |
| 20 | |
Mike Frysinger | 369814b | 2019-07-10 17:10:07 -0400 | [diff] [blame] | 21 | import re |
Mike Frysinger | ca540ae | 2019-07-10 15:42:30 -0400 | [diff] [blame] | 22 | import unittest |
| 23 | |
| 24 | import git_command |
| 25 | |
| 26 | |
| 27 | class GitCallUnitTest(unittest.TestCase): |
| 28 | """Tests the _GitCall class (via git_command.git).""" |
| 29 | |
| 30 | def test_version_tuple(self): |
| 31 | """Check git.version_tuple() handling.""" |
| 32 | ver = git_command.git.version_tuple() |
| 33 | self.assertIsNotNone(ver) |
| 34 | |
| 35 | # We don't dive too deep into the values here to avoid having to update |
| 36 | # whenever git versions change. We do check relative to this min version |
| 37 | # as this is what `repo` itself requires via MIN_GIT_VERSION. |
| 38 | MIN_GIT_VERSION = (1, 7, 2) |
| 39 | self.assertTrue(isinstance(ver.major, int)) |
| 40 | self.assertTrue(isinstance(ver.minor, int)) |
| 41 | self.assertTrue(isinstance(ver.micro, int)) |
| 42 | |
| 43 | self.assertGreater(ver.major, MIN_GIT_VERSION[0] - 1) |
| 44 | self.assertGreaterEqual(ver.micro, 0) |
| 45 | self.assertGreaterEqual(ver.major, 0) |
| 46 | |
| 47 | self.assertGreaterEqual(ver, MIN_GIT_VERSION) |
| 48 | self.assertLess(ver, (9999, 9999, 9999)) |
| 49 | |
| 50 | self.assertNotEqual('', ver.full) |
Mike Frysinger | 369814b | 2019-07-10 17:10:07 -0400 | [diff] [blame] | 51 | |
| 52 | |
Mike Frysinger | 71b0f31 | 2019-09-30 22:39:49 -0400 | [diff] [blame] | 53 | class UserAgentUnitTest(unittest.TestCase): |
| 54 | """Tests the UserAgent function.""" |
| 55 | |
| 56 | def test_smoke_os(self): |
| 57 | """Make sure UA OS setting returns something useful.""" |
| 58 | os_name = git_command.user_agent.os |
| 59 | # We can't dive too deep because of OS/tool differences, but we can check |
| 60 | # the general form. |
| 61 | m = re.match(r'^[^ ]+$', os_name) |
| 62 | self.assertIsNotNone(m) |
Mike Frysinger | 369814b | 2019-07-10 17:10:07 -0400 | [diff] [blame] | 63 | |
Mike Frysinger | 71b0f31 | 2019-09-30 22:39:49 -0400 | [diff] [blame] | 64 | def test_smoke_repo(self): |
| 65 | """Make sure repo UA returns something useful.""" |
| 66 | ua = git_command.user_agent.repo |
Mike Frysinger | 369814b | 2019-07-10 17:10:07 -0400 | [diff] [blame] | 67 | # We can't dive too deep because of OS/tool differences, but we can check |
| 68 | # the general form. |
| 69 | m = re.match(r'^git-repo/[^ ]+ ([^ ]+) git/[^ ]+ Python/[0-9.]+', ua) |
| 70 | self.assertIsNotNone(m) |
Mike Frysinger | 2f0951b | 2019-07-10 17:13:46 -0400 | [diff] [blame] | 71 | |
| 72 | def test_smoke_git(self): |
| 73 | """Make sure git UA returns something useful.""" |
| 74 | ua = git_command.user_agent.git |
| 75 | # We can't dive too deep because of OS/tool differences, but we can check |
| 76 | # the general form. |
| 77 | m = re.match(r'^git/[^ ]+ ([^ ]+) git-repo/[^ ]+', ua) |
| 78 | self.assertIsNotNone(m) |