Skip to content

Commit

Permalink
Merge pull request AstuteSource#68 from simojo/feat/nullable-check-co…
Browse files Browse the repository at this point in the history
…unts

WIP: Feature: Allow `min` and `max` values in any checks file to have `null` value
  • Loading branch information
laurennevill authored Oct 17, 2023
2 parents d6631d9 + fefd211 commit f345eaa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
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

0 comments on commit f345eaa

Please sign in to comment.