Add unittest.TestCase.assertMappingEqual
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
Feature or enhancement
Proposal:
unittest.TestCase has assertDictEqual which requires both arguments to be dict's. Would it make sense to add assertMappingEqual which would weaken this requirement to Mapping?
For example, this would be helpful with immutabledict which is not a dict.
Possible implementation (pseudocode) is to change the existing code:
def assertDictEqual(self, d1, d2, msg=None):
# [existing] assert d1 and d2 are dict's
# [existing] check that items are the same
to
def assertMappingEqual(self, d1, d2, msg=None):
# [new] assert d1 and d2 are Mapping's
# [existing] check that items are the same
def assertDictEqual(self, d1, d2, msg=None):
# [existing] assert d1 and d2 are dict's
self.assertMappingEqual(d2, d2, msg)
Considerations and comparison:
-
Alternatively, the checks in
assertDictEqualcould be weakened toMapping, however this might introduce problems into existing tests. -
For sequences, there are
assertListEqualandassertSequenceEqual. HereassertListEqualsimply callsassertSequenceEqualwithout any type checks. -
For sets, there are
assertSetEqualandassertCountEqual. Here the implementations are different.assertSetEqualdoes not check the types of the arguments, but requires them to have the methoddifference.assertCountEqualonly requires the arguments to be iterables. -
It is possible to replace
assertMappingEqual(a, b)withassertDictEqual({**a}, {**b}), however this is arguably ugly.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-121113
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
unittest.TestCase.assertDictEqual エントリーポイントから開始し、リンクされている PR gh-121113 を確認します。独立した assertMappingEqual API が適切かどうかを判断し、既存の辞書の動作を維持します。提案された mapping 比較が Mapping 入力のカバレッジを含めて実装され、既存の動作がそのまま維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100