~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_nonascii.py

  • Committer: John Arbash Meinel
  • Date: 2006-01-16 20:55:04 UTC
  • mto: (1685.1.1 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060116205504-a50588b5612d2912
Adding bzrlib.osutils.unicode_filename to handle unicode normalization for file paths.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Test that various operations work in a non-ASCII environment."""
18
18
 
19
19
import os
 
20
import sys
 
21
from unicodedata import normalize
20
22
 
 
23
from bzrlib.branch import Branch
 
24
from bzrlib.osutils import normalizes_filenames, unicode_filename
21
25
from bzrlib.tests import TestCaseInTempDir
22
 
from bzrlib.branch import Branch
23
26
 
24
27
 
25
28
class NonAsciiTest(TestCaseInTempDir):
36
39
        br = Branch.initialize(u".")
37
40
        file("a", "w").write("hello")
38
41
        br.working_tree().add(["a"], ["a-id"])
 
42
 
 
43
 
 
44
a_circle_c = u'\xe5'
 
45
a_dots_c = u'\xe4'
 
46
a_circle_d = u'a\u030a'
 
47
a_dots_d = u'a\u0308'
 
48
z_umlat_c = u'\u017d'
 
49
z_umlat_d = u'Z\u030c'
 
50
 
 
51
 
 
52
class UnicodeFilename(TestCaseInTempDir):
 
53
    """Test that UnicodeFilename returns the expected values."""
 
54
 
 
55
    def test_a_circle(self):
 
56
        self.assertEqual(a_circle_d, normalize('NFKD', a_circle_c))
 
57
        self.assertEqual(a_circle_c, normalize('NFKC', a_circle_d))
 
58
 
 
59
        self.assertEqual((a_circle_c, True), unicode_filename(a_circle_c))
 
60
        if normalizes_filenames():
 
61
            self.assertEqual((a_circle_c, True), unicode_filename(a_circle_d))
 
62
        else:
 
63
            self.assertEqual((a_circle_d, False), unicode_filename(a_circle_d))
 
64
 
 
65
    def test_platform(self):
 
66
        self.build_tree([a_circle_c, a_dots_c, z_umlat_c])
 
67
 
 
68
        if sys.platform == 'darwin':
 
69
            expected = sorted([a_circle_d, a_dots_d, z_umlat_d])
 
70
        else:
 
71
            expected = sorted([a_circle_c, a_dots_c, z_umlat_c])
 
72
 
 
73
        present = sorted(os.listdir(u'.'))
 
74
        self.assertEqual(expected, present)
 
75
 
 
76
    def test_access(self):
 
77
        # We should always be able to access files by the path returned
 
78
        # from unicode_filename
 
79
        files = [a_circle_c, a_dots_c, z_umlat_c]
 
80
        self.build_tree(files)
 
81
 
 
82
        for fname in files:
 
83
            path = unicode_filename(fname)[0]
 
84
            # We should get an exception if we can't open the file at
 
85
            # this location.
 
86
            f = open(path, 'rb')
 
87
            f.close()
 
88
 
 
89