~ubuntu-branches/ubuntu/oneiric/dulwich/oneiric

« back to all changes in this revision

Viewing changes to dulwich/tests/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-01-21 19:38:13 UTC
  • mfrom: (1.2.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20110121193813-2cnp21akwf5j0pq2
Tags: 0.7.0-1
* New upstream release.
 + Changes default test runner from nose to testtools.
* Drop Pure- from the description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
"""Tests for Dulwich."""
21
21
 
22
 
import unittest
23
 
 
24
 
try:
25
 
    from testtools.testcase import TestCase
26
 
except ImportError:
27
 
    from unittest import TestCase
28
 
 
29
 
try:
 
22
import doctest
 
23
import os
 
24
import shutil
 
25
import subprocess
 
26
import sys
 
27
import tempfile
 
28
 
 
29
 
 
30
if sys.version_info >= (2, 7):
30
31
    # If Python itself provides an exception, use that
 
32
    import unittest
31
33
    from unittest import SkipTest as TestSkipped
32
 
except ImportError:
33
 
    # Check if the nose exception can be used
 
34
    from unittest import TestCase
 
35
else:
34
36
    try:
35
 
        import nose
 
37
        import unittest2 as unittest
 
38
        from unittest2 import SkipTest as TestSkipped
 
39
        from unittest2 import TestCase
36
40
    except ImportError:
37
 
        try:
38
 
            import testtools.testcase
39
 
        except ImportError:
40
 
            class TestSkipped(Exception):
41
 
                def __init__(self, msg):
42
 
                    self.msg = msg
43
 
        else:
44
 
            TestSkipped = testtools.testcase.TestCase.skipException
45
 
    else:
46
 
        TestSkipped = nose.SkipTest
47
 
        try:
48
 
            import testtools.testcase
49
 
        except ImportError:
50
 
            pass
51
 
        else:
52
 
            # Make testtools use the same exception class as nose
53
 
            testtools.testcase.TestCase.skipException = TestSkipped
54
 
 
55
 
 
56
 
def test_suite():
 
41
        import unittest
 
42
        from testtools.testcase import TestSkipped
 
43
        from testtools.testcase import TestCase
 
44
        TestCase.skipException = TestSkipped
 
45
 
 
46
 
 
47
class BlackboxTestCase(TestCase):
 
48
    """Blackbox testing."""
 
49
 
 
50
    bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
 
51
        "..", "..", "bin"))
 
52
 
 
53
    def bin_path(self, name):
 
54
        """Determine the full path of a binary.
 
55
 
 
56
        :param name: Name of the script
 
57
        :return: Full path
 
58
        """
 
59
        return os.path.join(self.bin_directory, name)
 
60
 
 
61
    def run_command(self, name, args):
 
62
        """Run a Dulwich command.
 
63
 
 
64
        :param name: Name of the command, as it exists in bin/
 
65
        :param args: Arguments to the command
 
66
        """
 
67
        env = dict(os.environ)
 
68
        env["PYTHONPATH"] = os.pathsep.join(sys.path)
 
69
 
 
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.
 
73
        #
 
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,
 
79
            env=env)
 
80
 
 
81
 
 
82
def self_test_suite():
57
83
    names = [
 
84
        'blackbox',
58
85
        'client',
59
86
        'fastexport',
60
87
        'file',
70
97
        'web',
71
98
        ]
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)
 
102
 
 
103
 
 
104
def tutorial_test_suite():
 
105
    tutorial = [
 
106
        '0-introduction',
 
107
        '1-repo',
 
108
        '2-object-store',
 
109
        '3-conclusion',
 
110
        ]
 
111
    tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
 
112
    def setup(test):
 
113
        test.__dulwich_tempdir = tempfile.mkdtemp()
 
114
        os.chdir(test.__dulwich_tempdir)
 
115
    def teardown(test):
 
116
        shutil.rmtree(test.__dulwich_tempdir)
 
117
    return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
 
118
        *tutorial_files)
 
119
 
 
120
 
 
121
def nocompat_test_suite():
 
122
    result = unittest.TestSuite()
 
123
    result.addTests(self_test_suite())
 
124
    result.addTests(tutorial_test_suite())
 
125
    return result
 
126
 
 
127
 
 
128
def 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())
77
134
    return result