From 682f54c46fe2751d1802b53851f54fa971e6524b Mon Sep 17 00:00:00 2001 From: Simon Jones Date: Thu, 21 Sep 2023 20:54:26 -0400 Subject: [PATCH 1/5] fix: comparing min/max when one is Nonetype is switched --- chasten/checks.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chasten/checks.py b/chasten/checks.py index 4b3e5de0..6e1d2b54 100644 --- a/chasten/checks.py +++ b/chasten/checks.py @@ -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 From 6f080841cec5b040041fcc0c3b89fb7515bfe976 Mon Sep 17 00:00:00 2001 From: Simon Jones Date: Thu, 21 Sep 2023 20:55:14 -0400 Subject: [PATCH 2/5] feat: updating jsonschema validation to allow null for min and max --- chasten/validate.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/chasten/validate.py b/chasten/validate.py index f393df64..41f4d739 100644 --- a/chasten/validate.py +++ b/chasten/validate.py @@ -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"], }, From 96fddd481a77ea8908587915fdf34532f6b28545 Mon Sep 17 00:00:00 2001 From: Simon Jones Date: Thu, 21 Sep 2023 20:57:30 -0400 Subject: [PATCH 3/5] feat: pydantic BaseModel allows nullable integers greater than zero this also uses the pydantic conint type to constrain the min and max values to be greater than or equal to zero, as there is no need to have a check count be negative. --- chasten/results.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/chasten/results.py b/chasten/results.py index fd6eecad..6a005e75 100644 --- a/chasten/results.py +++ b/chasten/results.py @@ -3,10 +3,11 @@ import uuid from datetime import datetime from pathlib import Path -from typing import List, Union +from typing import List, Union, Optional from pyastgrep import search as pyastgrepsearch # type: ignore from pydantic import BaseModel +from pydantic.types import conint from chasten import debug @@ -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 + max: Optional[conint(ge=0)] = 0 pattern: str passed: bool matches: list[Match] = [] From c5849e4c6c95b39a47776bf67384729bd317a831 Mon Sep 17 00:00:00 2001 From: Simon Jones Date: Thu, 21 Sep 2023 21:10:36 -0400 Subject: [PATCH 4/5] fix: ignore type of pydantic `conint` to pass linter check --- chasten/results.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chasten/results.py b/chasten/results.py index 6a005e75..78331fbe 100644 --- a/chasten/results.py +++ b/chasten/results.py @@ -68,8 +68,8 @@ class Check(BaseModel): id: str name: str description: str = "" - min: Optional[conint(ge=0)] = 0 - max: Optional[conint(ge=0)] = 0 + min: Optional[conint(ge=0)] = 0 # type: ignore + max: Optional[conint(ge=0)] = 0 # type: ignore pattern: str passed: bool matches: list[Match] = [] From cd16005e09cb7fe1e636e45218a44dbcbfe1dff8 Mon Sep 17 00:00:00 2001 From: Simon Jones Date: Thu, 21 Sep 2023 21:40:58 -0400 Subject: [PATCH 5/5] fix: reformatting --- chasten/results.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chasten/results.py b/chasten/results.py index 78331fbe..a7effeb0 100644 --- a/chasten/results.py +++ b/chasten/results.py @@ -68,8 +68,8 @@ class Check(BaseModel): id: str name: str description: str = "" - min: Optional[conint(ge=0)] = 0 # type: ignore - max: Optional[conint(ge=0)] = 0 # type: ignore + min: Optional[conint(ge=0)] = 0 # type: ignore + max: Optional[conint(ge=0)] = 0 # type: ignore pattern: str passed: bool matches: list[Match] = []