/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/test_whitebox.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-18 18:18:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4461.
  • Revision ID: john@arbash-meinel.com-20090618181836-biodfkat9a8eyzjz
The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL
Which is completely valid, but 'broke' one of the tests.
So to fix it, changed the test to use CHKInventories on both sides, and add an __eq__
member. The nice thing is that CHKInventory.__eq__ is fairly cheap, since it only
has to check the root keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import os
 
18
import unittest
 
19
 
 
20
from bzrlib import (
 
21
    osutils,
 
22
    )
 
23
from bzrlib.tests import TestCaseWithTransport, TestCase
 
24
from bzrlib.branch import Branch
 
25
from bzrlib.errors import PathNotChild
 
26
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
 
27
 
 
28
 
 
29
class MoreTests(TestCaseWithTransport):
 
30
 
 
31
    def test_relpath(self):
 
32
        """test for branch path lookups
 
33
 
 
34
        bzrlib.osutils._relpath do a simple but subtle
 
35
        job: given a path (either relative to cwd or absolute), work out
 
36
        if it is inside a branch and return the path relative to the base.
 
37
        """
 
38
        import tempfile
 
39
 
 
40
        savedir = os.getcwdu()
 
41
        dtmp = osutils.mkdtemp()
 
42
        # On Mac OSX, /tmp actually expands to /private/tmp
 
43
        dtmp = realpath(dtmp)
 
44
 
 
45
        def rp(p):
 
46
            return relpath(dtmp, p)
 
47
 
 
48
        try:
 
49
            # check paths inside dtmp while standing outside it
 
50
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
 
51
 
 
52
            # root = nothing
 
53
            self.assertEqual(rp(dtmp), '')
 
54
 
 
55
            self.assertRaises(PathNotChild,
 
56
                              rp,
 
57
                              '/etc')
 
58
 
 
59
            # now some near-miss operations -- note that
 
60
            # os.path.commonprefix gets these wrong!
 
61
            self.assertRaises(PathNotChild,
 
62
                              rp,
 
63
                              dtmp.rstrip('\\/') + '2')
 
64
 
 
65
            self.assertRaises(PathNotChild,
 
66
                              rp,
 
67
                              dtmp.rstrip('\\/') + '2/foo')
 
68
 
 
69
            # now operations based on relpath of files in current
 
70
            # directory, or nearby
 
71
            os.chdir(dtmp)
 
72
 
 
73
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
 
74
 
 
75
            self.assertEqual(rp('foo'), 'foo')
 
76
 
 
77
            self.assertEqual(rp('./foo'), 'foo')
 
78
 
 
79
            self.assertEqual(rp(abspath('foo')), 'foo')
 
80
 
 
81
            self.assertRaises(PathNotChild,
 
82
                              rp, '../foo')
 
83
 
 
84
        finally:
 
85
            os.chdir(savedir)
 
86
            osutils.rmtree(dtmp)