Skip to content

Commit

Permalink
Update model tests (#2528)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Apr 17, 2024
1 parent 593b7b2 commit 0d48590
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import decimal
import json
import datetime
from pathlib import Path
from typing import Any, Iterable, List, Literal, Dict, Mapping, Sequence, Set, Tuple, Optional, overload, Union
import pytest
import isodate
Expand Down Expand Up @@ -3968,3 +3969,32 @@ class ModelWithEnumProperty(Model):
model = ModelWithEnumProperty({"enumProperty": MyEnum.A})
assert model.enum_property == MyEnum.A
assert model["enumProperty"] == "a"

def test_not_mutating_original_dict():
class MyInnerModel(Model):
property: str = rest_field()

class MyModel(Model):
property: MyInnerModel = rest_field()

origin = {"property": {"property": "hello"}}

dpg_model = MyModel(origin)
assert dpg_model["property"]["property"] == "hello"

origin["property"]["property"] = "world"
assert dpg_model["property"]["property"] == "hello"

def test_model_init_io():
class BytesModel(Model):
property: bytes = rest_field()

JPG = Path(__file__).parent.parent / "data/image.jpg"
with open(JPG, "rb") as f:
b = BytesModel({"property": f})
assert b.property == f
assert b["property"] == f
with open(JPG, "rb") as f:
b = BytesModel(property=f)
assert b.property == f
assert b["property"] == f

This file was deleted.

0 comments on commit 0d48590

Please sign in to comment.