~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__walkdirs_win32.py

  • Committer: Patch Queue Manager
  • Date: 2012-07-28 15:55:41 UTC
  • mfrom: (5912.5.9 Base64CredentialStore)
  • Revision ID: pqm@pqm.ubuntu.com-20120728155541-d860rcyc2q82nhnj
(gz) Add Base64CredentialStore for authentication.conf password obfuscation
 (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008, 2009, 2010 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
from bzrlib.tests import (
 
26
    features,
 
27
    )
 
28
 
 
29
 
 
30
win32_readdir_feature = features.ModuleAvailableFeature('bzrlib._walkdirs_win32')
 
31
 
 
32
 
 
33
class TestWin32Finder(tests.TestCaseInTempDir):
 
34
 
 
35
    _test_needs_features = [win32_readdir_feature]
 
36
 
 
37
    def setUp(self):
 
38
        super(TestWin32Finder, self).setUp()
 
39
        from bzrlib._walkdirs_win32 import (
 
40
            Win32ReadDir,
 
41
            )
 
42
        self.reader = Win32ReadDir()
 
43
 
 
44
    def _remove_stat_from_dirblock(self, dirblock):
 
45
        return [info[:3] + info[4:] for info in dirblock]
 
46
 
 
47
    def assertWalkdirs(self, expected, top, prefix=''):
 
48
        old_selected_dir_reader = osutils._selected_dir_reader
 
49
        try:
 
50
            osutils._selected_dir_reader = self.reader
 
51
            finder = osutils._walkdirs_utf8(top, prefix=prefix)
 
52
            result = []
 
53
            for dirname, dirblock in finder:
 
54
                dirblock = self._remove_stat_from_dirblock(dirblock)
 
55
                result.append((dirname, dirblock))
 
56
            self.assertEqual(expected, result)
 
57
        finally:
 
58
            osutils._selected_dir_reader = old_selected_dir_reader
 
59
 
 
60
    def assertReadDir(self, expected, prefix, top_unicode):
 
61
        result = self._remove_stat_from_dirblock(
 
62
            self.reader.read_dir(prefix, top_unicode))
 
63
        self.assertEqual(expected, result)
 
64
 
 
65
    def test_top_prefix_to_starting_dir(self):
 
66
        # preparing an iteration should create a unicode native path.
 
67
        self.assertEqual(('prefix', None, None, None, u'\x12'),
 
68
            self.reader.top_prefix_to_starting_dir(u'\x12'.encode('utf8'),
 
69
                                                   'prefix'))
 
70
 
 
71
    def test_empty_directory(self):
 
72
        self.assertReadDir([], 'prefix', u'.')
 
73
        self.assertWalkdirs([(('', u'.'), [])], u'.')
 
74
 
 
75
    def test_file(self):
 
76
        self.build_tree(['foo'])
 
77
        self.assertReadDir([('foo', 'foo', 'file', u'./foo')],
 
78
            '', u'.')
 
79
 
 
80
    def test_directory(self):
 
81
        self.build_tree(['bar/'])
 
82
        self.assertReadDir([('bar', 'bar', 'directory', u'./bar')],
 
83
            '', u'.')
 
84
 
 
85
    def test_prefix(self):
 
86
        self.build_tree(['bar/', 'baf'])
 
87
        self.assertReadDir([
 
88
            ('xxx/baf', 'baf', 'file', u'./baf'),
 
89
            ('xxx/bar', 'bar', 'directory', u'./bar'),
 
90
            ],
 
91
            'xxx', u'.')
 
92
 
 
93
    def test_missing_dir(self):
 
94
        e = self.assertRaises(WindowsError,
 
95
            self.reader.read_dir, 'prefix', u'no_such_dir')
 
96
        self.assertEqual(errno.ENOENT, e.errno)
 
97
        self.assertEqual(3, e.winerror)
 
98
        self.assertEqual((3, u'no_such_dir/*'), e.args)
 
99
 
 
100
 
 
101
class Test_Win32Stat(tests.TestCaseInTempDir):
 
102
 
 
103
    _test_needs_features = [win32_readdir_feature]
 
104
 
 
105
    def setUp(self):
 
106
        super(Test_Win32Stat, self).setUp()
 
107
        from bzrlib._walkdirs_win32 import lstat
 
108
        self.win32_lstat = lstat
 
109
 
 
110
    def test_zero_members_present(self):
 
111
        self.build_tree(['foo'])
 
112
        st = self.win32_lstat('foo')
 
113
        # we only want to ensure that some members are present
 
114
        self.assertEqual(0, st.st_dev)
 
115
        self.assertEqual(0, st.st_ino)
 
116
        self.assertEqual(0, st.st_uid)
 
117
        self.assertEqual(0, st.st_gid)