Passed
Push — master ( a8cf2f...4ab9d5 )
by torrua
02:00 queued 12s
created

keyboa.button_check   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 47
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ButtonCheck.is_callback_proper_type() 0 8 2
A ButtonCheck.is_button_data_proper_type() 0 10 2
A ButtonCheck.is_callback_data_in_limits() 0 8 2
1
# -*- coding:utf-8 -*-
2 1
"""
3
This module contains all checks for Keyboa Button class parameters
4
"""
5
# pylint: disable = C0116
6
7 1
from keyboa.constants import (
8
    InlineKeyboardButton,
9
    InlineButtonData,
10
    callback_data_types,
11
    MAXIMUM_CBD_LENGTH,
12
)
13
14
15 1
class ButtonCheck:
16
    """
17
    This class contains all checks for Keyboa Button class parameters
18
    """
19 1
    @staticmethod
20 1
    def is_button_data_proper_type(button_data) -> None:
21 1
        if not isinstance(button_data, (tuple, dict, str, int)):
22 1
            type_error_message = (
23
                "Cannot create %s from %s. Please use %s instead.\n"
24
                "Probably you specified 'auto_alignment' or 'items_in_line' "
25
                "parameter for StructuredSequence."
26
                % (InlineKeyboardButton, type(button_data), InlineButtonData)
27
            )
28 1
            raise TypeError(type_error_message)
29
30 1
    @staticmethod
31 1
    def is_callback_proper_type(callback) -> None:
32 1
        if not isinstance(callback, callback_data_types):
33 1
            type_error_message = "Callback cannot be %s. Only %s allowed." % (
34
                type(callback),
35
                callback_data_types,
36
            )
37 1
            raise TypeError(type_error_message)
38
39 1
    @staticmethod
40 1
    def is_callback_data_in_limits(callback_data) -> None:
41 1
        if len(callback_data.encode()) > MAXIMUM_CBD_LENGTH:
42 1
            size_error_message = (
43
                "The callback data cannot be more than "
44
                "64 bytes for one button. Your size is %s" % len(callback_data.encode())
45
            )
46
            raise ValueError(size_error_message)
47