/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 bzrlib/tests/test_nonascii.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-02 05:28:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1851.
  • Revision ID: john@arbash-meinel.com-20060702052812-2edccb8f915f46b2
A couple no-op cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Canonical Ltd
 
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
 
 
17
"""Test that various operations work in a non-ASCII environment."""
 
18
 
 
19
import os
 
20
import sys
 
21
from unicodedata import normalize
 
22
 
 
23
from bzrlib import osutils
 
24
from bzrlib.osutils import pathjoin
 
25
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
26
from bzrlib.workingtree import WorkingTree
 
27
 
 
28
 
 
29
class NonAsciiTest(TestCaseWithTransport):
 
30
 
 
31
    def test_add_in_nonascii_branch(self):
 
32
        """Test adding in a non-ASCII branch."""
 
33
        br_dir = u"\u1234"
 
34
        try:
 
35
            wt = self.make_branch_and_tree(br_dir)
 
36
        except UnicodeEncodeError:
 
37
            raise TestSkipped("filesystem can't accomodate nonascii names")
 
38
            return
 
39
        file(pathjoin(br_dir, "a"), "w").write("hello")
 
40
        wt.add(["a"], ["a-id"])
 
41
 
 
42
 
 
43
a_circle_c = u'\xe5'
 
44
a_dots_c = u'\xe4'
 
45
a_circle_d = u'a\u030a'
 
46
a_dots_d = u'a\u0308'
 
47
z_umlat_c = u'\u017d'
 
48
z_umlat_d = u'Z\u030c'
 
49
 
 
50
 
 
51
class TestNormalization(TestCase):
 
52
    """Verify that we have our normalizations correct."""
 
53
 
 
54
    def test_normalize(self):
 
55
        self.assertEqual(a_circle_d, normalize('NFKD', a_circle_c))
 
56
        self.assertEqual(a_circle_c, normalize('NFKC', a_circle_d))
 
57
        self.assertEqual(a_dots_d, normalize('NFKD', a_dots_c))
 
58
        self.assertEqual(a_dots_c, normalize('NFKC', a_dots_d))
 
59
        self.assertEqual(z_umlat_d, normalize('NFKD', z_umlat_c))
 
60
        self.assertEqual(z_umlat_c, normalize('NFKC', z_umlat_d))
 
61
 
 
62
 
 
63
class NormalizedFilename(TestCaseWithTransport):
 
64
    """Test normalized_filename and associated helpers"""
 
65
 
 
66
    def test__accessible_normalized_filename(self):
 
67
        anf = osutils._accessible_normalized_filename
 
68
        self.assertEqual((a_circle_c, True), anf(a_circle_c))
 
69
        self.assertEqual((a_circle_c, True), anf(a_circle_d))
 
70
        self.assertEqual((a_dots_c, True), anf(a_dots_c))
 
71
        self.assertEqual((a_dots_c, True), anf(a_dots_d))
 
72
        self.assertEqual((z_umlat_c, True), anf(z_umlat_c))
 
73
        self.assertEqual((z_umlat_c, True), anf(z_umlat_d))
 
74
 
 
75
    def test__inaccessible_normalized_filename(self):
 
76
        inf = osutils._inaccessible_normalized_filename
 
77
        self.assertEqual((a_circle_c, True), inf(a_circle_c))
 
78
        self.assertEqual((a_circle_c, False), inf(a_circle_d))
 
79
        self.assertEqual((a_dots_c, True), inf(a_dots_c))
 
80
        self.assertEqual((a_dots_c, False), inf(a_dots_d))
 
81
        self.assertEqual((z_umlat_c, True), inf(z_umlat_c))
 
82
        self.assertEqual((z_umlat_c, False), inf(z_umlat_d))
 
83
 
 
84
    def test_functions(self):
 
85
        if osutils.normalizes_filenames():
 
86
            self.assertEqual(osutils.normalized_filename,
 
87
                             osutils._accessible_normalized_filename)
 
88
        else:
 
89
            self.assertEqual(osutils.normalized_filename,
 
90
                             osutils._inaccessible_normalized_filename)
 
91
 
 
92
    def test_platform(self):
 
93
        try:
 
94
            self.build_tree([a_circle_c, a_dots_c, z_umlat_c])
 
95
        except UnicodeError:
 
96
            raise TestSkipped("filesystem cannot create unicode files")
 
97
 
 
98
        if sys.platform == 'darwin':
 
99
            expected = sorted([a_circle_d, a_dots_d, z_umlat_d])
 
100
        else:
 
101
            expected = sorted([a_circle_c, a_dots_c, z_umlat_c])
 
102
 
 
103
        present = sorted(os.listdir(u'.'))
 
104
        self.assertEqual(expected, present)
 
105
 
 
106
    def test_access_normalized(self):
 
107
        # We should always be able to access files created with normalized filenames
 
108
        files = [a_circle_c, a_dots_c, z_umlat_c]
 
109
        try:
 
110
            self.build_tree(files)
 
111
        except UnicodeError:
 
112
            raise TestSkipped("filesystem cannot create unicode files")
 
113
 
 
114
        for fname in files:
 
115
            # We should get an exception if we can't open the file at
 
116
            # this location.
 
117
            path, can_access = osutils.normalized_filename(fname)
 
118
 
 
119
            self.assertEqual(path, fname)
 
120
            self.assertTrue(can_access)
 
121
 
 
122
            f = open(path, 'rb')
 
123
            f.close()
 
124
 
 
125
    def test_access_non_normalized(self):
 
126
        # Sometimes we can access non-normalized files by their normalized
 
127
        # path, verify that normalized_filename returns the right info
 
128
        files = [a_circle_d, a_dots_d, z_umlat_d]
 
129
 
 
130
        try:
 
131
            self.build_tree(files)
 
132
        except UnicodeError:
 
133
            raise TestSkipped("filesystem cannot create unicode files")
 
134
 
 
135
        for fname in files:
 
136
            # We should get an exception if we can't open the file at
 
137
            # this location.
 
138
            path, can_access = osutils.normalized_filename(fname)
 
139
 
 
140
            self.assertNotEqual(path, fname)
 
141
 
 
142
            # We should always be able to access them from the name
 
143
            # they were created with
 
144
            f = open(fname, 'rb')
 
145
            f.close()
 
146
 
 
147
            # And normalized_filename sholud tell us correctly if we can
 
148
            # access them by an alternate name
 
149
            if can_access:
 
150
                f = open(path, 'rb')
 
151
                f.close()
 
152
            else:
 
153
                self.assertRaises(IOError, open, path, 'rb')