~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Robert Collins
  • Date: 2006-01-02 22:37:32 UTC
  • mfrom: (1185.50.33 bzr-jam-integration)
  • Revision ID: robertc@robertcollins.net-20060102223732-d5221b37ff0f7888
Merge in John Meinels integration branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import bzrlib.inventory
35
35
import bzrlib.merge3
36
36
import bzrlib.osutils
 
37
import bzrlib.osutils as osutils
37
38
import bzrlib.plugin
38
39
import bzrlib.store
39
40
import bzrlib.trace
97
98
        # at the end
98
99
        SHOW_DESCRIPTIONS = False
99
100
        if self.showAll:
100
 
            width = bzrlib.osutils.terminal_width()
 
101
            width = osutils.terminal_width()
101
102
            name_width = width - 15
102
103
            what = None
103
104
            if SHOW_DESCRIPTIONS:
257
258
            return
258
259
        raise AssertionError("texts not equal:\n" + 
259
260
                             self._ndiff_strings(a, b))      
 
261
        
 
262
    def assertStartsWith(self, s, prefix):
 
263
        if not s.startswith(prefix):
 
264
            raise AssertionError('string %r does not start with %r' % (s, prefix))
 
265
 
 
266
    def assertEndsWith(self, s, suffix):
 
267
        if not s.endswith(prefix):
 
268
            raise AssertionError('string %r does not end with %r' % (s, suffix))
260
269
 
261
270
    def assertContainsRe(self, haystack, needle_re):
262
271
        """Assert that a contains something matching a regular expression."""
524
533
                else:
525
534
                    raise
526
535
            # successfully created
527
 
            TestCaseInTempDir.TEST_ROOT = os.path.abspath(root)
 
536
            TestCaseInTempDir.TEST_ROOT = osutils.abspath(root)
528
537
            break
529
538
        # make a fake bzr directory there to prevent any tests propagating
530
539
        # up onto the source directory's real branch
531
 
        os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
 
540
        os.mkdir(osutils.pathjoin(TestCaseInTempDir.TEST_ROOT, '.bzr'))
532
541
 
533
542
    def setUp(self):
534
543
        super(TestCaseInTempDir, self).setUp()
536
545
        _currentdir = os.getcwdu()
537
546
        short_id = self.id().replace('bzrlib.tests.', '') \
538
547
                   .replace('__main__.', '')
539
 
        self.test_dir = os.path.join(self.TEST_ROOT, short_id)
 
548
        self.test_dir = osutils.pathjoin(self.TEST_ROOT, short_id)
540
549
        os.mkdir(self.test_dir)
541
550
        os.chdir(self.test_dir)
542
551
        os.environ['HOME'] = self.test_dir
 
552
        os.environ['APPDATA'] = self.test_dir
543
553
        def _leaveDirectory():
544
554
            os.chdir(_currentdir)
545
555
        self.addCleanup(_leaveDirectory)
576
586
 
577
587
    def failUnlessExists(self, path):
578
588
        """Fail unless path, which may be abs or relative, exists."""
579
 
        self.failUnless(bzrlib.osutils.lexists(path))
 
589
        self.failUnless(osutils.lexists(path))
 
590
 
 
591
    def failIfExists(self, path):
 
592
        """Fail if path, which may be abs or relative, exists."""
 
593
        self.failIf(osutils.lexists(path))
580
594
        
581
595
    def assertFileEqual(self, content, path):
582
596
        """Fail if path does not contain 'content'."""
583
 
        self.failUnless(bzrlib.osutils.lexists(path))
 
597
        self.failUnless(osutils.lexists(path))
584
598
        self.assertEqualDiff(content, open(path, 'r').read())
585
 
        
 
599
 
586
600
 
587
601
def filter_suite_by_re(suite, pattern):
588
602
    result = TestSuite()
636
650
                   'bzrlib.tests.test_annotate',
637
651
                   'bzrlib.tests.test_api',
638
652
                   'bzrlib.tests.test_bad_files',
 
653
                   'bzrlib.tests.test_basis_inventory',
639
654
                   'bzrlib.tests.test_branch',
640
655
                   'bzrlib.tests.test_command',
641
656
                   'bzrlib.tests.test_commit',
658
673
                   'bzrlib.tests.test_msgeditor',
659
674
                   'bzrlib.tests.test_nonascii',
660
675
                   'bzrlib.tests.test_options',
 
676
                   'bzrlib.tests.test_osutils',
661
677
                   'bzrlib.tests.test_parent',
 
678
                   'bzrlib.tests.test_permissions',
662
679
                   'bzrlib.tests.test_plugins',
663
680
                   'bzrlib.tests.test_remove',
664
681
                   'bzrlib.tests.test_revision',
670
687
                   'bzrlib.tests.test_sampler',
671
688
                   'bzrlib.tests.test_selftest',
672
689
                   'bzrlib.tests.test_setup',
673
 
                   'bzrlib.tests.test_sftp',
 
690
                   'bzrlib.tests.test_sftp_transport',
674
691
                   'bzrlib.tests.test_smart_add',
675
692
                   'bzrlib.tests.test_source',
676
693
                   'bzrlib.tests.test_status',
689
706
                   'bzrlib.tests.test_xml',
690
707
                   ]
691
708
 
692
 
    print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
 
709
    TestCase.BZRPATH = osutils.pathjoin(
 
710
            osutils.realpath(osutils.dirname(bzrlib.__path__[0])), 'bzr')
 
711
    print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
693
712
    print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
694
713
    print
695
714
    suite = TestSuite()