Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature: Allow min and max values in any checks file to have null value #68

Merged
merged 9 commits into from
Oct 17, 2023
8 changes: 4 additions & 4 deletions chasten/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def check_match_count(
if min_value is not None and max_value is not None:
return is_in_closed_interval(count, min_value, max_value)
# at this point, only one of the values might not be None
# if min_value is not None, then confirm that it is less than or equal
# if min_value is not None, then confirm that it is greater than or equal
if min_value is not None:
if count <= min_value:
if count >= min_value:
return True
# if max_value is not None, then confirm that it is greater than or equal
# if max_value is not None, then confirm that it is less than or equal
if max_value is not None:
if count >= max_value:
if count <= max_value:
return True
# if none of those conditions were true, then the count is not
# between the minimum and the maximum value, inclusively
Expand Down
7 changes: 4 additions & 3 deletions chasten/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import uuid
from datetime import datetime
from pathlib import Path
from typing import List, Union
from typing import List, Optional, Union

from pyastgrep import search as pyastgrepsearch # type: ignore
from pydantic import BaseModel
from pydantic.types import conint

from chasten import debug

Expand Down Expand Up @@ -67,8 +68,8 @@ class Check(BaseModel):
id: str
name: str
description: str = ""
min: Union[None, int] = 0
max: Union[None, int] = 0
min: Optional[conint(ge=0)] = 0 # type: ignore
max: Optional[conint(ge=0)] = 0 # type: ignore
pattern: str
passed: bool
matches: list[Match] = []
Expand Down
32 changes: 28 additions & 4 deletions chasten/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,43 @@
"anyOf": [
{
"type": "object",
"properties": {"min": {"type": "integer"}},
"properties": {
"min": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
}
},
"required": ["min"],
},
{
"type": "object",
"properties": {"max": {"type": "integer"}},
"properties": {
"max": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
}
},
"required": ["max"],
},
{
"type": "object",
"properties": {
"min": {"type": "integer"},
"max": {"type": "integer"},
"min": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
},
"max": {
"anyOf": [
{"type": "integer"},
{"type": "null"},
]
},
},
"required": ["min", "max"],
},
Expand Down
Loading