Skip to content

Commit

Permalink
Erroneous whitespace fix
Browse files Browse the repository at this point in the history
  • Loading branch information
noamgat committed May 4, 2024
1 parent 32b50cb commit 31c851f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lmformatenforcer/characterlevelparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Hashable, List, Optional, TypeVar
from .consts import (COMPLETE_ALPHABET, WHITESPACE_CHARACTERS, DEFAULT_MAX_CONSECUTIVE_WHITESPACES,
DEFAULT_FORCE_JSON_FIELD_ORDER, CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES,
CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER )
CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER)


def _parse_bool(s: str) -> bool:
Expand All @@ -25,7 +25,7 @@ class CharacterLevelParserConfig:
max_consecutive_whitespaces: int = _env_or_default_field(CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES,
DEFAULT_MAX_CONSECUTIVE_WHITESPACES)
"""How many consective whitespaces the JsonSchemaParser will allow"""
force_json_field_order: bool = _env_or_default_field(CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER ,
force_json_field_order: bool = _env_or_default_field(CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER,
DEFAULT_FORCE_JSON_FIELD_ORDER)
"""Whether the JsonSchemaParser will force fields to appear in the
order of the 'required' field in the schema"""
Expand Down
2 changes: 1 addition & 1 deletion lmformatenforcer/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"""Environment variable for externally controlling how many consective whitespaces the
JsonSchemaParser will allow. Default: 12"""

CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER = 'LMFE_STRICT_JSON_FIELD_ORDER '
CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER = 'LMFE_STRICT_JSON_FIELD_ORDER'
"""Environment variable for externally controlling whether the JsonSchemaParser will force
fields to appear in the order of the 'required' field in the schema. Default: false"""
4 changes: 2 additions & 2 deletions tests/test_jsonschemaparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from lmformatenforcer import JsonSchemaParser
from enum import Enum
import pytest
from lmformatenforcer.consts import BACKSLASH, BACKSLASH_ESCAPING_CHARACTERS, CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER , CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES
from lmformatenforcer.consts import BACKSLASH, BACKSLASH_ESCAPING_CHARACTERS, CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER, CONFIG_ENV_VAR_MAX_CONSECUTIVE_WHITESPACES

from .common import assert_parser_with_string, CharacterNotAllowedException

Expand Down Expand Up @@ -525,7 +525,7 @@ class TwoRequiredModel(BaseModel):
b: str
c: int = 1
schema = TwoRequiredModel.model_json_schema()
env_var_name = CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER
env_var_name = CONFIG_ENV_VAR_STRICT_JSON_FIELD_ORDER
with _temp_replace_env_var(env_var_name, None):
# Check that the default is false
_test_json_schema_parsing_with_string('{"b": "X", "a": 1}', schema, True)
Expand Down

0 comments on commit 31c851f

Please sign in to comment.