~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-11-16 22:42:54 UTC
  • mfrom: (4797.3.21 2.1.0b4-win32-accepted)
  • Revision ID: pqm@pqm.ubuntu.com-20091116224254-fgspnq9xz29z662j
(jam) Lots of win32 test-suite fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
from bzrlib.win32utils import glob_expand, get_app_path
33
33
 
34
34
 
35
 
# Features
36
 
# --------
37
 
 
38
 
class _NeedsGlobExpansionFeature(Feature):
 
35
class _BackslashDirSeparatorFeature(tests.Feature):
39
36
 
40
37
    def _probe(self):
41
 
        return sys.platform == 'win32'
 
38
        try:
 
39
            os.lstat(os.getcwd() + '\\')
 
40
        except OSError:
 
41
            return False
 
42
        else:
 
43
            return True
42
44
 
43
45
    def feature_name(self):
44
 
        return 'Internally performed glob expansion'
 
46
        return "Filesystem treats '\\' as a directory separator."
45
47
 
46
 
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
 
48
BackslashDirSeparatorFeature = _BackslashDirSeparatorFeature()
47
49
 
48
50
 
49
51
class _RequiredModuleFeature(Feature):
70
72
# Tests
71
73
# -----
72
74
 
73
 
class TestNeedsGlobExpansionFeature(TestCase):
74
 
 
75
 
    def test_available(self):
76
 
        self.assertEqual(sys.platform == 'win32',
77
 
                         NeedsGlobExpansionFeature.available())
78
 
 
79
 
    def test_str(self):
80
 
        self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
81
 
 
82
 
 
83
75
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
84
76
 
85
 
    _test_needs_features = [NeedsGlobExpansionFeature]
 
77
    _test_needs_features = []
86
78
 
87
79
    def test_empty_tree(self):
88
80
        self.build_tree([])
92
84
            [['*'], ['*']],
93
85
            [['a', 'a'], ['a', 'a']]])
94
86
 
95
 
    def test_tree_ascii(self):
96
 
        """Checks the glob expansion and path separation char
97
 
        normalization"""
 
87
    def build_ascii_tree(self):
98
88
        self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
99
89
                         'b', 'b1', 'b2', 'b3',
100
90
                         'c/', 'c/c1', 'c/c2',
101
91
                         'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
 
92
 
 
93
    def build_unicode_tree(self):
 
94
        self.requireFeature(UnicodeFilenameFeature)
 
95
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/',
 
96
                         u'\u1235/\u1235'])
 
97
 
 
98
    def test_tree_ascii(self):
 
99
        """Checks the glob expansion and path separation char
 
100
        normalization"""
 
101
        self.build_ascii_tree()
102
102
        self._run_testset([
103
103
            # no wildcards
104
104
            [[u'a'], [u'a']],
105
105
            [[u'a', u'a' ], [u'a', u'a']],
106
 
            [[u'A'], [u'A']],
107
106
 
108
107
            [[u'd'], [u'd']],
109
108
            [[u'd/'], [u'd/']],
110
 
            [[u'd\\'], [u'd/']],
111
109
 
112
110
            # wildcards
113
111
            [[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
115
113
            [[u'a?'], [u'a1', u'a2']],
116
114
            [[u'a??'], [u'a11', u'a.1']],
117
115
            [[u'b[1-2]'], [u'b1', u'b2']],
118
 
            [[u'A?'], [u'a1', u'a2']],
119
116
 
120
117
            [[u'd/*'], [u'd/d1', u'd/d2', u'd/e']],
 
118
            [[u'?/*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
 
119
            [[u'*/*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
 
120
            [[u'*/'], [u'c/', u'd/']],
 
121
            ])
 
122
 
 
123
    def test_backslash_globbing(self):
 
124
        self.requireFeature(BackslashDirSeparatorFeature)
 
125
        self.build_ascii_tree()
 
126
        self._run_testset([
 
127
            [[u'd\\'], [u'd/']],
121
128
            [[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
122
129
            [[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
123
130
            [[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
124
 
            [[u'*/'], [u'c/', u'd/']],
125
 
            [[u'*\\'], [u'c/', u'd/']]])
 
131
            [[u'*\\'], [u'c/', u'd/']],
 
132
            ])
 
133
 
 
134
    def test_case_insensitive_globbing(self):
 
135
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
 
136
        self.build_ascii_tree()
 
137
        self._run_testset([
 
138
            [[u'A'], [u'A']],
 
139
            [[u'A?'], [u'a1', u'a2']],
 
140
            ])
126
141
 
127
142
    def test_tree_unicode(self):
128
143
        """Checks behaviour with non-ascii filenames"""
129
 
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
 
144
        self.build_unicode_tree()
130
145
        self._run_testset([
131
146
            # no wildcards
132
147
            [[u'\u1234'], [u'\u1234']],
142
157
 
143
158
            [[u'\u1235/?'], [u'\u1235/\u1235']],
144
159
            [[u'\u1235/*'], [u'\u1235/\u1235']],
 
160
            [[u'?/'], [u'\u1235/']],
 
161
            [[u'*/'], [u'\u1235/']],
 
162
            [[u'?/?'], [u'\u1235/\u1235']],
 
163
            [[u'*/*'], [u'\u1235/\u1235']],
 
164
            ])
 
165
 
 
166
    def test_unicode_backslashes(self):
 
167
        self.requireFeature(BackslashDirSeparatorFeature)
 
168
        self.build_unicode_tree()
 
169
        self._run_testset([
 
170
            # no wildcards
 
171
            [[u'\u1235\\'], [u'\u1235/']],
 
172
            [[u'\u1235\\\u1235'], [u'\u1235/\u1235']],
145
173
            [[u'\u1235\\?'], [u'\u1235/\u1235']],
146
174
            [[u'\u1235\\*'], [u'\u1235/\u1235']],
147
 
            [[u'?/'], [u'\u1235/']],
148
 
            [[u'*/'], [u'\u1235/']],
149
175
            [[u'?\\'], [u'\u1235/']],
150
176
            [[u'*\\'], [u'\u1235/']],
151
 
            [[u'?/?'], [u'\u1235/\u1235']],
152
 
            [[u'*/*'], [u'\u1235/\u1235']],
153
177
            [[u'?\\?'], [u'\u1235/\u1235']],
154
 
            [[u'*\\*'], [u'\u1235/\u1235']]])
 
178
            [[u'*\\*'], [u'\u1235/\u1235']],
 
179
            ])
155
180
 
156
181
    def _run_testset(self, testset):
157
182
        for pattern, expected in testset:
356
381
    def test_no_single_quote_supported(self):
357
382
        self.assertCommandLine(["add", "let's-do-it.txt"],
358
383
            "add let's-do-it.txt")
 
384
 
 
385
    def test_case_insensitive_globs(self):
 
386
        self.requireFeature(tests.CaseInsCasePresFilenameFeature)
 
387
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
 
388
        self.assertCommandLine([u'A/b.c'], 'A/B*')
 
389
 
 
390
    def test_backslashes(self):
 
391
        self.requireFeature(BackslashDirSeparatorFeature)
 
392
        self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
 
393
        self.assertCommandLine([u'a/b.c'], 'a\\b*')