20
20
"""Tests for Dulwich."""
25
from testtools.testcase import TestCase
27
from unittest import TestCase
30
if sys.version_info >= (2, 7):
30
31
# If Python itself provides an exception, use that
31
33
from unittest import SkipTest as TestSkipped
33
# Check if the nose exception can be used
34
from unittest import TestCase
37
import unittest2 as unittest
38
from unittest2 import SkipTest as TestSkipped
39
from unittest2 import TestCase
36
40
except ImportError:
38
import testtools.testcase
40
class TestSkipped(Exception):
41
def __init__(self, msg):
44
TestSkipped = testtools.testcase.TestCase.skipException
46
TestSkipped = nose.SkipTest
48
import testtools.testcase
52
# Make testtools use the same exception class as nose
53
testtools.testcase.TestCase.skipException = TestSkipped
42
from testtools.testcase import TestSkipped
43
from testtools.testcase import TestCase
44
TestCase.skipException = TestSkipped
47
class BlackboxTestCase(TestCase):
48
"""Blackbox testing."""
50
bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
53
def bin_path(self, name):
54
"""Determine the full path of a binary.
56
:param name: Name of the script
59
return os.path.join(self.bin_directory, name)
61
def run_command(self, name, args):
62
"""Run a Dulwich command.
64
:param name: Name of the command, as it exists in bin/
65
:param args: Arguments to the command
67
env = dict(os.environ)
68
env["PYTHONPATH"] = os.pathsep.join(sys.path)
70
# Since they don't have any extensions, Windows can't recognize
71
# executablility of the Python files in /bin. Even then, we'd have to
72
# expect the user to set up file associations for .py files.
74
# Save us from all that headache and call python with the bin script.
75
argv = [sys.executable, self.bin_path(name)] + args
76
return subprocess.Popen(argv,
77
stdout=subprocess.PIPE,
78
stdin=subprocess.PIPE, stderr=subprocess.PIPE,
82
def self_test_suite():
72
99
module_names = ['dulwich.tests.test_' + name for name in names]
73
result = unittest.TestSuite()
74
100
loader = unittest.TestLoader()
75
suite = loader.loadTestsFromNames(module_names)
76
result.addTests(suite)
101
return loader.loadTestsFromNames(module_names)
104
def tutorial_test_suite():
111
tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
113
test.__dulwich_tempdir = tempfile.mkdtemp()
114
os.chdir(test.__dulwich_tempdir)
116
shutil.rmtree(test.__dulwich_tempdir)
117
return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
121
def nocompat_test_suite():
122
result = unittest.TestSuite()
123
result.addTests(self_test_suite())
124
result.addTests(tutorial_test_suite())
129
result = unittest.TestSuite()
130
result.addTests(self_test_suite())
131
result.addTests(tutorial_test_suite())
132
from dulwich.tests.compat import test_suite as compat_test_suite
133
result.addTests(compat_test_suite())