forked from chaoss/grimoirelab-perceval
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_errors.py
141 lines (93 loc) · 4.22 KB
/
test_errors.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015-2020 Bitergia
#
# 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 3 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, see <http://www.gnu.org/licenses/>.
#
# Authors:
# Santiago Dueñas <[email protected]>
# Stephan Barth <[email protected]>
# Valerio Cosentino <[email protected]>
# Miguel Ángel Fernández <[email protected]>
#
import unittest
import perceval.errors as errors
# Mock classes to test BaseError class
class MockErrorNoArgs(errors.BaseError):
message = "Mock error without args"
class MockErrorArgs(errors.BaseError):
message = "Mock error with args. Error: %(code)s %(msg)s"
class TestBaseError(unittest.TestCase):
def test_subblass_with_no_args(self):
"""Check subclasses that do not require arguments.
Arguments passed to the constructor should be ignored.
"""
e = MockErrorNoArgs(code=1, msg='Fatal error')
self.assertEqual("Mock error without args", str(e))
def test_subclass_args(self):
"""Check subclasses that require arguments"""
e = MockErrorArgs(code=1, msg='Fatal error')
self.assertEqual("Mock error with args. Error: 1 Fatal error",
str(e))
def test_subclass_invalid_args(self):
"""Check when required arguments are not given.
When this happens, it raises a KeyError exception.
"""
kwargs = {'code': 1, 'error': 'Fatal error'}
self.assertRaises(KeyError, MockErrorArgs, **kwargs)
class TestArchiveError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.ArchiveError(cause='archive item not found')
self.assertEqual('archive item not found', str(e))
class TestArchiveManagerError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.ArchiveManagerError(cause='archive not found')
self.assertEqual('archive not found', str(e))
class TestBackendError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.BackendError(cause='mock error on backend')
self.assertEqual('mock error on backend', str(e))
class TestRepositoryError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.RepositoryError(cause='error cloning repository')
self.assertEqual('error cloning repository', str(e))
class TestRateLimitError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.RateLimitError(cause="client rate exhausted",
seconds_to_reset=10)
self.assertEqual("client rate exhausted; 10 seconds to rate reset",
str(e))
def test_seconds_to_reset_property(self):
"""Test property"""
e = errors.RateLimitError(cause="client rate exhausted",
seconds_to_reset=10)
self.assertEqual(e.seconds_to_reset, 10)
class TestParseError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.ParseError(cause='error on line 10')
self.assertEqual('error on line 10', str(e))
class TestBackendCommandArgumentParserError(unittest.TestCase):
def test_message(self):
"""Make sure that prints the correct error"""
e = errors.BackendCommandArgumentParserError(cause='mock error on backend command argument parser')
self.assertEqual('mock error on backend command argument parser', str(e))
if __name__ == "__main__":
unittest.main()