Merge error improvements.
[jelmer/subvertpy.git] / tests / test_errors.py
1 # Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
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 3 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 from bzrlib.errors import (ConnectionError, ConnectionReset, LockError, 
18                            PermissionDenied, TransportError,
19                            UnexpectedEndOfContainerError)
20 from bzrlib.tests import TestCase
21
22 from bzrlib.plugins.svn import constants
23 from bzrlib.plugins.svn.core import SubversionException
24 from bzrlib.plugins.svn.errors import (convert_svn_error, convert_error, InvalidPropertyValue, 
25                     InvalidSvnBranchPath, NotSvnBranchPath)
26
27
28 class TestConvertError(TestCase):
29     def test_decorator_unknown(self):
30         @convert_svn_error
31         def test_throws_svn():
32             raise SubversionException("foo", 2000)
33
34         self.assertRaises(SubversionException, test_throws_svn)
35
36     def test_decorator_known(self):
37         @convert_svn_error
38         def test_throws_svn():
39             raise SubversionException("Connection closed", constants.ERR_RA_SVN_CONNECTION_CLOSED)
40
41         self.assertRaises(ConnectionReset, test_throws_svn)
42
43     def test_convert_error_oserror(self):
44         self.assertIsInstance(convert_error(SubversionException("foo", 13)),
45                 OSError)
46
47     def test_convert_error_unknown(self):
48         self.assertIsInstance(convert_error(SubversionException("foo", -4)),
49                 SubversionException)
50
51     def test_convert_malformed(self):
52         self.assertIsInstance(convert_error(SubversionException("foo", constants.ERR_RA_SVN_MALFORMED_DATA)), TransportError)
53
54     def test_convert_error_reset(self):
55         self.assertIsInstance(convert_error(SubversionException("Connection closed", constants.ERR_RA_SVN_CONNECTION_CLOSED)), ConnectionReset)
56
57     def test_convert_error_lock(self):
58         self.assertIsInstance(convert_error(SubversionException("Working copy locked", constants.ERR_WC_LOCKED)), LockError)
59
60     def test_convert_perm_denied(self):
61         self.assertIsInstance(convert_error(SubversionException("Permission Denied", constants.ERR_RA_NOT_AUTHORIZED)), PermissionDenied)
62
63     def test_convert_unexpected_end(self):
64         self.assertIsInstance(convert_error(SubversionException("Unexpected end of stream", constants.ERR_INCOMPLETE_DATA)), UnexpectedEndOfContainerError)
65
66     def test_convert_unknown_hostname(self):
67         self.assertIsInstance(convert_error(SubversionException("Unknown hostname 'bla'", constants.ERR_UNKNOWN_HOSTNAME)), ConnectionError)
68
69     def test_not_implemented(self):
70         self.assertIsInstance(convert_error(SubversionException("Remote server doesn't support ...", constants.ERR_RA_NOT_IMPLEMENTED)), NotImplementedError)
71
72     def test_decorator_nothrow(self):
73         @convert_svn_error
74         def test_nothrow(foo):
75             return foo+1
76         self.assertEqual(2, test_nothrow(1))
77
78     def test_invalid_property_value(self):
79         error = InvalidPropertyValue("svn:foobar", "corrupt")
80
81         self.assertEqual(
82           "Invalid property value for Subversion property svn:foobar: corrupt", 
83           str(error))
84
85     def test_notsvnbranchpath_nonascii(self):
86         NotSvnBranchPath('\xc3\xb6', None)
87
88     def test_invalidsvnbranchpath_nonascii(self):
89         InvalidSvnBranchPath('\xc3\xb6', None)
90