251
283
self._cleanups.append(callable)
253
285
def _cleanEnvironment(self):
254
self.oldenv = os.environ.get('HOME', None)
255
os.environ['HOME'] = os.getcwd()
256
self.bzr_email = os.environ.get('BZREMAIL')
257
if self.bzr_email is not None:
258
del os.environ['BZREMAIL']
259
self.email = os.environ.get('EMAIL')
260
if self.email is not None:
261
del os.environ['EMAIL']
288
'APPDATA': os.getcwd(),
262
293
self.addCleanup(self._restoreEnvironment)
294
for name, value in new_env.iteritems():
295
self._captureVar(name, value)
298
def _captureVar(self, name, newvalue):
299
"""Set an environment variable, preparing it to be reset when finished."""
300
self.__old_env[name] = os.environ.get(name, None)
302
if name in os.environ:
305
os.environ[name] = newvalue
308
def _restoreVar(name, value):
310
if name in os.environ:
313
os.environ[name] = value
264
315
def _restoreEnvironment(self):
265
os.environ['HOME'] = self.oldenv
266
if os.environ.get('BZREMAIL') is not None:
267
del os.environ['BZREMAIL']
268
if self.bzr_email is not None:
269
os.environ['BZREMAIL'] = self.bzr_email
270
if os.environ.get('EMAIL') is not None:
271
del os.environ['EMAIL']
272
if self.email is not None:
273
os.environ['EMAIL'] = self.email
316
for name, value in self.__old_env.iteritems():
317
self._restoreVar(name, value)
275
319
def tearDown(self):
276
320
self._runCleanups()
553
609
def test_suite():
554
610
"""Build and return TestSuite for the whole program."""
555
import bzrlib.store, bzrlib.inventory, bzrlib.branch
556
import bzrlib.osutils, bzrlib.merge3, bzrlib.plugin
557
611
from doctest import DocTestSuite
559
global MODULES_TO_TEST, MODULES_TO_DOCTEST
613
global MODULES_TO_DOCTEST
561
615
# FIXME: If these fail to load, e.g. because of a syntax error, the
562
616
# exception is hidden by unittest. Sucks. Should either fix that or
563
617
# perhaps import them and pass them to unittest as modules.
564
618
testmod_names = \
565
['bzrlib.selftest.MetaTestLog',
566
'bzrlib.selftest.testapi',
567
'bzrlib.selftest.testgpg',
568
'bzrlib.selftest.testidentitymap',
569
'bzrlib.selftest.testinv',
570
'bzrlib.selftest.test_ancestry',
571
'bzrlib.selftest.test_commit',
572
'bzrlib.selftest.test_command',
573
'bzrlib.selftest.test_commit_merge',
574
'bzrlib.selftest.testconfig',
575
'bzrlib.selftest.versioning',
576
'bzrlib.selftest.testmerge3',
577
'bzrlib.selftest.testmerge',
578
'bzrlib.selftest.testhashcache',
579
'bzrlib.selftest.teststatus',
580
'bzrlib.selftest.testlog',
581
'bzrlib.selftest.testrevisionnamespaces',
582
'bzrlib.selftest.testbranch',
583
'bzrlib.selftest.testrevision',
584
'bzrlib.selftest.test_revision_info',
585
'bzrlib.selftest.test_merge_core',
586
'bzrlib.selftest.test_smart_add',
587
'bzrlib.selftest.test_bad_files',
588
'bzrlib.selftest.testdiff',
589
'bzrlib.selftest.test_parent',
590
'bzrlib.selftest.test_xml',
591
'bzrlib.selftest.test_weave',
592
'bzrlib.selftest.testfetch',
593
'bzrlib.selftest.whitebox',
594
'bzrlib.selftest.teststore',
595
'bzrlib.selftest.blackbox',
596
'bzrlib.selftest.testsampler',
597
'bzrlib.selftest.testtransactions',
598
'bzrlib.selftest.testtransport',
599
'bzrlib.selftest.testsftp',
600
'bzrlib.selftest.testgraph',
601
'bzrlib.selftest.testworkingtree',
602
'bzrlib.selftest.test_upgrade',
603
'bzrlib.selftest.test_conflicts',
604
'bzrlib.selftest.testtestament',
605
'bzrlib.selftest.testannotate',
606
'bzrlib.selftest.testrevprops',
607
'bzrlib.selftest.testoptions',
608
'bzrlib.selftest.testhttp',
609
'bzrlib.selftest.testnonascii',
610
'bzrlib.selftest.testreweave',
611
'bzrlib.selftest.testtsort',
612
'bzrlib.selftest.testtrace',
619
['bzrlib.tests.MetaTestLog',
620
'bzrlib.tests.test_api',
621
'bzrlib.tests.test_gpg',
622
'bzrlib.tests.test_identitymap',
623
'bzrlib.tests.test_inv',
624
'bzrlib.tests.test_ancestry',
625
'bzrlib.tests.test_commit',
626
'bzrlib.tests.test_command',
627
'bzrlib.tests.test_commit_merge',
628
'bzrlib.tests.test_config',
629
'bzrlib.tests.test_merge3',
630
'bzrlib.tests.test_merge',
631
'bzrlib.tests.test_hashcache',
632
'bzrlib.tests.test_status',
633
'bzrlib.tests.test_log',
634
'bzrlib.tests.test_revisionnamespaces',
635
'bzrlib.tests.test_branch',
636
'bzrlib.tests.test_revision',
637
'bzrlib.tests.test_revision_info',
638
'bzrlib.tests.test_merge_core',
639
'bzrlib.tests.test_smart_add',
640
'bzrlib.tests.test_bad_files',
641
'bzrlib.tests.test_diff',
642
'bzrlib.tests.test_parent',
643
'bzrlib.tests.test_xml',
644
'bzrlib.tests.test_weave',
645
'bzrlib.tests.test_fetch',
646
'bzrlib.tests.test_whitebox',
647
'bzrlib.tests.test_store',
648
'bzrlib.tests.test_sampler',
649
'bzrlib.tests.test_transactions',
650
'bzrlib.tests.test_transport',
651
'bzrlib.tests.test_sftp',
652
'bzrlib.tests.test_graph',
653
'bzrlib.tests.test_workingtree',
654
'bzrlib.tests.test_upgrade',
655
'bzrlib.tests.test_uncommit',
656
'bzrlib.tests.test_conflicts',
657
'bzrlib.tests.test_testament',
658
'bzrlib.tests.test_annotate',
659
'bzrlib.tests.test_revprops',
660
'bzrlib.tests.test_options',
661
'bzrlib.tests.test_http',
662
'bzrlib.tests.test_nonascii',
663
'bzrlib.tests.test_reweave',
664
'bzrlib.tests.test_tsort',
665
'bzrlib.tests.test_trace',
666
'bzrlib.tests.test_rio',
615
for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,
616
bzrlib.osutils, bzrlib.commands, bzrlib.merge3,
619
if m not in MODULES_TO_DOCTEST:
620
MODULES_TO_DOCTEST.append(m)
622
669
TestCase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
623
670
print '%-30s %s' % ('bzr binary', TestCase.BZRPATH)
625
672
suite = TestSuite()
626
673
suite.addTest(TestLoader().loadTestsFromNames(testmod_names))
674
for package in packages_to_test():
675
suite.addTest(package.test_suite())
627
676
for m in MODULES_TO_TEST:
628
suite.addTest(TestLoader().loadTestsFromModule(m))
677
suite.addTest(TestLoader().loadTestsFromModule(m))
629
678
for m in (MODULES_TO_DOCTEST):
630
679
suite.addTest(DocTestSuite(m))
631
680
for p in bzrlib.plugin.all_plugins: