diff options
Diffstat (limited to 'tests/test_git_command.py')
-rw-r--r-- | tests/test_git_command.py | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/tests/test_git_command.py b/tests/test_git_command.py index 51171a32..93300a6f 100644 --- a/tests/test_git_command.py +++ b/tests/test_git_command.py | |||
@@ -1,5 +1,3 @@ | |||
1 | # -*- coding:utf-8 -*- | ||
2 | # | ||
3 | # Copyright 2019 The Android Open Source Project | 1 | # Copyright 2019 The Android Open Source Project |
4 | # | 2 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -16,12 +14,16 @@ | |||
16 | 14 | ||
17 | """Unittests for the git_command.py module.""" | 15 | """Unittests for the git_command.py module.""" |
18 | 16 | ||
19 | from __future__ import print_function | ||
20 | |||
21 | import re | 17 | import re |
22 | import unittest | 18 | import unittest |
23 | 19 | ||
20 | try: | ||
21 | from unittest import mock | ||
22 | except ImportError: | ||
23 | import mock | ||
24 | |||
24 | import git_command | 25 | import git_command |
26 | import wrapper | ||
25 | 27 | ||
26 | 28 | ||
27 | class GitCallUnitTest(unittest.TestCase): | 29 | class GitCallUnitTest(unittest.TestCase): |
@@ -35,7 +37,7 @@ class GitCallUnitTest(unittest.TestCase): | |||
35 | # We don't dive too deep into the values here to avoid having to update | 37 | # 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 | 38 | # whenever git versions change. We do check relative to this min version |
37 | # as this is what `repo` itself requires via MIN_GIT_VERSION. | 39 | # as this is what `repo` itself requires via MIN_GIT_VERSION. |
38 | MIN_GIT_VERSION = (1, 7, 2) | 40 | MIN_GIT_VERSION = (2, 10, 2) |
39 | self.assertTrue(isinstance(ver.major, int)) | 41 | self.assertTrue(isinstance(ver.major, int)) |
40 | self.assertTrue(isinstance(ver.minor, int)) | 42 | self.assertTrue(isinstance(ver.minor, int)) |
41 | self.assertTrue(isinstance(ver.micro, int)) | 43 | self.assertTrue(isinstance(ver.micro, int)) |
@@ -76,3 +78,45 @@ class UserAgentUnitTest(unittest.TestCase): | |||
76 | # the general form. | 78 | # the general form. |
77 | m = re.match(r'^git/[^ ]+ ([^ ]+) git-repo/[^ ]+', ua) | 79 | m = re.match(r'^git/[^ ]+ ([^ ]+) git-repo/[^ ]+', ua) |
78 | self.assertIsNotNone(m) | 80 | self.assertIsNotNone(m) |
81 | |||
82 | |||
83 | class GitRequireTests(unittest.TestCase): | ||
84 | """Test the git_require helper.""" | ||
85 | |||
86 | def setUp(self): | ||
87 | ver = wrapper.GitVersion(1, 2, 3, 4) | ||
88 | mock.patch.object(git_command.git, 'version_tuple', return_value=ver).start() | ||
89 | |||
90 | def tearDown(self): | ||
91 | mock.patch.stopall() | ||
92 | |||
93 | def test_older_nonfatal(self): | ||
94 | """Test non-fatal require calls with old versions.""" | ||
95 | self.assertFalse(git_command.git_require((2,))) | ||
96 | self.assertFalse(git_command.git_require((1, 3))) | ||
97 | self.assertFalse(git_command.git_require((1, 2, 4))) | ||
98 | self.assertFalse(git_command.git_require((1, 2, 3, 5))) | ||
99 | |||
100 | def test_newer_nonfatal(self): | ||
101 | """Test non-fatal require calls with newer versions.""" | ||
102 | self.assertTrue(git_command.git_require((0,))) | ||
103 | self.assertTrue(git_command.git_require((1, 0))) | ||
104 | self.assertTrue(git_command.git_require((1, 2, 0))) | ||
105 | self.assertTrue(git_command.git_require((1, 2, 3, 0))) | ||
106 | |||
107 | def test_equal_nonfatal(self): | ||
108 | """Test require calls with equal values.""" | ||
109 | self.assertTrue(git_command.git_require((1, 2, 3, 4), fail=False)) | ||
110 | self.assertTrue(git_command.git_require((1, 2, 3, 4), fail=True)) | ||
111 | |||
112 | def test_older_fatal(self): | ||
113 | """Test fatal require calls with old versions.""" | ||
114 | with self.assertRaises(SystemExit) as e: | ||
115 | git_command.git_require((2,), fail=True) | ||
116 | self.assertNotEqual(0, e.code) | ||
117 | |||
118 | def test_older_fatal_msg(self): | ||
119 | """Test fatal require calls with old versions and message.""" | ||
120 | with self.assertRaises(SystemExit) as e: | ||
121 | git_command.git_require((2,), fail=True, msg='so sad') | ||
122 | self.assertNotEqual(0, e.code) | ||