Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / dulwich / tests / compat / test_utils.py @ 959

History | View | Annotate | Download (3.48 KB)

1
# test_utils.py -- Tests for git compatibility utilities
2
# Copyright (C) 2010 Google, Inc.
3
#
4
# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
5
# General Public License as public by the Free Software Foundation; version 2.0
6
# or (at your option) any later version. You can redistribute it and/or
7
# modify it under the terms of either of these two licenses.
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
#
15
# You should have received a copy of the licenses; if not, see
16
# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
17
# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
18
# License, Version 2.0.
19
#
20

    
21
"""Tests for git compatibility utilities."""
22

    
23
from dulwich.tests import (
24
    SkipTest,
25
    TestCase,
26
    )
27
from dulwich.tests.compat import utils
28

    
29

    
30
class GitVersionTests(TestCase):
31

    
32
    def setUp(self):
33
        super(GitVersionTests, self).setUp()
34
        self._orig_run_git = utils.run_git
35
        self._version_str = None  # tests can override to set stub version
36

    
37
        def run_git(args, **unused_kwargs):
38
            self.assertEqual(['--version'], args)
39
            return 0, self._version_str
40
        utils.run_git = run_git
41

    
42
    def tearDown(self):
43
        super(GitVersionTests, self).tearDown()
44
        utils.run_git = self._orig_run_git
45

    
46
    def test_git_version_none(self):
47
        self._version_str = b'not a git version'
48
        self.assertEqual(None, utils.git_version())
49

    
50
    def test_git_version_3(self):
51
        self._version_str = b'git version 1.6.6'
52
        self.assertEqual((1, 6, 6, 0), utils.git_version())
53

    
54
    def test_git_version_4(self):
55
        self._version_str = b'git version 1.7.0.2'
56
        self.assertEqual((1, 7, 0, 2), utils.git_version())
57

    
58
    def test_git_version_extra(self):
59
        self._version_str = b'git version 1.7.0.3.295.gd8fa2'
60
        self.assertEqual((1, 7, 0, 3), utils.git_version())
61

    
62
    def assertRequireSucceeds(self, required_version):
63
        try:
64
            utils.require_git_version(required_version)
65
        except SkipTest:
66
            self.fail()
67

    
68
    def assertRequireFails(self, required_version):
69
        self.assertRaises(SkipTest, utils.require_git_version,
70
                          required_version)
71

    
72
    def test_require_git_version(self):
73
        try:
74
            self._version_str = b'git version 1.6.6'
75
            self.assertRequireSucceeds((1, 6, 6))
76
            self.assertRequireSucceeds((1, 6, 6, 0))
77
            self.assertRequireSucceeds((1, 6, 5))
78
            self.assertRequireSucceeds((1, 6, 5, 99))
79
            self.assertRequireFails((1, 7, 0))
80
            self.assertRequireFails((1, 7, 0, 2))
81
            self.assertRaises(ValueError, utils.require_git_version,
82
                              (1, 6, 6, 0, 0))
83

    
84
            self._version_str = b'git version 1.7.0.2'
85
            self.assertRequireSucceeds((1, 6, 6))
86
            self.assertRequireSucceeds((1, 6, 6, 0))
87
            self.assertRequireSucceeds((1, 7, 0))
88
            self.assertRequireSucceeds((1, 7, 0, 2))
89
            self.assertRequireFails((1, 7, 0, 3))
90
            self.assertRequireFails((1, 7, 1))
91
        except SkipTest as e:
92
            # This test is designed to catch all SkipTest exceptions.
93
            self.fail('Test unexpectedly skipped: %s' % e)