Skip to content

Commit

Permalink
Merge pull request #672 from Andrew-S-Rosen/patch-6
Browse files Browse the repository at this point in the history
Add another regression test for `recursive_msonable` behavior
  • Loading branch information
shyuep committed May 14, 2024
2 parents e1bc24a + f21e7ee commit a8d4b3a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
except ImportError:
torch = None

try:
import pydantic
except ImportError:
pydantic = None

try:
from bson.objectid import ObjectId
except ImportError:
Expand Down Expand Up @@ -737,6 +742,23 @@ def test_jsanitize(self):
clean_recursive_msonable = jsanitize(d, recursive_msonable=True)
assert clean_recursive_msonable["hello"]["a"] == 1
assert clean_recursive_msonable["hello"]["b"] == 2
assert clean_recursive_msonable["hello"]["c"] == 3
assert clean_recursive_msonable["test"] == "hi"

d = {"hello": [GoodMSONClass(1, 2, 3), "test"], "test": "hi"}
clean_recursive_msonable = jsanitize(d, recursive_msonable=True)
assert clean_recursive_msonable["hello"][0]["a"] == 1
assert clean_recursive_msonable["hello"][0]["b"] == 2
assert clean_recursive_msonable["hello"][0]["c"] == 3
assert clean_recursive_msonable["hello"][1] == "test"
assert clean_recursive_msonable["test"] == "hi"

d = {"hello": (GoodMSONClass(1, 2, 3), "test"), "test": "hi"}
clean_recursive_msonable = jsanitize(d, recursive_msonable=True)
assert clean_recursive_msonable["hello"][0]["a"] == 1
assert clean_recursive_msonable["hello"][0]["b"] == 2
assert clean_recursive_msonable["hello"][0]["c"] == 3
assert clean_recursive_msonable["hello"][1] == "test"
assert clean_recursive_msonable["test"] == "hi"

d = {"dt": datetime.datetime.now()}
Expand Down Expand Up @@ -866,6 +888,7 @@ def test_redirect_settings_file(self):
}
}

@pytest.mark.skipif(pydantic is None, reason="pydantic not present")
def test_pydantic_integrations(self):
from pydantic import BaseModel, ValidationError

Expand Down

0 comments on commit a8d4b3a

Please sign in to comment.