|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 import unittest |
|
18 |
|
19 |
|
20 |
|
21 from cone.public import api, exceptions |
|
22 |
|
23 class TestProblems(unittest.TestCase): |
|
24 |
|
25 def test_create_from_generic_exception(self): |
|
26 ex = RuntimeError('foobar') |
|
27 self.assertEquals( |
|
28 api.Problem.from_exception(ex), |
|
29 api.Problem('foobar', severity = api.Problem.SEVERITY_ERROR)) |
|
30 |
|
31 def test_create_from_cone_exception_simple(self): |
|
32 ex = exceptions.ConeException('foobar') |
|
33 self.assertEquals( |
|
34 api.Problem.from_exception(ex), |
|
35 api.Problem('foobar', |
|
36 type = '', |
|
37 severity = api.Problem.SEVERITY_ERROR)) |
|
38 |
|
39 def test_create_from_cone_exception_all_attributes(self): |
|
40 ex = exceptions.ConeException('foobar', |
|
41 problem_lineno = 101, |
|
42 problem_msg = 'foobar2', |
|
43 problem_type = 'foo.bar') |
|
44 self.assertEquals( |
|
45 api.Problem.from_exception(ex), |
|
46 api.Problem('foobar2', |
|
47 type = 'foo.bar', |
|
48 line = 101, |
|
49 severity = api.Problem.SEVERITY_ERROR)) |
|
50 |
|
51 def test_create_from_xml_parse_error(self): |
|
52 ex = exceptions.XmlParseError('XML parse error', |
|
53 problem_lineno = 1) |
|
54 self.assertEquals( |
|
55 api.Problem.from_exception(ex), |
|
56 api.Problem('XML parse error', |
|
57 type = 'xml', |
|
58 line = 1, |
|
59 severity = api.Problem.SEVERITY_ERROR)) |
|
60 |
|
61 if __name__ == '__main__': |
|
62 unittest.main() |
|
63 |