Passed
Pull Request — master (#618)
by Jose
02:12
created

pyof.foundation.exceptions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 6
eloc 23
dl 0
loc 64
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A WrongListItemType.__init__() 0 12 1
A ValidationError.__str__() 0 2 1
A WrongListItemType.__str__() 0 3 1
A MethodNotImplemented.__str__() 0 2 1
A BadValueException.__str__() 0 2 1
A UnsupportedVersion.__str__() 0 2 1
1
"""Exceptions raised by this library."""
2
3
4 1
class ValidationError(Exception):
5
    """Can be used directly or inherited by mpre specific validation errors."""
6
7 1
    def __str__(self):
8
        return "Validation error: " + super().__str__()
9
10
11 1
class MethodNotImplemented(Exception):
12
    """Exception to be raised when a method is not implemented."""
13
14 1
    def __str__(self):
15
        return "Method not yet implemented: " + super().__str__()
16
17
18 1
class BadValueException(Exception):
19
    """Attribute has an unexpected value."""
20
21 1
    def __str__(self):
22
        return "BadValue error: " + super().__str__()
23
24
25 1
class WrongListItemType(Exception):
26
    """When an item of a wrong type is inserted into a list.
27
28
    Exception used by :class:`.FixedTypeList` and :class:`.ConstantTypeList`
29
    when the user tries to insert an item that does not match the expected
30
    type.
31
    """
32
33 1
    def __init__(self, item_class, expected_class):
34
        """Take the parameters to inform the user about the error.
35
36
        Args:
37
            item_class (:obj:`type`): The class of the item that was being
38
                inserted in the list when the exception was raised.
39
            expected_class (:obj:`type`): The expected type that didn't match
40
                against the item to be inserted.
41
        """
42
        super().__init__()
43
        self.item_class = item_class
44
        self.expected_class = expected_class
45
46 1
    def __str__(self):
47
        return "'{}' is not an instance of {}".format(self.item_class,
48
                                                      self.expected_class)
49
50
51 1
class UnpackException(Exception):
52
    """Error while unpacking."""
53
54
55 1
class PackException(Exception):
56
    """Error while unpacking."""
57
58
59 1
class UnsupportedVersion(Exception):
60
    """Exception raised when an unsupported OpenFlow version is specified."""
61
62 1
    def __str__(self):
63
        return "Version not supported: " + super().__str__()
64