File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change 11import json
2+ import os
23import platform
3- from pathlib import PosixPath
4+ from pathlib import Path
45from typing import Any , Union
56
67import pytest
@@ -196,11 +197,21 @@ class RootModel:
196197 assert s .to_python (v ) == '123'
197198 assert s .to_json (v ) == b'"123"'
198199
200+ # Path is chosen because it has a .root property
201+ # which could look like a root model in bad implementations
202+
203+ if os .name == 'nt' :
204+ path_value = Path ('C:\\ a\\ b' )
205+ path_bytes = b'"C:\\ a\\ b"'
206+ else :
207+ path_value = Path ('/a/b' )
208+ path_bytes = b'"/a/b"'
209+
199210 with pytest .warns (UserWarning , match = r'PydanticSerializationUnexpectedValue\(Expected `RootModel`' ):
200- assert s .to_python (PosixPath ( '/a/b' )) == PosixPath ( '/a/b' )
211+ assert s .to_python (path_value ) == path_value
201212
202213 with pytest .warns (UserWarning , match = r'PydanticSerializationUnexpectedValue\(Expected `RootModel`' ):
203- assert s .to_json (PosixPath ( '/a/b' )) == b'"/a/b"'
214+ assert s .to_json (path_value ) == path_bytes
204215
205- assert s .to_python (PosixPath ( '/a/b' ) , warnings = False ) == PosixPath ( '/a/b' )
206- assert s .to_json (PosixPath ( '/a/b' ) , warnings = False ) == b'"/a/b"'
216+ assert s .to_python (path_value , warnings = False ) == path_value
217+ assert s .to_json (path_value , warnings = False ) == path_bytes
You can’t perform that action at this time.
0 commit comments