~ubuntu-branches/ubuntu/quantal/dulwich/quantal

« back to all changes in this revision

Viewing changes to .pc/01_reset_chdir/dulwich/tests/__init__.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2011-10-31 13:07:39 UTC
  • mfrom: (1.2.17)
  • Revision ID: package-import@ubuntu.com-20111031130739-mcjs1sqp6hmwro2y
Tags: 0.8.1-1
* New upstream release.
 + Now provides access to remote http(s) smart server repositories.
   Closes: #636331

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# __init__.py -- The tests for dulwich
 
2
# Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
 
3
#
 
4
# This program is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU General Public License
 
6
# as published by the Free Software Foundation; version 2
 
7
# of the License or (at your option) any later version of
 
8
# the License.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
# MA  02110-1301, USA.
 
19
 
 
20
"""Tests for Dulwich."""
 
21
 
 
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):
 
31
    # If Python itself provides an exception, use that
 
32
    import unittest
 
33
    from unittest import SkipTest, TestCase
 
34
else:
 
35
    import unittest2 as unittest
 
36
    from unittest2 import SkipTest, TestCase
 
37
 
 
38
 
 
39
class BlackboxTestCase(TestCase):
 
40
    """Blackbox testing."""
 
41
 
 
42
    bin_directory = os.path.abspath(os.path.join(os.path.dirname(__file__),
 
43
        "..", "..", "bin"))
 
44
 
 
45
    def bin_path(self, name):
 
46
        """Determine the full path of a binary.
 
47
 
 
48
        :param name: Name of the script
 
49
        :return: Full path
 
50
        """
 
51
        return os.path.join(self.bin_directory, name)
 
52
 
 
53
    def run_command(self, name, args):
 
54
        """Run a Dulwich command.
 
55
 
 
56
        :param name: Name of the command, as it exists in bin/
 
57
        :param args: Arguments to the command
 
58
        """
 
59
        env = dict(os.environ)
 
60
        env["PYTHONPATH"] = os.pathsep.join(sys.path)
 
61
 
 
62
        # Since they don't have any extensions, Windows can't recognize
 
63
        # executablility of the Python files in /bin. Even then, we'd have to
 
64
        # expect the user to set up file associations for .py files.
 
65
        #
 
66
        # Save us from all that headache and call python with the bin script.
 
67
        argv = [sys.executable, self.bin_path(name)] + args
 
68
        return subprocess.Popen(argv,
 
69
            stdout=subprocess.PIPE,
 
70
            stdin=subprocess.PIPE, stderr=subprocess.PIPE,
 
71
            env=env)
 
72
 
 
73
 
 
74
def self_test_suite():
 
75
    names = [
 
76
        'blackbox',
 
77
        'client',
 
78
        'diff_tree',
 
79
        'fastexport',
 
80
        'file',
 
81
        'index',
 
82
        'lru_cache',
 
83
        'objects',
 
84
        'object_store',
 
85
        'pack',
 
86
        'patch',
 
87
        'protocol',
 
88
        'repository',
 
89
        'server',
 
90
        'walk',
 
91
        'web',
 
92
        ]
 
93
    module_names = ['dulwich.tests.test_' + name for name in names]
 
94
    loader = unittest.TestLoader()
 
95
    return loader.loadTestsFromNames(module_names)
 
96
 
 
97
 
 
98
def tutorial_test_suite():
 
99
    tutorial = [
 
100
        'introduction',
 
101
        'repo',
 
102
        'object-store',
 
103
        'conclusion',
 
104
        ]
 
105
    tutorial_files = ["../../docs/tutorial/%s.txt" % name for name in tutorial]
 
106
    def setup(test):
 
107
        test.__dulwich_tempdir = tempfile.mkdtemp()
 
108
        os.chdir(test.__dulwich_tempdir)
 
109
    def teardown(test):
 
110
        shutil.rmtree(test.__dulwich_tempdir)
 
111
    return doctest.DocFileSuite(setUp=setup, tearDown=teardown,
 
112
        *tutorial_files)
 
113
 
 
114
 
 
115
def nocompat_test_suite():
 
116
    result = unittest.TestSuite()
 
117
    result.addTests(self_test_suite())
 
118
    result.addTests(tutorial_test_suite())
 
119
    return result
 
120
 
 
121
 
 
122
def test_suite():
 
123
    result = unittest.TestSuite()
 
124
    result.addTests(self_test_suite())
 
125
    result.addTests(tutorial_test_suite())
 
126
    from dulwich.tests.compat import test_suite as compat_test_suite
 
127
    result.addTests(compat_test_suite())
 
128
    return result