Skip to content

Commit ce843ed

Browse files
committed
fix tests + get things working with validate_by_name
1 parent 8598f3e commit ce843ed

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/validators/arguments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ahash::AHashSet;
88
use pyo3::IntoPyObjectExt;
99

1010
use crate::build_tools::py_schema_err;
11-
use crate::build_tools::ExtraBehavior;
11+
use crate::build_tools::{schema_or_config_same, ExtraBehavior};
1212
use crate::errors::{ErrorTypeDefaults, ValError, ValLineError, ValResult};
1313
use crate::input::{Arguments, BorrowInput, Input, KeywordArgs, PositionalArgs, ValidationMatch};
1414
use crate::lookup_key::LookupKey;
@@ -68,7 +68,7 @@ impl BuildValidator for ArgumentsValidator {
6868
) -> PyResult<CombinedValidator> {
6969
let py = schema.py();
7070

71-
let validate_by_name = config.get_as(intern!(py, "validate_by_name"))?.unwrap_or(false);
71+
let validate_by_name = schema_or_config_same(schema, config, intern!(py, "validate_by_name"))?.unwrap_or(false);
7272

7373
let arguments_schema: Bound<'_, PyList> = schema.get_as_req(intern!(py, "arguments_schema"))?;
7474
let mut parameters: Vec<Parameter> = Vec::with_capacity(arguments_schema.len());

tests/validators/test_typed_dict.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ def test_alias_allow_pop(py_and_json: PyAndJson):
396396
'fields': {
397397
'field_a': {'validation_alias': 'FieldA', 'type': 'typed-dict-field', 'schema': {'type': 'int'}}
398398
},
399+
'config': {'validate_by_name': True},
399400
},
400-
config=CoreConfig(validate_by_name=True),
401401
)
402402
assert v.validate_test({'FieldA': '123'}) == {'field_a': 123}
403403
assert v.validate_test({'field_a': '123'}) == {'field_a': 123}
@@ -590,8 +590,8 @@ def test_paths_allow_by_name(py_and_json: PyAndJson, input_value):
590590
'schema': {'type': 'int'},
591591
}
592592
},
593+
'config': {'validate_by_name': True},
593594
},
594-
config=CoreConfig(validate_by_name=True),
595595
)
596596
assert v.validate_test(input_value) == {'field_a': 42}
597597

@@ -798,8 +798,8 @@ def test_alias_extra_by_name(py_and_json: PyAndJson):
798798
'fields': {
799799
'field_a': {'validation_alias': 'FieldA', 'type': 'typed-dict-field', 'schema': {'type': 'int'}}
800800
},
801+
'config': {'validate_by_name': True},
801802
},
802-
config=CoreConfig(validate_by_name=True),
803803
)
804804
assert v.validate_test({'FieldA': 1}) == {'field_a': 1}
805805
assert v.validate_test({'field_a': 1}) == {'field_a': 1}

0 commit comments

Comments
 (0)