1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
1 |
# Copyright (C) 2005 by Canonical Development 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 Escaped Stores."""
|
|
18 |
||
19 |
from cStringIO import StringIO |
|
20 |
import os |
|
21 |
import gzip |
|
22 |
||
23 |
from bzrlib.errors import BzrError, UnlistableStore, NoSuchFile |
|
24 |
from bzrlib.store import copy_all |
|
25 |
from bzrlib.store.text import TextStore |
|
26 |
from bzrlib.tests import TestCaseWithTransport |
|
27 |
import bzrlib.transport |
|
28 |
||
29 |
||
30 |
class TestEscaped(TestCaseWithTransport): |
|
31 |
"""Mixin template class that provides some common tests for stores"""
|
|
32 |
||
33 |
def get_store(self, prefixed=False, escaped=True): |
|
34 |
t = bzrlib.transport.get_transport(self.get_url()) |
|
35 |
return TextStore(t, prefixed=prefixed, escaped=escaped) |
|
36 |
||
37 |
def test_paths(self): |
|
38 |
text_store = self.get_store() |
|
39 |
||
40 |
self.assertEqual('a', text_store._relpath('a')) |
|
41 |
self.assertEqual('a', text_store._relpath(u'a')) |
|
42 |
self.assertEqual('%2520', text_store._relpath(' ')) |
|
1185.80.7
by John Arbash Meinel
Changing the escapes so that we leave @ as unescaped. |
43 |
self.assertEqual('%40%253A%253C%253E', text_store._relpath('@:<>')) |
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
44 |
self.assertEqual('%25C3%25A5', text_store._relpath(u'\xe5')) |
45 |
||
46 |
def test_prefixed(self): |
|
47 |
# Prefix should be determined by unescaped string
|
|
48 |
text_store = self.get_store(prefixed=True) |
|
49 |
||
50 |
# hash_prefix() is not defined for unicode characters
|
|
51 |
# it is only defined for byte streams.
|
|
52 |
# so hash_prefix() needs to operate on *at most* utf-8
|
|
53 |
# encoded. However urlescape() does both encoding to utf-8
|
|
54 |
# and urllib quoting, so we will use the escaped form
|
|
55 |
# as the path passed to hash_prefix
|
|
56 |
||
57 |
self.assertEqual('62/a', text_store._relpath('a')) |
|
58 |
self.assertEqual('88/%2520', text_store._relpath(' ')) |
|
1185.80.7
by John Arbash Meinel
Changing the escapes so that we leave @ as unescaped. |
59 |
self.assertEqual('12/%40%253A%253C%253E', |
1185.80.5
by John Arbash Meinel
Changing the escaping just a little bit. Now we can handle unicode characters. |
60 |
text_store._relpath('@:<>')) |
61 |
self.assertEqual('37/%25C3%25A5', text_store._relpath(u'\xe5')) |
|
62 |
||
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
63 |
def test_files(self): |
64 |
text_store = self.get_store(prefixed=True) |
|
65 |
||
66 |
text_store.add(StringIO('a'), 'a') |
|
67 |
self.failUnlessExists('62/a') |
|
68 |
||
69 |
text_store.add(StringIO('space'), ' ') |
|
70 |
self.failUnlessExists('88/%20') |
|
71 |
self.assertEquals('space', text_store.get(' ').read()) |
|
72 |
||
73 |
text_store.add(StringIO('surprise'), '@:<>') |
|
1185.80.7
by John Arbash Meinel
Changing the escapes so that we leave @ as unescaped. |
74 |
self.failUnlessExists('12/@%3A%3C%3E') |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
75 |
self.assertEquals('surprise', text_store.get('@:<>').read()) |
76 |
||
77 |
text_store.add(StringIO('unicode'), u'\xe5') |
|
78 |
self.failUnlessExists('37/%C3%A5') |
|
79 |
self.assertEquals('unicode', text_store.get(u'\xe5').read()) |
|
80 |
||
81 |
def test_weave(self): |
|
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
82 |
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. |
83 |
from bzrlib.transactions import PassThroughTransaction |
84 |
||
85 |
trans = PassThroughTransaction() |
|
86 |
||
87 |
t = bzrlib.transport.get_transport(self.get_url()) |
|
88 |
weave_store = WeaveStore(t, prefixed=True, escaped=True) |
|
89 |
||
90 |
weave_store.add_text('a', 'r', ['a'], [], trans) |
|
91 |
self.failUnlessExists('62/a.weave') |
|
92 |
self.assertEqual(['a'], weave_store.get_lines('a', 'r', trans)) |
|
93 |
||
94 |
weave_store.add_text(' ', 'r', ['space'], [], trans) |
|
1608.2.1
by Martin Pool
[merge] Storage filename escaping |
95 |
self.failIfExists('21/ .weave') |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
96 |
self.failUnlessExists('88/%20.weave') |
97 |
self.assertEquals(['space'], weave_store.get_lines(' ', 'r', trans)) |
|
98 |
||
99 |
weave_store.add_text('@:<>', 'r', ['surprise'], [], trans) |
|
1185.80.7
by John Arbash Meinel
Changing the escapes so that we leave @ as unescaped. |
100 |
self.failUnlessExists('12/@%3A%3C%3E.weave') |
1185.80.6
by John Arbash Meinel
Adding tests to make sure weave stores can retrieve the files they add. |
101 |
self.assertEquals(['surprise'], weave_store.get_lines('@:<>', 'r', trans)) |
102 |
||
103 |
weave_store.add_text(u'\xe5', 'r', ['unicode'], [], trans) |
|
104 |
self.failUnlessExists('37/%C3%A5.weave') |
|
105 |
self.assertEquals(['unicode'], weave_store.get_lines(u'\xe5', 'r', trans)) |
|
106 |