/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_selftest.py

  • Committer: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""UI tests for the test framework."""
18
18
 
 
19
from cStringIO import StringIO
19
20
import os
20
21
import re
21
22
import signal
22
23
import sys
 
24
import unittest
23
25
 
24
26
import bzrlib
25
27
from bzrlib import (
27
29
    )
28
30
from bzrlib.errors import ParamikoNotPresent
29
31
from bzrlib.tests import (
 
32
                          SubUnitFeature,
30
33
                          TestCase,
31
34
                          TestCaseInTempDir,
32
35
                          TestCaseWithMemoryTransport,
88
91
            TestOptions.current_test = None
89
92
            TestCaseWithMemoryTransport.TEST_ROOT = old_root
90
93
 
 
94
    def test_subunit(self):
 
95
        """Passing --subunit results in subunit output."""
 
96
        self.requireFeature(SubUnitFeature)
 
97
        from subunit import ProtocolTestCase
 
98
        stdout = self.run_bzr(
 
99
            'selftest --subunit --no-plugins '
 
100
            'tests.test_selftest.SelftestTests.test_import_tests')[0]
 
101
        stream = StringIO(str(stdout))
 
102
        test = ProtocolTestCase(stream)
 
103
        result = unittest.TestResult()
 
104
        test.run(result)
 
105
        self.assertEqual(1, result.testsRun)
 
106
 
91
107
 
92
108
class TestRunBzr(ExternalBase):
93
109
 
180
196
        finally:
181
197
            TestCaseWithMemoryTransport.TEST_ROOT = old_root
182
198
        self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK')
183
 
        self.assertEqual(
184
 
            'tests passed\n',
185
 
            err)
 
199
        self.assertContainsRe(out, 'tests passed\n')
186
200
        benchfile = open(".perf_history", "rt")
187
201
        try:
188
202
            lines = benchfile.readlines()
469
483
class TestSelftestListOnly(TestCase):
470
484
 
471
485
    @staticmethod
472
 
    def _parse_test_list(lines, newlines_in_header=1):
 
486
    def _parse_test_list(lines, newlines_in_header=0):
473
487
        "Parse a list of lines into a tuple of 3 lists (header,body,footer)."
474
 
        in_header = True
 
488
        in_header = newlines_in_header != 0
475
489
        in_footer = False
476
490
        header = []
477
491
        body = []
500
514
    def test_list_only(self):
501
515
        # check that bzr selftest --list-only works correctly
502
516
        out,err = self.run_bzr('selftest selftest --list-only')
503
 
        self.assertEndsWith(err, 'tests passed\n')
504
517
        (header,body,footer) = self._parse_test_list(out.splitlines())
505
518
        num_tests = len(body)
506
 
        self.assertContainsRe(footer[0], 'Listed %s tests in' % num_tests)
 
519
        self.assertLength(0, header)
 
520
        self.assertLength(0, footer)
 
521
        self.assertEqual('', err)
507
522
 
508
523
    def test_list_only_filtered(self):
509
524
        # check that a filtered --list-only works, both include and exclude
533
548
        out_rand,err_rand = self.run_bzr(['selftest', '--list-only',
534
549
                                          'selftest', '--randomize', 'now'])
535
550
        (header_rand,tests_rand,dummy) = self._parse_test_list(
536
 
            out_rand.splitlines(), 2)
 
551
            out_rand.splitlines(), 1)
537
552
        # XXX: The following line asserts that the randomized order is not the
538
553
        # same as the default order.  It is just possible that they'll get
539
554
        # randomized into the same order and this will falsely fail, but
548
563
        out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only',
549
564
                                            'selftest', '--randomize', seed])
550
565
        (header_rand2,tests_rand2,dummy) = self._parse_test_list(
551
 
            out_rand2.splitlines(), 2)
 
566
            out_rand2.splitlines(), 1)
552
567
        self.assertEqual(tests_rand, tests_rand2)
553
568
 
554
569
 
563
578
        fl.close()
564
579
        out, err = self.run_bzr(
565
580
            ['selftest', '--load-list', test_list_fname, '--list'])
566
 
        self.assertContainsRe(out, "Listed 1 test in")
 
581
        self.assertContainsRe(out, "TestSelftestWithIdList")
 
582
        self.assertLength(1, out.splitlines())
567
583
 
568
584
    def test_load_unknown(self):
569
585
        out, err = self.run_bzr('selftest --load-list I_do_not_exist ',
575
591
    def test_starting_with_single_argument(self):
576
592
        out, err = self.run_bzr(
577
593
            ['selftest', '--starting-with', self.id(), '--list'])
578
 
        self.assertContainsRe(out, "Listed 1 test in")
579
594
        self.assertContainsRe(out, self.id())
580
595
 
581
596
    def test_starting_with_multiple_argument(self):
584
599
             '--starting-with', self.id(),
585
600
             '--starting-with', 'bzrlib.tests.test_sampler',
586
601
             '--list'])
587
 
        self.assertContainsRe(out, "Listed 2 tests in")
588
602
        self.assertContainsRe(out, self.id())
589
603
        self.assertContainsRe(out, 'bzrlib.tests.test_sampler')