~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__walkdirs_win32.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 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
 
"""Tests for the win32 walkdir extension."""
18
 
 
19
 
import errno
20
 
 
21
 
from bzrlib import (
22
 
    osutils,
23
 
    tests,
24
 
    )
25
 
 
26
 
 
27
 
win32_readdir_feature = tests.ModuleAvailableFeature('bzrlib._walkdirs_win32')
28
 
 
29
 
 
30
 
class TestWin32Finder(tests.TestCaseInTempDir):
31
 
 
32
 
    _test_needs_features = [win32_readdir_feature]
33
 
 
34
 
    def setUp(self):
35
 
        super(TestWin32Finder, self).setUp()
36
 
        from bzrlib._walkdirs_win32 import (
37
 
            Win32ReadDir,
38
 
            )
39
 
        self.reader = Win32ReadDir()
40
 
 
41
 
    def _remove_stat_from_dirblock(self, dirblock):
42
 
        return [info[:3] + info[4:] for info in dirblock]
43
 
 
44
 
    def assertWalkdirs(self, expected, top, prefix=''):
45
 
        old_selected_dir_reader = osutils._selected_dir_reader
46
 
        try:
47
 
            osutils._selected_dir_reader = self.reader
48
 
            finder = osutils._walkdirs_utf8(top, prefix=prefix)
49
 
            result = []
50
 
            for dirname, dirblock in finder:
51
 
                dirblock = self._remove_stat_from_dirblock(dirblock)
52
 
                result.append((dirname, dirblock))
53
 
            self.assertEqual(expected, result)
54
 
        finally:
55
 
            osutils._selected_dir_reader = old_selected_dir_reader
56
 
 
57
 
    def assertReadDir(self, expected, prefix, top_unicode):
58
 
        result = self._remove_stat_from_dirblock(
59
 
            self.reader.read_dir(prefix, top_unicode))
60
 
        self.assertEqual(expected, result)
61
 
 
62
 
    def test_top_prefix_to_starting_dir(self):
63
 
        # preparing an iteration should create a unicode native path.
64
 
        self.assertEqual(('prefix', None, None, None, u'\x12'),
65
 
            self.reader.top_prefix_to_starting_dir(u'\x12'.encode('utf8'),
66
 
                                                   'prefix'))
67
 
 
68
 
    def test_empty_directory(self):
69
 
        self.assertReadDir([], 'prefix', u'.')
70
 
        self.assertWalkdirs([(('', u'.'), [])], u'.')
71
 
 
72
 
    def test_file(self):
73
 
        self.build_tree(['foo'])
74
 
        self.assertReadDir([('foo', 'foo', 'file', u'./foo')],
75
 
            '', u'.')
76
 
 
77
 
    def test_dir(self):
78
 
        self.build_tree(['bar/'])
79
 
        self.assertReadDir([('bar', 'bar', 'directory', u'./bar')],
80
 
            '', u'.')
81
 
 
82
 
    def test_prefix(self):
83
 
        self.build_tree(['bar/', 'baf'])
84
 
        self.assertReadDir([
85
 
            ('xxx/baf', 'baf', 'file', u'./baf'),
86
 
            ('xxx/bar', 'bar', 'directory', u'./bar'),
87
 
            ],
88
 
            'xxx', u'.')
89
 
 
90
 
    def test_missing_dir(self):
91
 
        e = self.assertRaises(WindowsError,
92
 
            self.reader.read_dir, 'prefix', u'no_such_dir')
93
 
        self.assertEqual(errno.ENOENT, e.errno)
94
 
        self.assertEqual(3, e.winerror)
95
 
        self.assertEqual((3, u'no_such_dir/*'), e.args)