bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
1  | 
# Copyright (C) 2007 Canonical Ltd
 | 
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
16  | 
||
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
17  | 
import sys  | 
18  | 
||
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
19  | 
from bzrlib import osutils  | 
| 
2617.5.6
by Kuno Meyer
 Incorporated feedback from the mailinglist.  | 
20  | 
from bzrlib.tests import TestCase, TestCaseInTempDir, Feature  | 
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
21  | 
from bzrlib.win32utils import glob_expand  | 
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
22  | 
|
23  | 
||
24  | 
# Features
 | 
|
25  | 
# --------
 | 
|
26  | 
||
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
27  | 
class _NeedsGlobExpansionFeature(Feature):  | 
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
28  | 
|
29  | 
def _probe(self):  | 
|
| 
2617.5.5
by Kuno Meyer
 Just a typo remained from testing.  | 
30  | 
return sys.platform == 'win32'  | 
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
31  | 
|
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
32  | 
def feature_name(self):  | 
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
33  | 
return 'Internally performed glob expansion'  | 
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
34  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
35  | 
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()  | 
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
36  | 
|
37  | 
||
38  | 
# Tests
 | 
|
39  | 
# -----
 | 
|
| 
2617.5.6
by Kuno Meyer
 Incorporated feedback from the mailinglist.  | 
40  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
41  | 
class TestNeedsGlobExpansionFeature(TestCase):  | 
| 
2617.5.6
by Kuno Meyer
 Incorporated feedback from the mailinglist.  | 
42  | 
|
43  | 
def test_available(self):  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
44  | 
self.assertEqual(sys.platform == 'win32',  | 
45  | 
NeedsGlobExpansionFeature.available())  | 
|
| 
2617.5.6
by Kuno Meyer
 Incorporated feedback from the mailinglist.  | 
46  | 
|
47  | 
def test_str(self):  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
48  | 
self.assertTrue("performed" in str(NeedsGlobExpansionFeature))  | 
| 
2617.5.6
by Kuno Meyer
 Incorporated feedback from the mailinglist.  | 
49  | 
|
50  | 
||
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
51  | 
class TestWin32UtilsGlobExpand(TestCaseInTempDir):  | 
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
52  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
53  | 
_test_needs_features = [NeedsGlobExpansionFeature]  | 
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
54  | 
|
55  | 
def test_empty_tree(self):  | 
|
56  | 
self.build_tree([])  | 
|
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
57  | 
self._run_testset([  | 
58  | 
[['a'], ['a']],  | 
|
59  | 
[['?'], ['?']],  | 
|
60  | 
[['*'], ['*']],  | 
|
61  | 
[['a', 'a'], ['a', 'a']]])  | 
|
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
62  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
63  | 
def test_tree_ascii(self):  | 
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
64  | 
"""Checks the glob expansion and path separation char  | 
65  | 
        normalization"""
 | 
|
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
66  | 
self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',  | 
67  | 
'b', 'b1', 'b2', 'b3',  | 
|
68  | 
'c/', 'c/c1', 'c/c2',  | 
|
| 
2617.5.4
by Kuno Meyer
 Included feedback on initial patch.  | 
69  | 
'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])  | 
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
70  | 
self._run_testset([  | 
71  | 
            # no wildcards
 | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
72  | 
[[u'a'], [u'a']],  | 
73  | 
[[u'a', u'a' ], [u'a', u'a']],  | 
|
74  | 
[[u'A'], [u'A']],  | 
|
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
75  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
76  | 
[[u'd'], [u'd']],  | 
77  | 
[[u'd/'], [u'd/']],  | 
|
78  | 
[[u'd\\'], [u'd/']],  | 
|
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
79  | 
|
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
80  | 
            # wildcards
 | 
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
81  | 
[[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],  | 
82  | 
[[u'?'], [u'a', u'b', u'c', u'd']],  | 
|
83  | 
[[u'a?'], [u'a1', u'a2']],  | 
|
84  | 
[[u'a??'], [u'a11', u'a.1']],  | 
|
85  | 
[[u'b[1-2]'], [u'b1', u'b2']],  | 
|
86  | 
[[u'A?'], [u'a1', u'a2']],  | 
|
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
87  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
88  | 
[[u'd/*'], [u'd/d1', u'd/d2', u'd/e']],  | 
89  | 
[[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],  | 
|
90  | 
[[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],  | 
|
91  | 
[[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],  | 
|
92  | 
[[u'*/'], [u'c/', u'd/']],  | 
|
93  | 
[[u'*\\'], [u'c/', u'd/']]])  | 
|
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
94  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
95  | 
def test_tree_unicode(self):  | 
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
96  | 
"""Checks behaviour with non-ascii filenames"""  | 
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
97  | 
self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])  | 
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
98  | 
self._run_testset([  | 
99  | 
            # no wildcards
 | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
100  | 
[[u'\u1234'], [u'\u1234']],  | 
101  | 
[[u'\u1235'], [u'\u1235']],  | 
|
102  | 
||
103  | 
[[u'\u1235/'], [u'\u1235/']],  | 
|
104  | 
[[u'\u1235/\u1235'], [u'\u1235/\u1235']],  | 
|
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
105  | 
|
106  | 
            # wildcards
 | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
107  | 
[[u'?'], [u'\u1234', u'\u1235']],  | 
108  | 
[[u'*'], [u'\u1234', u'\u1234\u1234', u'\u1235']],  | 
|
109  | 
[[u'\u1234*'], [u'\u1234', u'\u1234\u1234']],  | 
|
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
110  | 
|
| 
2617.5.8
by Kuno Meyer
 Extended tests for unicode chars outside of the iso-8859-* range  | 
111  | 
[[u'\u1235/?'], [u'\u1235/\u1235']],  | 
112  | 
[[u'\u1235/*'], [u'\u1235/\u1235']],  | 
|
113  | 
[[u'\u1235\\?'], [u'\u1235/\u1235']],  | 
|
114  | 
[[u'\u1235\\*'], [u'\u1235/\u1235']],  | 
|
115  | 
[[u'?/'], [u'\u1235/']],  | 
|
116  | 
[[u'*/'], [u'\u1235/']],  | 
|
117  | 
[[u'?\\'], [u'\u1235/']],  | 
|
118  | 
[[u'*\\'], [u'\u1235/']],  | 
|
119  | 
[[u'?/?'], [u'\u1235/\u1235']],  | 
|
120  | 
[[u'*/*'], [u'\u1235/\u1235']],  | 
|
121  | 
[[u'?\\?'], [u'\u1235/\u1235']],  | 
|
122  | 
[[u'*\\*'], [u'\u1235/\u1235']]])  | 
|
| 
2617.5.7
by Kuno Meyer
 Fix for non-ASCII filenames  | 
123  | 
|
| 
2617.5.1
by Kuno Meyer
 Added direct unit tests for win32utils.glob_expand().  | 
124  | 
def _run_testset(self, testset):  | 
125  | 
for pattern, expected in testset:  | 
|
126  | 
result = glob_expand(pattern)  | 
|
127  | 
expected.sort()  | 
|
128  | 
result.sort()  | 
|
129  | 
self.assertEqual(expected, result, 'pattern %s' % pattern)  | 
|
| 
2617.5.2
by Kuno Meyer
 just reformatting  | 
130  |