-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: constraints with a Falsy value should still return a truthful ha…
…s_constraints (#1844)
- Loading branch information
1 parent
2d0f900
commit ab4a39c
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Optional, Union | ||
|
||
import pytest | ||
|
||
from datamodel_code_generator.model.pydantic.base_model import Constraints | ||
from datamodel_code_generator.types import UnionIntFloat | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'gt,expected', | ||
[ | ||
(None, False), | ||
(4, True), | ||
(0, True), | ||
(0.0, True), | ||
], | ||
) | ||
def test_constraint(gt: Optional[Union[int, float]], expected: bool) -> None: | ||
constraints = Constraints() | ||
constraints.gt = UnionIntFloat(gt) if gt is not None else None | ||
assert constraints.has_constraints == expected |