Skip to content

Commit 6ada18b

Browse files
committed
just use os-specific implementation
1 parent 00200d2 commit 6ada18b

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/serializers/test_model_root.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
2+
import os
23
import platform
3-
from pathlib import PosixPath
4+
from pathlib import Path
45
from typing import Any, Union
56

67
import 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

0 commit comments

Comments
 (0)