~bzr-pqm/bzr/bzr.dev

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
2681.4.2 by Alexander Belchenko
test for get_app_path
17
import os
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
18
import sys
19
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
20
from bzrlib import osutils
2681.4.4 by Alexander Belchenko
test use Feature instead of TestSkipped
21
from bzrlib.tests import TestCase, TestCaseInTempDir, Feature
2681.4.2 by Alexander Belchenko
test for get_app_path
22
from bzrlib.win32utils import glob_expand, get_app_path
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
23
24
25
# Features
26
# --------
27
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
28
class _NeedsGlobExpansionFeature(Feature):
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
29
30
    def _probe(self):
2617.5.5 by Kuno Meyer
Just a typo remained from testing.
31
        return sys.platform == 'win32'
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
32
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
33
    def feature_name(self):
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
34
        return 'Internally performed glob expansion'
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
35
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
36
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
37
38
2681.4.4 by Alexander Belchenko
test use Feature instead of TestSkipped
39
class _Win32RegistryFeature(Feature):
40
41
    def _probe(self):
42
        try:
43
            import _winreg
44
            return True
45
        except ImportError:
46
            return False
47
48
    def feature_name(self):
49
        return '_winreg'
50
51
Win32RegistryFeature = _Win32RegistryFeature()
52
53
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
54
# Tests
55
# -----
2617.5.6 by Kuno Meyer
Incorporated feedback from the mailinglist.
56
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
57
class TestNeedsGlobExpansionFeature(TestCase):
2617.5.6 by Kuno Meyer
Incorporated feedback from the mailinglist.
58
    
59
    def test_available(self):
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
60
        self.assertEqual(sys.platform == 'win32', 
61
                         NeedsGlobExpansionFeature.available())
2617.5.6 by Kuno Meyer
Incorporated feedback from the mailinglist.
62
        
63
    def test_str(self):
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
64
        self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
2617.5.6 by Kuno Meyer
Incorporated feedback from the mailinglist.
65
66
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
67
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
2617.5.2 by Kuno Meyer
just reformatting
68
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
69
    _test_needs_features = [NeedsGlobExpansionFeature]
2617.5.1 by Kuno Meyer
Added direct unit tests for win32utils.glob_expand().
70
   
71
    def test_empty_tree(self):
72
        self.build_tree([])
2617.5.2 by Kuno Meyer
just reformatting
73
        self._run_testset([
74
            [['a'], ['a']],
75
            [['?'], ['?']],
76
            [['*'], ['*']],
77
            [['a', 'a'], ['a', 'a']]])
2617.5.1 by Kuno Meyer
Added direct unit tests for win32utils.glob_expand().
78
        
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
79
    def test_tree_ascii(self):
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
80
        """Checks the glob expansion and path separation char
81
        normalization"""
2617.5.1 by Kuno Meyer
Added direct unit tests for win32utils.glob_expand().
82
        self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
83
                         'b', 'b1', 'b2', 'b3',
84
                         'c/', 'c/c1', 'c/c2', 
2617.5.4 by Kuno Meyer
Included feedback on initial patch.
85
                         'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
2617.5.2 by Kuno Meyer
just reformatting
86
        self._run_testset([
87
            # no wildcards
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
88
            [[u'a'], [u'a']],
89
            [[u'a', u'a' ], [u'a', u'a']],
90
            [[u'A'], [u'A']],
2617.5.2 by Kuno Meyer
just reformatting
91
                
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
92
            [[u'd'], [u'd']],
93
            [[u'd/'], [u'd/']],
94
            [[u'd\\'], [u'd/']],
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
95
            
2617.5.2 by Kuno Meyer
just reformatting
96
            # wildcards
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
97
            [[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
98
            [[u'?'], [u'a', u'b', u'c', u'd']],
99
            [[u'a?'], [u'a1', u'a2']],
100
            [[u'a??'], [u'a11', u'a.1']],
101
            [[u'b[1-2]'], [u'b1', u'b2']],
102
            [[u'A?'], [u'a1', u'a2']],
2617.5.2 by Kuno Meyer
just reformatting
103
               
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
104
            [[u'd/*'], [u'd/d1', u'd/d2', u'd/e']],
105
            [[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
106
            [[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
107
            [[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
108
            [[u'*/'], [u'c/', u'd/']],
109
            [[u'*\\'], [u'c/', u'd/']]])
2617.5.1 by Kuno Meyer
Added direct unit tests for win32utils.glob_expand().
110
        
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
111
    def test_tree_unicode(self):
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
112
        """Checks behaviour with non-ascii filenames"""
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
113
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
114
        self._run_testset([
115
            # no wildcards
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
116
            [[u'\u1234'], [u'\u1234']],
117
            [[u'\u1235'], [u'\u1235']],
118
         
119
            [[u'\u1235/'], [u'\u1235/']],
120
            [[u'\u1235/\u1235'], [u'\u1235/\u1235']],
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
121
            
122
            # wildcards
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
123
            [[u'?'], [u'\u1234', u'\u1235']],
124
            [[u'*'], [u'\u1234', u'\u1234\u1234', u'\u1235']],
125
            [[u'\u1234*'], [u'\u1234', u'\u1234\u1234']],
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
126
            
2617.5.8 by Kuno Meyer
Extended tests for unicode chars outside of the iso-8859-* range
127
            [[u'\u1235/?'], [u'\u1235/\u1235']],
128
            [[u'\u1235/*'], [u'\u1235/\u1235']],
129
            [[u'\u1235\\?'], [u'\u1235/\u1235']],
130
            [[u'\u1235\\*'], [u'\u1235/\u1235']],
131
            [[u'?/'], [u'\u1235/']],
132
            [[u'*/'], [u'\u1235/']],
133
            [[u'?\\'], [u'\u1235/']],
134
            [[u'*\\'], [u'\u1235/']],
135
            [[u'?/?'], [u'\u1235/\u1235']],
136
            [[u'*/*'], [u'\u1235/\u1235']],
137
            [[u'?\\?'], [u'\u1235/\u1235']],
138
            [[u'*\\*'], [u'\u1235/\u1235']]])
2617.5.7 by Kuno Meyer
Fix for non-ASCII filenames
139
2617.5.1 by Kuno Meyer
Added direct unit tests for win32utils.glob_expand().
140
    def _run_testset(self, testset):
141
        for pattern, expected in testset:
142
            result = glob_expand(pattern)
143
            expected.sort()
144
            result.sort()
145
            self.assertEqual(expected, result, 'pattern %s' % pattern)
2617.5.2 by Kuno Meyer
just reformatting
146
2681.4.2 by Alexander Belchenko
test for get_app_path
147
148
class TestAppPaths(TestCase):
149
2681.4.4 by Alexander Belchenko
test use Feature instead of TestSkipped
150
    _test_needs_features = [Win32RegistryFeature]
151
2681.4.2 by Alexander Belchenko
test for get_app_path
152
    def test_iexplore(self):
153
        # typical windows users should have IE installed
154
        for a in ('iexplore', 'iexplore.exe'):
155
            p = get_app_path(a)
156
            d, b = os.path.split(p)
157
            self.assertEquals('iexplore.exe', b)
158
            self.assertNotEquals('', d)
159
160
    def test_not_existing(self):
161
        p = get_app_path('not-existing')
162
        self.assertEquals('not-existing', p)