Add unittest.TestCase.assertMappingEqual
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo ponto de entrada unittest.TestCase.assertDictEqual e analise o PR vinculado gh-121113. Determine se uma API assertMappingEqual separada é apropriada e preserve o comportamento existente dos dicionários; considera-se concluído quando a comparação de mappings proposta estiver implementada com cobertura para entradas Mapping e o comportamento existente permanecer intacto.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- testing
- Tipo de issue
- Funcionalidade
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 25/100