From f5f9c4c4b882a2f4d1d43c02f77c3321af2662bc Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Mon, 24 Jun 2024 23:22:55 +0100 Subject: [PATCH 1/2] use full type names in errors --- src/errors/validation_exception.rs | 2 +- tests/test_errors.py | 2 +- tests/validators/test_arguments.py | 2 +- tests/validators/test_decimal.py | 10 ++++++---- tests/validators/test_int.py | 4 ++-- tests/validators/test_string.py | 4 +++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/errors/validation_exception.rs b/src/errors/validation_exception.rs index d41a10e65..cb94ca8b7 100644 --- a/src/errors/validation_exception.rs +++ b/src/errors/validation_exception.rs @@ -572,7 +572,7 @@ impl PyLineError { let input_str = safe_repr(input_value); truncate_input_value!(output, &input_str.to_cow()); - if let Ok(type_) = input_value.get_type().qualname() { + if let Ok(type_) = input_value.get_type().fully_qualified_name() { write!(output, ", input_type={type_}")?; } } diff --git a/tests/test_errors.py b/tests/test_errors.py index daabf04c6..7fd5e276b 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -730,7 +730,7 @@ def test_error_on_repr(pydantic_version): assert str(exc_info.value) == ( '1 validation error for int\n' ' Input should be a valid integer ' - '[type=int_type, input_value=, input_type=BadRepr]\n' + '[type=int_type, input_value=, input_type=tests.test_errors.BadRepr]\n' f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/int_type' ) assert exc_info.value.errors(include_url=False) == [ diff --git a/tests/validators/test_arguments.py b/tests/validators/test_arguments.py index 915f05878..51a471ec6 100644 --- a/tests/validators/test_arguments.py +++ b/tests/validators/test_arguments.py @@ -1095,7 +1095,7 @@ def test_error_display(pydantic_version): '1 validation error for arguments\n' 'b\n' ' Missing required argument [type=missing_argument, ' - "input_value=ArgsKwargs((), {'a': 1}), input_type=ArgsKwargs]\n" + "input_value=ArgsKwargs((), {'a': 1}), input_type=pydantic_core._pydantic_core.ArgsKwargs]\n" f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/missing_argument' ) # insert_assert(exc_info.value.json(include_url=False)) diff --git a/tests/validators/test_decimal.py b/tests/validators/test_decimal.py index 931fe6377..a0e204c98 100644 --- a/tests/validators/test_decimal.py +++ b/tests/validators/test_decimal.py @@ -358,7 +358,9 @@ def test_non_finite_json_values(py_and_json: PyAndJson, input_value, allow_inf_n ( Decimal('nan'), False, - Err("Input should be a finite number [type=finite_number, input_value=Decimal('NaN'), input_type=Decimal]"), + Err( + "Input should be a finite number [type=finite_number, input_value=Decimal('NaN'), input_type=decimal.Decimal]" + ), ), ], ) @@ -379,21 +381,21 @@ def test_non_finite_decimal_values(strict, input_value, allow_inf_nan, expected) Decimal('+inf'), False, Err( - "Input should be a finite number [type=finite_number, input_value=Decimal('Infinity'), input_type=Decimal]" + "Input should be a finite number [type=finite_number, input_value=Decimal('Infinity'), input_type=decimal.Decimal]" ), ), ( Decimal('-inf'), True, Err( - "Input should be greater than 0 [type=greater_than, input_value=Decimal('-Infinity'), input_type=Decimal]" + "Input should be greater than 0 [type=greater_than, input_value=Decimal('-Infinity'), input_type=decimal.Decimal]" ), ), ( Decimal('-inf'), False, Err( - "Input should be a finite number [type=finite_number, input_value=Decimal('-Infinity'), input_type=Decimal]" + "Input should be a finite number [type=finite_number, input_value=Decimal('-Infinity'), input_type=decimal.Decimal]" ), ), ], diff --git a/tests/validators/test_int.py b/tests/validators/test_int.py index f93919f17..987b4899a 100644 --- a/tests/validators/test_int.py +++ b/tests/validators/test_int.py @@ -122,7 +122,7 @@ def test_int_py_and_json(py_and_json: PyAndJson, input_value, expected): Decimal('1.001'), Err( 'Input should be a valid integer, got a number with a fractional part ' - "[type=int_from_float, input_value=Decimal('1.001'), input_type=Decimal]" + "[type=int_from_float, input_value=Decimal('1.001'), input_type=decimal.Decimal]" ), id='decimal-remainder', ), @@ -169,7 +169,7 @@ def test_int(input_value, expected): Decimal('1.001'), Err( 'Input should be a valid integer, got a number with a fractional part ' - "[type=int_from_float, input_value=Decimal('1.001'), input_type=Decimal]" + "[type=int_from_float, input_value=Decimal('1.001'), input_type=decimal.Decimal]" ), id='decimal-remainder', ), diff --git a/tests/validators/test_string.py b/tests/validators/test_string.py index 75edcc1b0..05d81b6f3 100644 --- a/tests/validators/test_string.py +++ b/tests/validators/test_string.py @@ -50,7 +50,9 @@ def test_str(py_and_json: PyAndJson, input_value, expected): (123, Err('Input should be a valid string [type=string_type, input_value=123, input_type=int]')), ( Decimal('123'), - Err("Input should be a valid string [type=string_type, input_value=Decimal('123'), input_type=Decimal]"), + Err( + "Input should be a valid string [type=string_type, input_value=Decimal('123'), input_type=decimal.Decimal]" + ), ), ], ) From 9abbdfa75863c62b52c866d3ade13a5226f94fe9 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 25 Jun 2024 10:02:39 +0100 Subject: [PATCH 2/2] rename wasm test dir to tests --- tests/emscripten_runner.js | 6 +++--- wasm-preview/worker.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/emscripten_runner.js b/tests/emscripten_runner.js index c3c53834e..c29760b74 100644 --- a/tests/emscripten_runner.js +++ b/tests/emscripten_runner.js @@ -83,9 +83,9 @@ async function main() { const pyodide = await loadPyodide(); const FS = pyodide.FS; setupStreams(FS, pyodide._module.TTY); - FS.mkdir('/test_dir'); - FS.mount(FS.filesystems.NODEFS, {root: path.join(root_dir, 'tests')}, '/test_dir'); - FS.chdir('/test_dir'); + FS.mkdir('/tests'); + FS.mount(FS.filesystems.NODEFS, {root: path.join(root_dir, 'tests')}, '/tests'); + FS.chdir('/tests'); await pyodide.loadPackage(['micropip', 'pytest']); // language=python errcode = await pyodide.runPythonAsync(` diff --git a/wasm-preview/worker.js b/wasm-preview/worker.js index c6223ecbd..6a4e67391 100644 --- a/wasm-preview/worker.js +++ b/wasm-preview/worker.js @@ -95,8 +95,8 @@ async function main() { const pyodide = await loadPyodide(); const {FS} = pyodide; setupStreams(FS, pyodide._module.TTY); - FS.mkdir('/test_dir'); - FS.chdir('/test_dir'); + FS.mkdir('/tests'); + FS.chdir('/tests'); await pyodide.loadPackage(['micropip', 'pytest', 'numpy']); if (pydantic_core_version < '2.0.0') await pyodide.loadPackage(['typing-extensions']); await pyodide.runPythonAsync(python_code, {globals: pyodide.toPy({pydantic_core_version, tests_zip})});