Passed
Push — main ( 82a426...0ba81e )
by Sat CFDI
05:06
created

satcfdi.models.code   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 40
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Code.__init__() 0 3 1
A Code.__repr__() 0 8 1
A Code.__str__() 0 6 3
A Code.__hash__() 0 2 1
A Code.__eq__() 0 8 5
1 1
import logging
2 1
from enum import Enum
3
4 1
logger = logging.getLogger(__name__)
5
6
7 1
class Code:
8 1
    def __init__(self, code, description):
9 1
        self.code = code
10 1
        self.description = description
11
12 1
    def __str__(self):
13 1
        if self.description is None:
14 1
            return self.code
15 1
        if isinstance(self.description, list):
16 1
            return str(self.code) + " - " + "; ".join(self.description)
17 1
        return str(self.code) + " - " + str(self.description)
18
19
    def __repr__(self):
20
        # return '%s.%s(%s)' % (self.__class__.__module__,
21
        #                       self.__class__.__qualname__,
22
        #                       f'{repr(self.code)}, {repr(self.description)}')
23
24
        return '%s(%s)' % (
25
            self.__class__.__qualname__,
26
            f'{repr(self.code)}, {repr(self.description)}'
27
        )
28
29 1
    def __eq__(self, other):
30 1
        if isinstance(other, Code):
31 1
            return self.code == other.code
32 1
        if isinstance(other, str) or isinstance(other, int):
33 1
            return self.code == other
34 1
        if isinstance(other, Enum):
35 1
            return self.code == other.value
36
        return NotImplemented
37
38 1
    def __hash__(self):
39 1
        return self.code.__hash__()
40
41
42