Passed
Push — master ( 812d55...611d69 )
by torrua
02:04
created

test_keyboard_pre_check   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 92
rs 10
c 0
b 0
f 0
wmc 13
1
# -*- coding:utf-8 -*-
2
"""
3
Test for keyboard_pre_check() function
4
"""
5
import os
6
import sys
7
8
sys.path.insert(0, "%s/../" % os.path.dirname(os.path.abspath(__file__)))
9
10
import pytest
11
from keyboa.keyboards import _keyboa_pre_check
12
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
13
14
15
def test_precheck_with_nothing():
16
    assert _keyboa_pre_check(items=None) is None
17
18
19
def test_precheck_with_no_list():
20
    assert _keyboa_pre_check(items=1) is None
21
22
23
def test_acceptable_number_of_passed_elements():
24
    """
25
26
    :return:
27
    """
28
    assert _keyboa_pre_check(items=list(range(99))) is None
29
30
    with pytest.raises(Exception) as _:
31
        _keyboa_pre_check(items=list(range(101)))
32
33
34
def test_acceptable_number_of_nested_elements():
35
    """
36
37
    :return:
38
    """
39
    range_105 = [list(range(0, 7)) for i in range(0, 15)]
40
41
    with pytest.raises(Exception) as _:
42
        _keyboa_pre_check(items=range_105)
43
44
45
@pytest.mark.parametrize("number_in_line", (0, 9))
46
def test_unacceptable_number_in_line(number_in_line):
47
    """
48
49
    :param number_in_line:
50
    :return:
51
    """
52
    with pytest.raises(Exception) as _:
53
        _keyboa_pre_check(items=list(range(50)), items_in_row=number_in_line)
54
55
56
@pytest.mark.parametrize("number_in_line", (1, 8, None))
57
def test_acceptable_number_in_line(number_in_line):
58
    """
59
60
    :param number_in_line:
61
    :return:
62
    """
63
    assert (
64
        _keyboa_pre_check(items=list(range(50)), items_in_row=number_in_line)
65
        is None
66
    )
67
68
69
def test_count_items_with_existing_keyboard():
70
    """
71
72
    :return:
73
    """
74
    existing_keyboard = InlineKeyboardMarkup().row(
75
        *[
76
            InlineKeyboardButton(**{"text": item, "callback_data": item})
77
            for item in list(range(8))
78
        ]
79
    )
80
81
    with pytest.raises(Exception) as _:
82
        _keyboa_pre_check(items=list(range(99)), keyboard=existing_keyboard)
83
84
85
def test_unacceptable_add_to_keyboard_variable_type():
86
    """
87
88
    :return:
89
    """
90
    with pytest.raises(Exception) as _:
91
        _keyboa_pre_check(items=list(range(99)), keyboard="not a keyboard")
92