35
35
except UnicodeEncodeError:
36
36
raise TestSkipped("filesystem can't accomodate nonascii names")
38
with open(pathjoin(br_dir, "a"), "w") as f:
40
wt.add(["a"], [b"a-id"])
38
file(pathjoin(br_dir, "a"), "w").write("hello")
39
wt.add(["a"], ["a-id"])
43
42
a_circle_c = u'\xe5'
44
44
a_circle_d = u'a\u030a'
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]
51
quarter_c = u'\xb2' # Gets mapped to u'1\u20444' (1/4) if we use NFK[CD]
55
class TestNormalization(TestCase):
56
"""Verify that we have our normalizations correct."""
58
def test_normalize(self):
59
self.assertEqual(a_circle_d, normalize('NFD', a_circle_c))
60
self.assertEqual(a_circle_c, normalize('NFC', a_circle_d))
61
self.assertEqual(a_dots_d, normalize('NFD', a_dots_c))
62
self.assertEqual(a_dots_c, normalize('NFC', a_dots_d))
63
self.assertEqual(z_umlat_d, normalize('NFD', z_umlat_c))
64
self.assertEqual(z_umlat_c, normalize('NFC', z_umlat_d))
65
self.assertEqual(squared_d, normalize('NFC', squared_c))
66
self.assertEqual(squared_c, normalize('NFD', squared_d))
67
self.assertEqual(quarter_d, normalize('NFC', quarter_c))
68
self.assertEqual(quarter_c, normalize('NFD', quarter_d))
71
class NormalizedFilename(TestCaseWithTransport):
72
"""Test normalized_filename and associated helpers"""
74
def test__accessible_normalized_filename(self):
75
anf = osutils._accessible_normalized_filename
76
# normalized_filename should allow plain ascii strings
77
# not just unicode strings
78
self.assertEqual((u'ascii', True), anf('ascii'))
79
self.assertEqual((a_circle_c, True), anf(a_circle_c))
80
self.assertEqual((a_circle_c, True), anf(a_circle_d))
81
self.assertEqual((a_dots_c, True), anf(a_dots_c))
82
self.assertEqual((a_dots_c, True), anf(a_dots_d))
83
self.assertEqual((z_umlat_c, True), anf(z_umlat_c))
84
self.assertEqual((z_umlat_c, True), anf(z_umlat_d))
85
self.assertEqual((squared_c, True), anf(squared_c))
86
self.assertEqual((squared_c, True), anf(squared_d))
87
self.assertEqual((quarter_c, True), anf(quarter_c))
88
self.assertEqual((quarter_c, True), anf(quarter_d))
90
def test__inaccessible_normalized_filename(self):
91
inf = osutils._inaccessible_normalized_filename
92
# normalized_filename should allow plain ascii strings
93
# not just unicode strings
94
self.assertEqual((u'ascii', True), inf('ascii'))
95
self.assertEqual((a_circle_c, True), inf(a_circle_c))
96
self.assertEqual((a_circle_c, False), inf(a_circle_d))
97
self.assertEqual((a_dots_c, True), inf(a_dots_c))
98
self.assertEqual((a_dots_c, False), inf(a_dots_d))
99
self.assertEqual((z_umlat_c, True), inf(z_umlat_c))
100
self.assertEqual((z_umlat_c, False), inf(z_umlat_d))
101
self.assertEqual((squared_c, True), inf(squared_c))
102
self.assertEqual((squared_c, True), inf(squared_d))
103
self.assertEqual((quarter_c, True), inf(quarter_c))
104
self.assertEqual((quarter_c, True), inf(quarter_d))
106
def test_functions(self):
107
if osutils.normalizes_filenames():
108
self.assertEqual(osutils.normalized_filename,
109
osutils._accessible_normalized_filename)
50
class UnicodeFilename(TestCaseWithTransport):
51
"""Test that UnicodeFilename returns the expected values."""
53
def test_a_circle(self):
54
self.assertEqual(a_circle_d, normalize('NFKD', a_circle_c))
55
self.assertEqual(a_circle_c, normalize('NFKC', a_circle_d))
57
self.assertEqual((a_circle_c, True), unicode_filename(a_circle_c))
58
if normalizes_filenames():
59
self.assertEqual((a_circle_c, True), unicode_filename(a_circle_d))
111
self.assertEqual(osutils.normalized_filename,
112
osutils._inaccessible_normalized_filename)
61
self.assertEqual((a_circle_d, False), unicode_filename(a_circle_d))
114
63
def test_platform(self):
115
# With FAT32 and certain encodings on win32
116
# a_circle_c and a_dots_c actually map to the same file
117
# adding a suffix kicks in the 'preserving but insensitive'
118
# route, and maintains the right files
119
files = [a_circle_c + '.1', a_dots_c + '.2', z_umlat_c + '.3']
121
self.build_tree(files)
123
raise TestSkipped("filesystem cannot create unicode files")
64
raise TestSkipped('This test is skipped until unicode filenames are worked out')
65
# FIXME: jam 20060425 Right now build_tree does not accept unicode filenames
66
self.build_tree([a_circle_c, a_dots_c, z_umlat_c])
125
68
if sys.platform == 'darwin':
127
[a_circle_d + '.1', a_dots_d + '.2', z_umlat_d + '.3'])
69
expected = sorted([a_circle_d, a_dots_d, z_umlat_d])
129
expected = sorted(files)
71
expected = sorted([a_circle_c, a_dots_c, z_umlat_c])
131
73
present = sorted(os.listdir(u'.'))
132
74
self.assertEqual(expected, present)
134
def test_access_normalized(self):
135
# We should always be able to access files created with
136
# normalized filenames
137
# With FAT32 and certain encodings on win32
138
# a_circle_c and a_dots_c actually map to the same file
139
# adding a suffix kicks in the 'preserving but insensitive'
140
# 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']
144
self.build_tree(files, line_endings='native')
146
raise TestSkipped("filesystem cannot create unicode files")
149
# We should get an exception if we can't open the file at
151
path, can_access = osutils.normalized_filename(fname)
153
self.assertEqual(path, fname)
154
self.assertTrue(can_access)
156
with open(path, 'rb') as f:
158
shouldbe = b'contents of %s%s' % (path.encode('utf8'),
159
os.linesep.encode('utf-8'))
161
self.assertEqual(shouldbe, actual,
162
'contents of %r is incorrect: %r != %r'
163
% (path, shouldbe, actual))
165
def test_access_non_normalized(self):
166
# Sometimes we can access non-normalized files by their normalized
167
# path, verify that normalized_filename returns the right info
168
files = [a_circle_d + '.1', a_dots_d + '.2', z_umlat_d + '.3']
171
self.build_tree(files)
173
raise TestSkipped("filesystem cannot create unicode files")
176
# We should get an exception if we can't open the file at
178
path, can_access = osutils.normalized_filename(fname)
180
self.assertNotEqual(path, fname)
182
# We should always be able to access them from the name
183
# they were created with
184
f = open(fname, 'rb')
76
def test_access(self):
77
# We should always be able to access files by the path returned
78
# from unicode_filename
79
raise TestSkipped('This test is skipped until unicode filenames are worked out')
80
# FIXME: jam 20060425 Right now build_tree does not accept unicode filenames
81
files = [a_circle_c, a_dots_c, z_umlat_c]
82
self.build_tree(files)
85
path = unicode_filename(fname)[0]
86
# We should get an exception if we can't open the file at
187
# And normalized_filename sholud tell us correctly if we can
188
# access them by an alternate name
193
self.assertRaises(IOError, open, path, 'rb')