Add unittest.TestCase.assertMappingEqual
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Parte del punto de entrada unittest.TestCase.assertDictEqual y revisa el PR vinculado gh-121113. Determina si es apropiada una API assertMappingEqual independiente y conserva el comportamiento existente de los diccionarios; se considera terminado cuando la comparación de mappings propuesta está implementada con cobertura para entradas Mapping y el comportamiento existente permanece intacto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- testing
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100