python / python/cpython

Add unittest.TestCase.assertMappingEqual

Đang mở
#121,104 0 bình luận 3 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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:

  1. Alternatively, the checks in assertDictEqual could be weakened to Mapping, however this might introduce problems into existing tests.

  2. For sequences, there are assertListEqual and assertSequenceEqual. Here assertListEqual simply calls assertSequenceEqual without any type checks.

  3. For sets, there are assertSetEqual and assertCountEqual. Here the implementations are different. assertSetEqual does not check the types of the arguments, but requires them to have the method difference. assertCountEqual only requires the arguments to be iterables.

  4. It is possible to replace assertMappingEqual(a, b) with assertDictEqual({**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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ entry point unittest.TestCase.assertDictEqual và xem xét PR được liên kết gh-121113. Xác định xem một API assertMappingEqual riêng có phù hợp hay không và giữ nguyên hành vi hiện tại của dictionary; hoàn tất khi phép so sánh mapping được đề xuất đã được triển khai với độ bao phủ cho các đầu vào Mapping và hành vi hiện tại vẫn được giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
testing
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.