Skip to content

Commit

Permalink
Fix Python 3.8 tests that were not running in CI
Browse files Browse the repository at this point in the history
In particular:
* Tests: Fix to recognize TypedDict values with extra keys
    - References #19
  • Loading branch information
davidfstr committed Apr 5, 2024
1 parent 986547f commit ca9c161
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ class Point3D(RichTypedDict):
self.assertTryCastSuccess(Point3D, {"x": 1, "y": 1, "z": 1})

def test_typeddict_with_extra_keys(self) -> None:
class Packet(NativeTypedDict):
class Packet(RichTypedDict):
type: str
payload: str

Expand Down Expand Up @@ -1963,11 +1963,13 @@ class TaggedMaybePoint1D(MaybePoint1D):
)
self.assertTryCastSuccess(Point3D, {"x": 1, "y": 2}, strict=False)
self.assertTryCastSuccess(Point3D, {"x": 1}, strict=False) # surprise!
self.assertTryCastFailure(Point3D, {"q": 1}, strict=False)
# NOTE: Unknown keys are allowed
self.assertTryCastSuccess(Point3D, {"q": 1}, strict=False)

self.assertTryCastSuccess(MaybePoint1D, {"x": 1}, strict=False)
self.assertTryCastSuccess(MaybePoint1D, {}, strict=False)
self.assertTryCastFailure(MaybePoint1D, {"q": 1}, strict=False)
# NOTE: Unknown keys are allowed
self.assertTryCastSuccess(MaybePoint1D, {"q": 1}, strict=False)

self.assertTryCastSuccess(
TaggedMaybePoint1D, {"x": 1, "name": "one"}, strict=False
Expand Down

0 comments on commit ca9c161

Please sign in to comment.