Kiln » Dependencies » Dulwich Read More
Clone URL:  
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# __init__.py -- The tests for dulwich # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net> # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 # of the License or (at your option) any later version of # the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. """Tests for Dulwich.""" import doctest import os import shutil import subprocess import sys import tempfile if sys.version_info >= (2, 7): # If Python itself provides an exception, use that import unittest from unittest import SkipTest, TestCase as _TestCase else: import unittest2 as unittest from unittest2 import SkipTest, TestCase as _TestCase def get_safe_env(env=None): """Returns the environment "env" (or a copy of "os.environ" by default) modified to avoid side-effects caused by user's ~/.gitconfig""" if env is None: env = os.environ.copy() # On Windows it's not enough to set "HOME" to a non-existing # directory. Git.cmd takes the first existing directory out of # "%HOME%", "%HOMEDRIVE%%HOMEPATH%" and "%USERPROFILE%". for e in 'HOME', 'HOMEPATH', 'USERPROFILE': env[e] = '/nosuchdir' return env class TestCase(_TestCase): def makeSafeEnv(self): """Create environment with homedirectory-related variables stripped. Modifies os.environ for the duration of a test case to avoid side-effects caused by the user's ~/.gitconfig and other files in their home directory. """ old_env = os.environ def restore(): os.environ = old_env self.addCleanup(restore) new_env = dict(os.environ) for e in ['HOME', 'HOMEPATH', 'USERPROFILE']: new_env[e] = '/nosuchdir' os.environ = new_env def setUp(self): super(TestCase, self).setUp() self.makeSafeEnv() class BlackboxTestCase(TestCase): """Blackbox testing.""" bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "bin")) def bin_path(self, name): """Determine the full path of a binary. :param name: Name of the script :return: Full path """ return os.path.join(self.bin_directory, name) def run_command(self, name, args): """Run a Dulwich command. :param name: Name of the command, as it exists in bin/ :param args: Arguments to the command """ env = dict(os.environ) env["PYTHONPATH"] = os.pathsep.join(sys.path) # Since they don't have any extensions, Windows can't recognize # executablility of the Python files in /bin. Even then, we'd have to # expect the user to set up file associations for .py files. # # Save us from all that headache and call python with the bin script. argv = [sys.executable, self.bin_path(name)] + args return subprocess.Popen(argv, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env) def self_test_suite(): names = [ 'blackbox', 'client', 'config', 'diff_tree', 'fastexport', 'file', 'index', 'lru_cache', 'objects', 'object_store', 'missing_obj_finder', 'pack', 'patch', 'protocol', 'repository', 'server', 'walk', 'web', ] module_names = ['dulwich.tests.test_' + name for name in names] loader = unittest.TestLoader() return loader.loadTestsFromNames(module_names) def tutorial_test_suite(): tutorial = [ 'introduction', 'repo', 'object-store', 'remote', 'conclusion', ] tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial] def setup(test): test.__old_cwd = os.getcwd() test.__dulwich_tempdir = tempfile.mkdtemp() os.chdir(test.__dulwich_tempdir) def teardown(test): os.chdir(test.__old_cwd) shutil.rmtree(test.__dulwich_tempdir) return doctest.DocFileSuite(setUp=setup, tearDown=teardown, *tutorial_files) def nocompat_test_suite(): result = unittest.TestSuite() result.addTests(self_test_suite()) result.addTests(tutorial_test_suite()) return result def compat_test_suite(): result = unittest.TestSuite() from dulwich.tests.compat import test_suite as compat_test_suite result.addTests(compat_test_suite()) return result def test_suite(): result = unittest.TestSuite() result.addTests(self_test_suite()) result.addTests(tutorial_test_suite()) from dulwich.tests.compat import test_suite as compat_test_suite result.addTests(compat_test_suite()) return result