/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/tests/test_nonascii.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import sys
21
21
from unicodedata import normalize
22
22
 
23
 
from .. import osutils
24
 
from ..osutils import pathjoin
25
 
from . import TestCase, TestCaseWithTransport, TestSkipped
 
23
from brzlib import osutils
 
24
from brzlib.osutils import pathjoin
 
25
from brzlib.tests import TestCase, TestCaseWithTransport, TestSkipped
26
26
 
27
27
 
28
28
class NonAsciiTest(TestCaseWithTransport):
35
35
        except UnicodeEncodeError:
36
36
            raise TestSkipped("filesystem can't accomodate nonascii names")
37
37
            return
38
 
        with open(pathjoin(br_dir, "a"), "w") as f:
39
 
            f.write("hello")
40
 
        wt.add(["a"], [b"a-id"])
 
38
        with file(pathjoin(br_dir, "a"), "w") as f: f.write("hello")
 
39
        wt.add(["a"], ["a-id"])
41
40
 
42
41
 
43
42
a_circle_c = u'\xe5'
46
45
a_dots_d = u'a\u0308'
47
46
z_umlat_c = u'\u017d'
48
47
z_umlat_d = u'Z\u030c'
49
 
squared_c = u'\xbc'  # This gets mapped to '2' if we use NFK[CD]
 
48
squared_c = u'\xbc' # This gets mapped to '2' if we use NFK[CD]
50
49
squared_d = u'\xbc'
51
 
quarter_c = u'\xb2'  # Gets mapped to u'1\u20444' (1/4) if we use NFK[CD]
 
50
quarter_c = u'\xb2' # Gets mapped to u'1\u20444' (1/4) if we use NFK[CD]
52
51
quarter_d = u'\xb2'
53
52
 
54
53
 
116
115
        # a_circle_c and a_dots_c actually map to the same file
117
116
        # adding a suffix kicks in the 'preserving but insensitive'
118
117
        # route, and maintains the right files
119
 
        files = [a_circle_c + '.1', a_dots_c + '.2', z_umlat_c + '.3']
 
118
        files = [a_circle_c+'.1', a_dots_c+'.2', z_umlat_c+'.3']
120
119
        try:
121
120
            self.build_tree(files)
122
121
        except UnicodeError:
123
122
            raise TestSkipped("filesystem cannot create unicode files")
124
123
 
125
124
        if sys.platform == 'darwin':
126
 
            expected = sorted(
127
 
                [a_circle_d + '.1', a_dots_d + '.2', z_umlat_d + '.3'])
 
125
            expected = sorted([a_circle_d+'.1', a_dots_d+'.2', z_umlat_d+'.3'])
128
126
        else:
129
127
            expected = sorted(files)
130
128
 
138
136
        # a_circle_c and a_dots_c actually map to the same file
139
137
        # adding a suffix kicks in the 'preserving but insensitive'
140
138
        # route, and maintains the right files
141
 
        files = [a_circle_c + '.1', a_dots_c + '.2', z_umlat_c + '.3',
142
 
                 squared_c + '.4', quarter_c + '.5']
 
139
        files = [a_circle_c+'.1', a_dots_c+'.2', z_umlat_c+'.3',
 
140
                 squared_c+'.4', quarter_c+'.5']
143
141
        try:
144
142
            self.build_tree(files, line_endings='native')
145
143
        except UnicodeError:
153
151
            self.assertEqual(path, fname)
154
152
            self.assertTrue(can_access)
155
153
 
156
 
            with open(path, 'rb') as f:
 
154
            f = open(path, 'rb')
 
155
            try:
157
156
                # Check the contents
158
 
                shouldbe = b'contents of %s%s' % (path.encode('utf8'),
159
 
                                                  os.linesep.encode('utf-8'))
 
157
                shouldbe = 'contents of %s%s' % (path.encode('utf8'),
 
158
                                                 os.linesep)
160
159
                actual = f.read()
 
160
            finally:
 
161
                f.close()
161
162
            self.assertEqual(shouldbe, actual,
162
163
                             'contents of %r is incorrect: %r != %r'
163
164
                             % (path, shouldbe, actual))
165
166
    def test_access_non_normalized(self):
166
167
        # Sometimes we can access non-normalized files by their normalized
167
168
        # path, verify that normalized_filename returns the right info
168
 
        files = [a_circle_d + '.1', a_dots_d + '.2', z_umlat_d + '.3']
 
169
        files = [a_circle_d+'.1', a_dots_d+'.2', z_umlat_d+'.3']
169
170
 
170
171
        try:
171
172
            self.build_tree(files)