15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from testsweet import TestBase, run_suite, InTempDir
18
from unittest import TestResult, TestCase
21
class TestBase(TestCase):
22
"""Base class for bzr test cases.
24
Just defines some useful helper functions; doesn't actually test
27
# TODO: Special methods to invoke bzr
29
def runcmd(self, cmd, expected=0):
30
self.log('$ ' + ' '.join(cmd))
31
from os import spawnvp, P_WAIT
32
rc = spawnvp(P_WAIT, cmd[0], cmd)
34
self.fail("command %r returned status %d" % (cmd, rc))
37
def backtick(self, cmd):
38
"""Run a command and return its output"""
40
self.log('$ ' + ' '.join(cmd))
51
self.fail("command %r returned status %d" % (cmd, rc))
57
"""Log a message to a progress file"""
63
class _MyResult(TestResult):
67
No special behaviour for now.
69
# def startTest(self, test):
70
# print str(test).ljust(50),
71
# TestResult.startTest(self, test)
73
# def stopTest(self, test):
75
# TestResult.stopTest(self, test)
22
84
from unittest import TestLoader, TestSuite
23
import bzrlib, bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, bzrlib.commands
25
86
import bzrlib.selftest.whitebox
26
87
import bzrlib.selftest.blackbox
27
import bzrlib.selftest.versioning
28
import bzrlib.selftest.testmerge3
29
import bzrlib.selftest.testhashcache
30
import bzrlib.merge_core
31
88
from doctest import DocTestSuite
38
TestBase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
39
print '%-30s %s' % ('bzr binary', TestBase.BZRPATH)
43
96
suite = TestSuite()
45
# should also test bzrlib.merge_core, but they seem to be out of date with
49
# python2.3's TestLoader() doesn't seem to work well; don't know why
51
for m in (bzrlib.store,
99
for m in bzrlib.selftest.whitebox, bzrlib.selftest.blackbox:
100
suite.addTest(tl.loadTestsFromModule(m))
102
for m in bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, \
57
104
suite.addTest(DocTestSuite(m))
59
for cl in (bzrlib.selftest.whitebox.TEST_CLASSES
60
+ bzrlib.selftest.versioning.TEST_CLASSES
61
+ bzrlib.selftest.testmerge3.TEST_CLASSES
62
+ bzrlib.selftest.testhashcache.TEST_CLASSES
63
+ bzrlib.selftest.blackbox.TEST_CLASSES):
66
suite.addTest(unittest.makeSuite(bzrlib.merge_core.MergeTest, 'test_'))
68
return run_suite(suite, 'testbzr')
109
_show_results(result)
111
return result.wasSuccessful()
114
def _setup_test_log():
119
log_filename = os.path.abspath('testbzr.log')
120
TEST_LOG = open(log_filename, 'wt', buffering=1) # line buffered
122
print >>TEST_LOG, "bzr tests run at " + time.ctime()
123
print '%-30s %s' % ('test log', log_filename)
126
def _setup_test_dir():
130
global ORIG_DIR, TEST_DIR
131
ORIG_DIR = os.getcwdu()
132
TEST_DIR = os.path.abspath("testbzr.tmp")
134
print '%-30s %s' % ('running tests in', TEST_DIR)
136
if os.path.exists(TEST_DIR):
137
shutil.rmtree(TEST_DIR)
143
def _show_results(result):
144
for case, tb in result.errors:
145
_show_test_failure('ERROR', case, tb)
147
for case, tb in result.failures:
148
_show_test_failure('FAILURE', case, tb)
151
print '%4d tests run' % result.testsRun
152
print '%4d errors' % len(result.errors)
153
print '%4d failures' % len(result.failures)
157
def _show_test_failure(kind, case, tb):
158
print (kind + '! ').ljust(60, '-')
161
print ''.ljust(60, '-')