Skip to content

Commit

Permalink
fix(integer validator): check not a number for failure description (#…
Browse files Browse the repository at this point in the history
…4414)

* add failing test

* add not a number to describe failures

* update changelog

---------

Co-authored-by: Darren Burns <[email protected]>
  • Loading branch information
TomJGooding and darrenburns authored Apr 16, 2024
1 parent 8320d07 commit dd36d6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed `Integer` validator missing failure description when not a number https://github.com/Textualize/textual/issues/4413
- Fixed a crash in `DataTable` if you clicked a link in the border https://github.com/Textualize/textual/issues/4410

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/textual/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def describe_failure(self, failure: Failure) -> str | None:
Returns:
A string description of the failure.
"""
if isinstance(failure, Integer.NotAnInteger):
if isinstance(failure, (Integer.NotANumber, Integer.NotAnInteger)):
return "Must be a valid integer."
elif isinstance(failure, Integer.NotInRange):
if self.minimum is None and self.maximum is not None:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,11 @@ def test_Function_validate(function, failure_description, is_valid):
assert result.is_valid is is_valid
if result.failure_descriptions:
assert result.failure_descriptions[0] == failure_description


def test_Integer_failure_description_when_NotANumber():
"""Regression test for https://github.com/Textualize/textual/issues/4413"""
validator = Integer()
result = validator.validate("x")
assert result.is_valid is False
assert result.failure_descriptions[0] == "Must be a valid integer."

0 comments on commit dd36d6f

Please sign in to comment.