~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_win32utils.py

  • Committer: Kuno Meyer
  • Date: 2007-07-24 19:40:40 UTC
  • mto: This revision was merged to the branch mainline in revision 2655.
  • Revision ID: kuno.meyer@gmx.ch-20070724194040-ocyjulqhy31xe3j1
Extended tests for unicode chars outside of the iso-8859-* range
Two workarounds for incorrect glob.glob() implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import sys
18
18
 
 
19
from bzrlib import osutils
19
20
from bzrlib.tests import TestCase, TestCaseInTempDir, Feature
20
21
from bzrlib.win32utils import glob_expand
21
22
 
23
24
# Features
24
25
# --------
25
26
 
26
 
class _Win32Feature(Feature):
 
27
class _NeedsGlobExpansionFeature(Feature):
27
28
 
28
29
    def _probe(self):
29
30
        return sys.platform == 'win32'
30
 
    
 
31
 
31
32
    def feature_name(self):
32
 
        return 'Win32 platform'
 
33
        return 'Internally performed glob expansion'
33
34
 
34
 
Win32Feature = _Win32Feature()
 
35
NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
35
36
 
36
37
 
37
38
# Tests
38
39
# -----
39
40
 
40
 
class TestWin32Feature(TestCase):
 
41
class TestNeedsGlobExpansionFeature(TestCase):
41
42
    
42
43
    def test_available(self):
43
 
        self.assertEqual(sys.platform == 'win32', Win32Feature.available())
 
44
        self.assertEqual(sys.platform == 'win32', 
 
45
                         NeedsGlobExpansionFeature.available())
44
46
        
45
47
    def test_str(self):
46
 
        self.assertTrue("platform" in str(Win32Feature))
 
48
        self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
47
49
 
48
50
 
49
51
class TestWin32UtilsGlobExpand(TestCaseInTempDir):
50
52
 
51
 
    _test_needs_features = [Win32Feature]
 
53
    _test_needs_features = [NeedsGlobExpansionFeature]
52
54
   
53
55
    def test_empty_tree(self):
54
56
        self.build_tree([])
58
60
            [['*'], ['*']],
59
61
            [['a', 'a'], ['a', 'a']]])
60
62
        
61
 
    def test_tree1(self):
 
63
    def test_tree_ascii(self):
62
64
        """Checks the glob expansion and path separation char
63
65
        normalization"""
64
66
        self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
67
69
                         'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
68
70
        self._run_testset([
69
71
            # no wildcards
70
 
            [['a'], ['a']],
71
 
            [['a', 'a' ], ['a', 'a']],
72
 
            [['A'], ['A']],
 
72
            [[u'a'], [u'a']],
 
73
            [[u'a', u'a' ], [u'a', u'a']],
 
74
            [[u'A'], [u'A']],
73
75
                
74
 
            [['d'], ['d']],
75
 
            [['d/'], ['d/']],
76
 
            [['d\\'], ['d/']],
 
76
            [[u'd'], [u'd']],
 
77
            [[u'd/'], [u'd/']],
 
78
            [[u'd\\'], [u'd/']],
77
79
            
78
80
            # wildcards
79
 
            [['a*'], ['a', 'a1', 'a2', 'a11', 'a.1']],
80
 
            [['?'], ['a', 'b', 'c', 'd']],
81
 
            [['a?'], ['a1', 'a2']],
82
 
            [['a??'], ['a11', 'a.1']],
83
 
            [['b[1-2]'], ['b1', 'b2']],
84
 
            [['A?'], ['a1', 'a2']],
 
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']],
85
87
               
86
 
            [['d/*'], ['d/d1', 'd/d2', 'd/e']],
87
 
            [['d\\*'], ['d/d1', 'd/d2', 'd/e']],
88
 
            [['?\\*'], ['c/c1', 'c/c2', 'd/d1', 'd/d2', 'd/e']],
89
 
            [['*\\*'], ['c/c1', 'c/c2', 'd/d1', 'd/d2', 'd/e']],
90
 
            [['*/'], ['c/', 'd/']],
91
 
            [['*\\'], ['c/', 'd/']]])
 
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/']]])
92
94
        
93
 
    def test_tree2(self):
 
95
    def test_tree_unicode(self):
94
96
        """Checks behaviour with non-ascii filenames"""
95
 
        self.build_tree([u'�', u'�', u'�/', u'�/��'])
 
97
        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
96
98
        self._run_testset([
97
99
            # no wildcards
98
 
            [[u'�'], [u'�']],
99
 
            [[u'�'], [u'�']],
100
 
            
101
 
            [[u'�/'], [u'�/']],
102
 
            [[u'�/��'], [u'�/��']],
 
100
            [[u'\u1234'], [u'\u1234']],
 
101
            [[u'\u1235'], [u'\u1235']],
 
102
         
 
103
            [[u'\u1235/'], [u'\u1235/']],
 
104
            [[u'\u1235/\u1235'], [u'\u1235/\u1235']],
103
105
            
104
106
            # wildcards
105
 
            [[u'?'], [u'�', u'�', u'�']],
106
 
            [[u'*'], [u'�', u'�', u'�']],
 
107
            [[u'?'], [u'\u1234', u'\u1235']],
 
108
            [[u'*'], [u'\u1234', u'\u1234\u1234', u'\u1235']],
 
109
            [[u'\u1234*'], [u'\u1234', u'\u1234\u1234']],
107
110
            
108
 
            [[u'*/'], [u'�/']],
109
 
            [[u'*/*'], [u'�/��']]])
 
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']]])
110
123
 
111
124
    def _run_testset(self, testset):
112
125
        for pattern, expected in testset: