2309.4.6
by John Arbash Meinel
Update the 'escaped store' tests to use both unicode and utf8 file ids. |
1 |
# Copyright (C) 2005, 2007 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
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 Escaped Stores."""
|
|
18 |
||
19 |
from cStringIO import StringIO |
|
20 |
import os |
|
21 |
import gzip |
|
22 |
||
2309.4.6
by John Arbash Meinel
Update the 'escaped store' tests to use both unicode and utf8 file ids. |
23 |
from bzrlib import osutils |
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
24 |
from bzrlib.errors import BzrError, UnlistableStore, NoSuchFile |
25 |
from bzrlib.store import copy_all |
|
26 |
from bzrlib.store.text import TextStore |
|
27 |
from bzrlib.tests import TestCaseWithTransport |
|
28 |
import bzrlib.transport |
|
29 |
||
30 |
||
31 |
class TestEscaped(TestCaseWithTransport): |
|
32 |
"""Mixin template class that provides some common tests for stores"""
|
|
33 |
||
34 |
def get_store(self, prefixed=False, escaped=True): |
|
35 |
t = bzrlib.transport.get_transport(self.get_url()) |
|
36 |
return TextStore(t, prefixed=prefixed, escaped=escaped) |
|
37 |
||
38 |
def test_paths(self): |
|
39 |
text_store = self.get_store() |
|
40 |
||
41 |
self.assertEqual('a', text_store._relpath('a')) |
|
42 |
self.assertEqual('a', text_store._relpath(u'a')) |
|
43 |
self.assertEqual('%2520', text_store._relpath(' ')) |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
44 |
self.assertEqual('%40%253a%253c%253e', text_store._relpath('@:<>')) |
45 |
self.assertEqual('%25c3%25a5', text_store._relpath(u'\xe5')) |
|
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
46 |
|
47 |
def test_prefixed(self): |
|
48 |
# Prefix should be determined by unescaped string
|
|
49 |
text_store = self.get_store(prefixed=True) |
|
50 |
||
51 |
# hash_prefix() is not defined for unicode characters
|
|
52 |
# it is only defined for byte streams.
|
|
53 |
# so hash_prefix() needs to operate on *at most* utf-8
|
|
1685.1.45
by John Arbash Meinel
Moved url functions into bzrlib.urlutils |
54 |
# encoded. However urlutils.escape() does both encoding to utf-8
|
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
55 |
# and urllib quoting, so we will use the escaped form
|
56 |
# as the path passed to hash_prefix
|
|
57 |
||
58 |
self.assertEqual('62/a', text_store._relpath('a')) |
|
59 |
self.assertEqual('88/%2520', text_store._relpath(' ')) |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
60 |
self.assertEqual('72/%40%253a%253c%253e', |
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
61 |
text_store._relpath('@:<>')) |
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
62 |
self.assertEqual('77/%25c3%25a5', text_store._relpath(u'\xe5')) |
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
63 |
|
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
64 |
def test_files(self): |
65 |
text_store = self.get_store(prefixed=True) |
|
66 |
||
67 |
text_store.add(StringIO('a'), 'a') |
|
68 |
self.failUnlessExists('62/a') |
|
69 |
||
70 |
text_store.add(StringIO('space'), ' ') |
|
71 |
self.failUnlessExists('88/%20') |
|
72 |
self.assertEquals('space', text_store.get(' ').read()) |
|
73 |
||
74 |
text_store.add(StringIO('surprise'), '@:<>') |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
75 |
self.failUnlessExists('72/@%3a%3c%3e') |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
76 |
self.assertEquals('surprise', text_store.get('@:<>').read()) |
77 |
||
2309.4.6
by John Arbash Meinel
Update the 'escaped store' tests to use both unicode and utf8 file ids. |
78 |
self.callDeprecated([osutils._file_id_warning], |
79 |
text_store.add, StringIO('unicode'), u'\xe5') |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
80 |
self.failUnlessExists('77/%c3%a5') |
2309.4.6
by John Arbash Meinel
Update the 'escaped store' tests to use both unicode and utf8 file ids. |
81 |
self.assertEquals('unicode', |
82 |
self.callDeprecated([osutils._file_id_warning], |
|
83 |
text_store.get, u'\xe5').read()) |
|
84 |
self.assertEquals('unicode', text_store.get('\xc3\xa5').read()) |
|
85 |
||
86 |
text_store.add(StringIO('utf8'), '\xc2\xb5') |
|
87 |
self.failUnlessExists('77/%c2%b5') |
|
88 |
self.assertEquals('utf8', text_store.get('\xc2\xb5').read()) |
|
89 |
self.assertEquals('utf8', |
|
90 |
self.callDeprecated([osutils._file_id_warning], |
|
91 |
text_store.get, u'\xb5').read()) |
|
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
92 |
|
93 |
def test_weave(self): |
|
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
94 |
from bzrlib.store.versioned import WeaveStore |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
95 |
from bzrlib.transactions import PassThroughTransaction |
96 |
||
97 |
trans = PassThroughTransaction() |
|
98 |
||
99 |
t = bzrlib.transport.get_transport(self.get_url()) |
|
100 |
weave_store = WeaveStore(t, prefixed=True, escaped=True) |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
101 |
def add_text(file_id, rev_id, contents, parents, transaction): |
102 |
vfile = weave_store.get_weave_or_empty(file_id, transaction) |
|
1608.2.13
by Martin Pool
(test_escaped_store) fix typo |
103 |
vfile.add_lines(rev_id, parents, contents) |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
104 |
|
1662.1.5
by Martin Pool
(test_escaped_store) Avoid calling deprecated WeaveStore.get_lines method |
105 |
def check_text(file_id, revision_id, contents): |
106 |
vfile = weave_store.get_weave(file_id, trans) |
|
107 |
self.assertEqual(contents, vfile.get_lines(revision_id)) |
|
108 |
||
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
109 |
add_text('a', 'r', ['a'], [], trans) |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
110 |
self.failUnlessExists('62/a.weave') |
1662.1.5
by Martin Pool
(test_escaped_store) Avoid calling deprecated WeaveStore.get_lines method |
111 |
check_text('a', 'r', ['a']) |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
112 |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
113 |
add_text(' ', 'r', ['space'], [], trans) |
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
114 |
self.failIfExists('21/ .weave') |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
115 |
self.failUnlessExists('88/%20.weave') |
1662.1.5
by Martin Pool
(test_escaped_store) Avoid calling deprecated WeaveStore.get_lines method |
116 |
check_text(' ', 'r', ['space']) |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
117 |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
118 |
add_text('@:<>', 'r', ['surprise'], [], trans) |
119 |
self.failUnlessExists('72/@%3a%3c%3e.weave') |
|
1662.1.5
by Martin Pool
(test_escaped_store) Avoid calling deprecated WeaveStore.get_lines method |
120 |
check_text('@:<>', 'r', ['surprise']) |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
121 |
|
2309.4.6
by John Arbash Meinel
Update the 'escaped store' tests to use both unicode and utf8 file ids. |
122 |
self.callDeprecated([osutils._file_id_warning], |
123 |
add_text, u'\xe5', 'r', ['unicode'], [], trans) |
|
1608.2.12
by Martin Pool
Store-escaping must quote uppercase characters too, so that they're safely |
124 |
self.failUnlessExists('77/%c3%a5.weave') |
2309.4.6
by John Arbash Meinel
Update the 'escaped store' tests to use both unicode and utf8 file ids. |
125 |
self.callDeprecated([osutils._file_id_warning], |
126 |
check_text, u'\xe5', 'r', ['unicode']) |
|
127 |
check_text('\xc3\xa5', 'r', ['unicode']) |
|
128 |
||
129 |
add_text('\xc2\xb5', 'r', ['utf8'], [], trans) |
|
130 |
self.failUnlessExists('77/%c2%b5.weave') |
|
131 |
check_text('\xc2\xb5', 'r', ['utf8']) |
|
132 |
self.callDeprecated([osutils._file_id_warning], |
|
133 |
check_text, u'\xb5', 'r', ['utf8']) |