Passed
Push — main ( 853695...d18ab9 )
by Máté
03:41 queued 02:14
created

illustration.Illustration.__str__()   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 3
nop 1
1
from pathlib import Path
2
import re
3
4
# noinspection PyPackages
5
from .state_of_illustrations import StateOfIllustrations  # type: ignore
6
7
8
def remove_wiki_unsafe_characters(upload_filename):
9
    upload_filename = re.sub(r"[{\[]", "(", upload_filename)
10
    upload_filename = re.sub(r"[}\]]", ")", upload_filename)
11
    return upload_filename
12
13
14
class Illustration:
15
    def __init__(
16
        self,
17
        upload_filename: str,
18
        size_in_pixels: int,
19
        state_of_illustrations: StateOfIllustrations,
20
        original_file_path: Path | None = None,
21
    ) -> None:
22
        assert isinstance(upload_filename, str)
23
        upload_filename = remove_wiki_unsafe_characters(upload_filename)
24
        self.upload_filename = upload_filename
25
26
        assert isinstance(size_in_pixels, int)
27
        self.size_in_pixels = size_in_pixels
28
29
        assert isinstance(state_of_illustrations, StateOfIllustrations)
30
        self.state_of_illustrations = state_of_illustrations
31
32
        if original_file_path:
33
            assert isinstance(original_file_path, Path)
34
        self.original_file_path = original_file_path
35
36
    def __str__(self) -> str:
37
        if (
38
            self.state_of_illustrations == StateOfIllustrations.YesAndAvailable
39
            or self.state_of_illustrations == StateOfIllustrations.YesButUnavailable
40
        ):
41
            return f"\n[[Fájl:{self.upload_filename}|keret|keretnélküli|{self.size_in_pixels}px]]"
42
        else:
43
            raise ValueError(
44
                "No images were expected in the quiz but one image filename was requested!"
45
            )
46