1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from bzrlib.errors import (ConnectionError, ConnectionReset, LockError,
PermissionDenied, TransportError,
UnexpectedEndOfContainerError)
from bzrlib.tests import TestCase
from errors import (convert_svn_error, convert_error, InvalidPropertyValue,
InvalidSvnBranchPath, NotSvnBranchPath,
SVN_ERR_UNKNOWN_HOSTNAME)
import svn.core
from svn.core import SubversionException
class TestConvertError(TestCase):
def test_decorator_unknown(self):
@convert_svn_error
def test_throws_svn():
raise SubversionException("foo", 2000)
self.assertRaises(SubversionException, test_throws_svn)
def test_decorator_known(self):
@convert_svn_error
def test_throws_svn():
raise SubversionException("Connection closed", svn.core.SVN_ERR_RA_SVN_CONNECTION_CLOSED)
self.assertRaises(ConnectionReset, test_throws_svn)
def test_convert_error_oserror(self):
self.assertIsInstance(convert_error(SubversionException("foo", 13)),
OSError)
def test_convert_error_unknown(self):
self.assertIsInstance(convert_error(SubversionException("foo", -4)),
SubversionException)
def test_convert_malformed(self):
self.assertIsInstance(convert_error(SubversionException("foo", svn.core.SVN_ERR_RA_SVN_MALFORMED_DATA)), TransportError)
def test_convert_error_reset(self):
self.assertIsInstance(convert_error(SubversionException("Connection closed", svn.core.SVN_ERR_RA_SVN_CONNECTION_CLOSED)), ConnectionReset)
def test_convert_error_lock(self):
self.assertIsInstance(convert_error(SubversionException("Working copy locked", svn.core.SVN_ERR_WC_LOCKED)), LockError)
def test_convert_perm_denied(self):
self.assertIsInstance(convert_error(SubversionException("Permission Denied", svn.core.SVN_ERR_RA_NOT_AUTHORIZED)), PermissionDenied)
def test_convert_unexpected_end(self):
self.assertIsInstance(convert_error(SubversionException("Unexpected end of stream", svn.core.SVN_ERR_INCOMPLETE_DATA)), UnexpectedEndOfContainerError)
def test_convert_unknown_hostname(self):
self.assertIsInstance(convert_error(SubversionException("Unknown hostname 'bla'", SVN_ERR_UNKNOWN_HOSTNAME)), ConnectionError)
def test_not_implemented(self):
self.assertIsInstance(convert_error(SubversionException("Remote server doesn't support ...", svn.core.SVN_ERR_RA_NOT_IMPLEMENTED)), NotImplementedError)
def test_decorator_nothrow(self):
@convert_svn_error
def test_nothrow(foo):
return foo+1
self.assertEqual(2, test_nothrow(1))
def test_invalid_property_value(self):
error = InvalidPropertyValue("svn:foobar", "corrupt")
self.assertEqual(
"Invalid property value for Subversion property svn:foobar: corrupt",
str(error))
def test_invalidsvnbranchpath_nonascii(self):
InvalidSvnBranchPath('\xc3\xb6', None)
def test_notsvnbranchpath_nonascii(self):
NotSvnBranchPath('\xc3\xb6', None)
|