~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2007-04-26 05:49:56 UTC
  • mfrom: (2459 +trunk)
  • mto: (2420.2.1 bzr.http.auth)
  • mto: This revision was merged to the branch mainline in revision 2463.
  • Revision ID: andrew.bennetts@canonical.com-20070426054956-eipakzwjs76a14wq
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""UI tests for the test framework."""
18
18
 
19
19
import os
 
20
import re
20
21
import signal
21
22
import sys
22
23
 
102
103
        self.encoding = encoding
103
104
        self.stdin = stdin
104
105
        self.working_dir = working_dir
 
106
        return '', ''
105
107
 
106
108
    def test_args(self):
107
109
        """Test that run_bzr passes args correctly to run_bzr_captured"""
491
493
        self.assertEquals(['bzr','bzrlib','setup.py',
492
494
                           'test9999.tmp','tests'],
493
495
                           after)
 
496
 
 
497
 
 
498
class TestSelftestListOnly(TestCase):
 
499
 
 
500
    @staticmethod
 
501
    def _parse_test_list(lines, newlines_in_header=1):
 
502
        "Parse a list of lines into a tuple of 3 lists (header,body,footer)."
 
503
 
 
504
        in_header = True
 
505
        in_footer = False
 
506
        header = []
 
507
        body = []
 
508
        footer = []
 
509
        header_newlines_found = 0 
 
510
        for line in lines:
 
511
            if in_header:
 
512
                if line == '':
 
513
                    header_newlines_found += 1
 
514
                    if header_newlines_found >= newlines_in_header:
 
515
                        in_header = False
 
516
                        continue
 
517
                header.append(line)
 
518
            elif not in_footer:
 
519
                if line.startswith('-------'):
 
520
                    in_footer = True
 
521
                else:
 
522
                    body.append(line)
 
523
            else:
 
524
                footer.append(line)
 
525
        # If the last body line is blank, drop it off the list
 
526
        if len(body) > 0 and body[-1] == '':
 
527
            body.pop()                
 
528
        return (header,body,footer)
 
529
 
 
530
    def test_list_only(self):
 
531
        # check that bzr selftest --list-only works correctly
 
532
        out,err = self.run_bzr_captured(['selftest', 'selftest',
 
533
            '--list-only'])
 
534
        self.assertEndsWith(err, 'tests passed\n')
 
535
        (header,body,footer) = self._parse_test_list(out.splitlines())
 
536
        num_tests = len(body)
 
537
        self.assertContainsRe(footer[0], 'Listed %s tests in' % num_tests)
 
538
 
 
539
    def test_list_only_filtered(self):
 
540
        # check that a filtered --list-only works, both include and exclude
 
541
        out_all,err_all = self.run_bzr_captured(['selftest', '--list-only'])
 
542
        tests_all = self._parse_test_list(out_all.splitlines())[1]
 
543
        out_incl,err_incl = self.run_bzr_captured(['selftest', '--list-only',
 
544
          'selftest'])
 
545
        tests_incl = self._parse_test_list(out_incl.splitlines())[1]
 
546
        self.assertSubset(tests_incl, tests_all)
 
547
        out_excl,err_excl = self.run_bzr_captured(['selftest', '--list-only',
 
548
          '--exclude', 'selftest'])
 
549
        tests_excl = self._parse_test_list(out_excl.splitlines())[1]
 
550
        self.assertSubset(tests_excl, tests_all)
 
551
        set_incl = set(tests_incl)
 
552
        set_excl = set(tests_excl)
 
553
        intersection = set_incl.intersection(set_excl)
 
554
        self.assertEquals(0, len(intersection))
 
555
        self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl))
 
556
 
 
557
    def test_list_only_random(self):
 
558
        # check that --randomize works correctly
 
559
        out_all,err_all = self.run_bzr_captured(['selftest', '--list-only',
 
560
            'selftest'])
 
561
        tests_all = self._parse_test_list(out_all.splitlines())[1]
 
562
        out_rand,err_rand = self.run_bzr_captured(['selftest', '--list-only',
 
563
            'selftest', '--randomize', 'now'])
 
564
        (header_rand,tests_rand,dummy) = self._parse_test_list(
 
565
            out_rand.splitlines(), 2)
 
566
        self.assertNotEqual(tests_all, tests_rand)
 
567
        self.assertEqual(sorted(tests_all), sorted(tests_rand))
 
568
        # Check that the seed can be reused to get the exact same order
 
569
        seed_re = re.compile('Randomizing test order using seed (\w+)')
 
570
        match_obj = seed_re.search(header_rand[-1])
 
571
        seed = match_obj.group(1)
 
572
        out_rand2,err_rand2 = self.run_bzr_captured(['selftest', '--list-only',
 
573
            'selftest', '--randomize', seed])
 
574
        (header_rand2,tests_rand2,dummy) = self._parse_test_list(
 
575
            out_rand2.splitlines(), 2)
 
576
        self.assertEqual(tests_rand, tests_rand2)
 
577