~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_walkdirs.py

  • Committer: Robert Collins
  • Date: 2006-07-31 07:18:54 UTC
  • mto: (1852.14.2 status-benchmarks)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20060731071854-d1fe7dd1ee353097
Tweak the Tree.walkdirs interface more to be more useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
class TestWalkdirs(TestCaseWithWorkingTree):
32
32
 
33
 
    def test_walkdir_unknowns(self):
34
 
        """unknown files and directories should be reported by walkdirs."""
 
33
    def get_tree_with_unknowns(self):
35
34
        tree = self.make_branch_and_tree('.')
36
35
        self.build_tree([
37
36
            'unknown file',
45
44
        u_d_s_stat = os.lstat('unknown dir to skip')
46
45
        u_d_f_stat = os.lstat('unknown dir/a file')
47
46
        expected_dirblocks = [
48
 
            (('', '', tree.inventory.root.file_id),
 
47
            (('', tree.inventory.root.file_id),
49
48
             [
50
 
              ('unknown dir', 'unknown dir', 'directory', u_d_stat, 'unknown dir', None, None),
51
 
              ('unknown dir to skip', 'unknown dir to skip', 'directory', u_d_s_stat, 'unknown dir to skip', None, None),
52
 
              ('unknown file', 'unknown file', 'file', u_f_stat, 'unknown file', None, None),
53
 
             ]
54
 
            ),
55
 
            (('unknown dir', 'unknown dir', None),
56
 
             [('unknown dir/a file', 'a file', 'file', u_d_f_stat, 'unknown dir/a file', None, None),
57
 
             ]
58
 
            ),
59
 
        ]
 
49
              ('unknown dir', 'unknown dir', 'directory', u_d_stat, None, None),
 
50
              ('unknown dir to skip', 'unknown dir to skip', 'directory', u_d_s_stat, None, None),
 
51
              ('unknown file', 'unknown file', 'file', u_f_stat, None, None),
 
52
             ]
 
53
            ),
 
54
            (('unknown dir', None),
 
55
             [('unknown dir/a file', 'a file', 'file', u_d_f_stat, None, None),
 
56
             ]
 
57
            ),
 
58
            ]
 
59
        return tree, expected_dirblocks
 
60
    
 
61
    def test_walkdir_unknowns(self):
 
62
        """unknown files and directories should be reported by walkdirs."""
60
63
        # test that its iterable by iterating, and that skipping an unknown dir
61
64
        # works:
62
65
        result = []
 
66
        tree, expected_dirblocks = self.get_tree_with_unknowns()
63
67
        found_unknown_to_skip = False
64
68
        for dirinfo, dirblock in tree.walkdirs():
65
69
            result.append((dirinfo, list(dirblock)))
71
75
        for pos, item in enumerate(expected_dirblocks):
72
76
            self.assertEqual(item, result[pos])
73
77
        self.assertTrue(found_unknown_to_skip)
 
78
 
 
79
    def test_walkdir_from_unknown_dir(self):
 
80
        """Doing a walkdir when the requested prefix is unknown but on disk."""
 
81
        result = []
 
82
        tree, expected_dirblocks = self.get_tree_with_unknowns()
 
83
        for dirinfo, dirblock in tree.walkdirs('unknown dir'):
 
84
            result.append((dirinfo, list(dirblock)))
 
85
        # check each return value for debugging ease.
 
86
        for pos, item in enumerate(expected_dirblocks[1:]):
 
87
            self.assertEqual(item, result[pos])