Add unittest.TestCase.assertMappingEqual
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le point d’entrée unittest.TestCase.assertDictEqual et examinez la PR liée gh-121113. Déterminez si une API assertMappingEqual distincte est appropriée et préservez le comportement existant des dictionnaires ; le travail est terminé lorsque la comparaison de mappings proposée est implémentée avec une couverture des entrées Mapping et que le comportement existant reste intact.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- testing
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100