summaryrefslogtreecommitdiffstats
path: root/tests/test_git_command.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_git_command.py')
-rw-r--r--tests/test_git_command.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_git_command.py b/tests/test_git_command.py
index 8d9b5f00..c2d3f1df 100644
--- a/tests/test_git_command.py
+++ b/tests/test_git_command.py
@@ -21,7 +21,13 @@ from __future__ import print_function
21import re 21import re
22import unittest 22import unittest
23 23
24try:
25 from unittest import mock
26except ImportError:
27 import mock
28
24import git_command 29import git_command
30import wrapper
25 31
26 32
27class GitCallUnitTest(unittest.TestCase): 33class GitCallUnitTest(unittest.TestCase):
@@ -76,3 +82,45 @@ class UserAgentUnitTest(unittest.TestCase):
76 # the general form. 82 # the general form.
77 m = re.match(r'^git/[^ ]+ ([^ ]+) git-repo/[^ ]+', ua) 83 m = re.match(r'^git/[^ ]+ ([^ ]+) git-repo/[^ ]+', ua)
78 self.assertIsNotNone(m) 84 self.assertIsNotNone(m)
85
86
87class GitRequireTests(unittest.TestCase):
88 """Test the git_require helper."""
89
90 def setUp(self):
91 ver = wrapper.GitVersion(1, 2, 3, 4)
92 mock.patch.object(git_command.git, 'version_tuple', return_value=ver).start()
93
94 def tearDown(self):
95 mock.patch.stopall()
96
97 def test_older_nonfatal(self):
98 """Test non-fatal require calls with old versions."""
99 self.assertFalse(git_command.git_require((2,)))
100 self.assertFalse(git_command.git_require((1, 3)))
101 self.assertFalse(git_command.git_require((1, 2, 4)))
102 self.assertFalse(git_command.git_require((1, 2, 3, 5)))
103
104 def test_newer_nonfatal(self):
105 """Test non-fatal require calls with newer versions."""
106 self.assertTrue(git_command.git_require((0,)))
107 self.assertTrue(git_command.git_require((1, 0)))
108 self.assertTrue(git_command.git_require((1, 2, 0)))
109 self.assertTrue(git_command.git_require((1, 2, 3, 0)))
110
111 def test_equal_nonfatal(self):
112 """Test require calls with equal values."""
113 self.assertTrue(git_command.git_require((1, 2, 3, 4), fail=False))
114 self.assertTrue(git_command.git_require((1, 2, 3, 4), fail=True))
115
116 def test_older_fatal(self):
117 """Test fatal require calls with old versions."""
118 with self.assertRaises(SystemExit) as e:
119 git_command.git_require((2,), fail=True)
120 self.assertNotEqual(0, e.code)
121
122 def test_older_fatal_msg(self):
123 """Test fatal require calls with old versions and message."""
124 with self.assertRaises(SystemExit) as e:
125 git_command.git_require((2,), fail=True, msg='so sad')
126 self.assertNotEqual(0, e.code)