mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-21 19:32:13 +08:00
Add tests for TestCase.assertDictEqual() (#11154)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from collections.abc import Iterator, Mapping
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
from fractions import Fraction
|
||||
from typing_extensions import assert_type
|
||||
from typing_extensions import TypedDict, assert_type
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
case = unittest.TestCase()
|
||||
@@ -89,6 +90,54 @@ case.assertGreater(Spam(), Eggs()) # type: ignore
|
||||
case.assertGreater(Ham(), Bacon()) # type: ignore
|
||||
case.assertGreater(Bacon(), Ham()) # type: ignore
|
||||
|
||||
|
||||
###
|
||||
# Tests for assertDictEqual
|
||||
###
|
||||
|
||||
|
||||
class TD1(TypedDict):
|
||||
x: int
|
||||
y: str
|
||||
|
||||
|
||||
class TD2(TypedDict):
|
||||
a: bool
|
||||
b: bool
|
||||
|
||||
|
||||
class MyMapping(Mapping[str, int]):
|
||||
def __getitem__(self, __key: str) -> int:
|
||||
return 42
|
||||
|
||||
def __iter__(self) -> Iterator[str]:
|
||||
return iter([])
|
||||
|
||||
def __len__(self) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
td1: TD1 = {"x": 1, "y": "foo"}
|
||||
td2: TD2 = {"a": True, "b": False}
|
||||
m = MyMapping()
|
||||
|
||||
case.assertDictEqual({}, {})
|
||||
case.assertDictEqual({"x": 1, "y": 2}, {"x": 1, "y": 2})
|
||||
case.assertDictEqual({"x": 1, "y": "foo"}, {"y": "foo", "x": 1})
|
||||
case.assertDictEqual({"x": 1}, {})
|
||||
case.assertDictEqual({}, {"x": 1})
|
||||
case.assertDictEqual({1: "x"}, {"y": 222})
|
||||
case.assertDictEqual({1: "x"}, td1)
|
||||
case.assertDictEqual(td1, {1: "x"})
|
||||
case.assertDictEqual(td1, td2)
|
||||
|
||||
case.assertDictEqual(1, {}) # type: ignore
|
||||
case.assertDictEqual({}, 1) # type: ignore
|
||||
|
||||
# These should fail, but don't due to TypedDict limitations:
|
||||
# case.assertDictEqual(m, {"": 0}) # xtype: ignore
|
||||
# case.assertDictEqual({"": 0}, m) # xtype: ignore
|
||||
|
||||
###
|
||||
# Tests for mock.patch
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user