Completed
Pull Request — master (#302)
by
unknown
03:35 queued 01:22
created

ImageService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 10
ccs 18
cts 21
cp 0.8571
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 5 1
B create() 0 18 5
1 1
import logging
2
3 1
from ..domain import Image, Font
4
5 1
from ._base import Service
6
7
8 1
log = logging.getLogger(__name__)
9
10
11 1
class ImageService(Service):
12
13 1
    def __init__(self, template_store, font_store, image_store, **kwargs):
14 1
        super().__init__(**kwargs)
15 1
        self.template_store = template_store
16 1
        self.font_store = font_store
17 1
        self.image_store = image_store
18
19 1
    def create(self, template, text, style=None, font=None):
20 1
        font = font or self.font_store.find(Font.DEFAULT)
21
22 1
        image = Image(template, text, style=style, font=font)
23
24 1
        try:
25 1
            self.image_store.create(image)
26 1
        except OSError as exception:
27 1
            if "name too long" in str(exception):
28 1
                exception = self.exceptions.FilenameTooLong
29 1
            elif "image file" in str(exception):
30 1
                exception = self.exceptions.InvalidImageLink
31 1
            raise exception from None
32
        except SystemError as exception:
33
            log.warning(exception)
34
            raise self.exceptions.InvalidImageLink from None
35
36
        return image
37