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 / __init__.py @ 959

History | View | Annotate | Download (5.14 KB)

1
# __init__.py -- The tests for dulwich
2
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
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 Dulwich."""
22

    
23
import doctest
24
import os
25
import shutil
26
import subprocess
27
import sys
28
import tempfile
29

    
30

    
31
# If Python itself provides an exception, use that
32
import unittest
33
from unittest import SkipTest, TestCase as _TestCase, skipIf, expectedFailure
34

    
35

    
36
class TestCase(_TestCase):
37

    
38
    def setUp(self):
39
        super(TestCase, self).setUp()
40
        self._old_home = os.environ.get("HOME")
41
        os.environ["HOME"] = "/nonexistant"
42

    
43
    def tearDown(self):
44
        super(TestCase, self).tearDown()
45
        if self._old_home:
46
            os.environ["HOME"] = self._old_home
47
        else:
48
            del os.environ["HOME"]
49

    
50

    
51
class BlackboxTestCase(TestCase):
52
    """Blackbox testing."""
53

    
54
    # TODO(jelmer): Include more possible binary paths.
55
    bin_directories = [os.path.abspath(os.path.join(os.path.dirname(__file__),
56
        "..", "..", "bin")), '/usr/bin', '/usr/local/bin']
57

    
58
    def bin_path(self, name):
59
        """Determine the full path of a binary.
60

61
        :param name: Name of the script
62
        :return: Full path
63
        """
64
        for d in self.bin_directories:
65
            p = os.path.join(d, name)
66
            if os.path.isfile(p):
67
                return p
68
        else:
69
            raise SkipTest("Unable to find binary %s" % name)
70

    
71
    def run_command(self, name, args):
72
        """Run a Dulwich command.
73

74
        :param name: Name of the command, as it exists in bin/
75
        :param args: Arguments to the command
76
        """
77
        env = dict(os.environ)
78
        env["PYTHONPATH"] = os.pathsep.join(sys.path)
79

    
80
        # Since they don't have any extensions, Windows can't recognize
81
        # executablility of the Python files in /bin. Even then, we'd have to
82
        # expect the user to set up file associations for .py files.
83
        #
84
        # Save us from all that headache and call python with the bin script.
85
        argv = [sys.executable, self.bin_path(name)] + args
86
        return subprocess.Popen(argv,
87
            stdout=subprocess.PIPE,
88
            stdin=subprocess.PIPE, stderr=subprocess.PIPE,
89
            env=env)
90

    
91

    
92
def self_test_suite():
93
    names = [
94
        'archive',
95
        'blackbox',
96
        'client',
97
        'config',
98
        'diff_tree',
99
        'fastexport',
100
        'file',
101
        'grafts',
102
        'greenthreads',
103
        'hooks',
104
        'index',
105
        'lru_cache',
106
        'objects',
107
        'objectspec',
108
        'object_store',
109
        'missing_obj_finder',
110
        'pack',
111
        'patch',
112
        'porcelain',
113
        'protocol',
114
        'reflog',
115
        'refs',
116
        'repository',
117
        'server',
118
        'walk',
119
        'web',
120
        ]
121
    module_names = ['dulwich.tests.test_' + name for name in names]
122
    loader = unittest.TestLoader()
123
    return loader.loadTestsFromNames(module_names)
124

    
125

    
126
def tutorial_test_suite():
127
    tutorial = [
128
        'introduction',
129
        'file-format',
130
        'repo',
131
        'object-store',
132
        'remote',
133
        'conclusion',
134
        ]
135
    tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
136
    def setup(test):
137
        test.__old_cwd = os.getcwd()
138
        test.__dulwich_tempdir = tempfile.mkdtemp()
139
        os.chdir(test.__dulwich_tempdir)
140
    def teardown(test):
141
        os.chdir(test.__old_cwd)
142
        shutil.rmtree(test.__dulwich_tempdir)
143
    return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
144
        *tutorial_files)
145

    
146

    
147
def nocompat_test_suite():
148
    result = unittest.TestSuite()
149
    result.addTests(self_test_suite())
150
    from dulwich.contrib import test_suite as contrib_test_suite
151
    if sys.version_info[0] == 2:
152
        result.addTests(tutorial_test_suite())
153
    result.addTests(contrib_test_suite())
154
    return result
155

    
156

    
157
def compat_test_suite():
158
    result = unittest.TestSuite()
159
    from dulwich.tests.compat import test_suite as compat_test_suite
160
    result.addTests(compat_test_suite())
161
    return result
162

    
163

    
164
def test_suite():
165
    result = unittest.TestSuite()
166
    result.addTests(self_test_suite())
167
    if sys.version_info[0] == 2 and sys.platform != 'win32':
168
        result.addTests(tutorial_test_suite())
169
    from dulwich.tests.compat import test_suite as compat_test_suite
170
    result.addTests(compat_test_suite())
171
    from dulwich.contrib import test_suite as contrib_test_suite
172
    result.addTests(contrib_test_suite())
173
    return result