Fixed coverage

This commit is contained in:
JRoot Junior 2024-01-27 18:44:14 +02:00
parent e30e89a789
commit 222d48ea09
No known key found for this signature in database
GPG key ID: 738964250D5FF6E2
2 changed files with 6 additions and 20 deletions

View file

@ -106,7 +106,7 @@ class KeyboardBuilder(Generic[ButtonType], ABC):
f"not type {type(row).__name__}"
)
if len(row) > self.max_width:
raise ValueError(f"Row {row!r} is too long (MAX_WIDTH={self.max_width})")
raise ValueError(f"Row {row!r} is too long (max width: {self.max_width})")
self._validate_buttons(*row)
return True
@ -144,14 +144,6 @@ class KeyboardBuilder(Generic[ButtonType], ABC):
raise ValueError(f"Row size {size} are not allowed")
return size
def copy(self: "KeyboardBuilder[ButtonType]") -> "KeyboardBuilder[ButtonType]":
"""
Make full copy of current builder with markup
:return:
"""
return self.__class__(self._button_type, markup=self.export())
def export(self) -> List[List[ButtonType]]:
"""
Export configured markup as list of lists of buttons

View file

@ -78,27 +78,21 @@ class TestKeyboardBuilder:
row=[KeyboardButton(text=f"test {index}") for index in range(count)]
)
def test_validate_markup(self):
def test_validate_markup_invalid_type(self):
builder = ReplyKeyboardBuilder()
with pytest.raises(ValueError):
builder._validate_markup(markup=())
def test_validate_markup_too_many_buttons(self):
builder = ReplyKeyboardBuilder()
with pytest.raises(ValueError):
builder._validate_markup(
markup=[
[KeyboardButton(text=f"{row}.{col}") for col in range(builder.max_width + 5)]
for row in range(5)
[KeyboardButton(text=f"{row}.{col}") for col in range(builder.max_width)]
for row in range(builder.max_buttons)
]
)
assert builder._validate_markup(
markup=[
[KeyboardButton(text=f"{row}.{col}") for col in range(builder.max_width)]
for row in range(5)
]
)
def test_validate_size(self):
builder = ReplyKeyboardBuilder()
with pytest.raises(ValueError):