From 1d3d8b2bebd8f7010d832aa23346465b56e7cb07 Mon Sep 17 00:00:00 2001 From: Fabrice Depaulis Date: Thu, 10 Dec 2015 16:32:01 +0100 Subject: [PATCH] Root ignored field not taken into account --- pydeepdiff/__init__.py | 2 +- pydeepdiff/diff.py | 18 ++--- test/test_get_true_diff.py | 137 +++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 test/test_get_true_diff.py diff --git a/pydeepdiff/__init__.py b/pydeepdiff/__init__.py index 9582426..391c23f 100644 --- a/pydeepdiff/__init__.py +++ b/pydeepdiff/__init__.py @@ -63,4 +63,4 @@ ] """ -__version__ = "1.0.0" +__version__ = "1.0.1" diff --git a/pydeepdiff/diff.py b/pydeepdiff/diff.py index 4815a9a..688bdb2 100644 --- a/pydeepdiff/diff.py +++ b/pydeepdiff/diff.py @@ -118,20 +118,22 @@ def _get_dictionary_diff(p_ldic, p_rdic, p_path="", p_mapping=[], p_ignored_fiel # As the diff is on "key" field, we add it to the path current_path = _add_field_to_path(p_path, key) no_idx_path = _get_path_without_indexes(current_path) - diff = {'path_to_object': current_path, 'kind': 'N', 'filter': no_idx_path} - if p_complex_details: - diff['rhs'] = p_ldic[key] - current_diffs.append(diff) + if no_idx_path not in p_ignored_fields: + diff = {'path_to_object': current_path, 'kind': 'N', 'filter': no_idx_path} + if p_complex_details: + diff['rhs'] = p_ldic[key] + current_diffs.append(diff) # Deletions for key in (p_rdic.keys() - intersect): # As the diff is on "key" field, we add it to the path current_path = _add_field_to_path(p_path, key) no_idx_path = _get_path_without_indexes(current_path) - diff = {'path_to_object': current_path, 'kind': 'D', 'filter': no_idx_path} - if p_complex_details: - diff['lhs'] = p_rdic[key] - current_diffs.append(diff) + if no_idx_path not in p_ignored_fields: + diff = {'path_to_object': current_path, 'kind': 'D', 'filter': no_idx_path} + if p_complex_details: + diff['lhs'] = p_rdic[key] + current_diffs.append(diff) # Changes for key in intersect: diff --git a/test/test_get_true_diff.py b/test/test_get_true_diff.py new file mode 100644 index 0000000..9e74af2 --- /dev/null +++ b/test/test_get_true_diff.py @@ -0,0 +1,137 @@ +""" + Test of get_diff function +""" + +from pydeepdiff.diff import get_diff + + +def test_empty_diff(): + a = { + 'blocs_reponses': [{ + 'activites_affichage_immediat': [{ + 'machine_learning_source': 'rr', + 'ordre': 1, + 'rubriques': [{ + 'code_an9': '54053000', + 'libelle_rubrique': 'restaurants', + 'code_an8': '693780' + }, { + 'code_an9': '00000706', + 'libelle_rubrique': 'restaurants asiatiques', + 'code_an8': '000706' + }], + 'type_bloc_activite': 'IMMEDIAT', + 'identifications_bloc_reponse_activite': [{ + 'origine_bloc_reponse': 'MANUEL', + 'identifiant_bloc_reponse': '130749' + }], + 'libelle': 'RESTAURANTS THAÏLANDAIS', + 'correction': False, + 'identifiant': 'ac1_2', + 'machine_learning_etat': 'valide', + 'forme_canonique': 'restaurant thaïlandais', + 'expressions': [{ + 'rubriques': [{ + 'code_an9': '54053000', + 'libelle_rubrique': '', + 'code_an8': '693780' + }, { + 'code_an9': '00000706', + 'libelle_rubrique': '', + 'code_an8': '000706' + }], + 'rubriques_fines': [{ + 'code_an9': '00000796', + 'libelle_rubrique': '', + 'code_an8': '000796' + }], + 'formes_brutes': ['restaurant', 'thaïlandais'], + 'type_crc': 'C', + 'chaine_saisie': 'restaurant thaïlandais', + 'type_expression': 'RESTRICTION_FAIBLE', + 'libelle': 'thaïlandaise', + 'code': 'ObjetCrc_restaurant thaïlandais_5825-693780-50693780-000706-789300-789350-680700_Principale', + 'formes_normales': ['RESTAURANT :: THAILANDAIS'] + }], + 'suggestion_editoriale': False, + 'scoring_qui_quoi': 'FORT' + }], + 'type_interpretation': 'QUOI', + 'identifiant_de_bloc': 'ac1' + }], + 'id': 'restaurant thaïlandais', + 'ambiguite': True, + 'creation_date': '2015-12-10T15:04:08.046092+00:00', + 'user': 'fabio', + 'status': 'OK', + 'mots_signifiants': ['restaurant', 'thaïlandais'] + } + + b = { + 'auto_state': { + 'user': None, + 'comments': [], + 'status': None + }, + 'id': 'restaurant thaïlandais', + 'ambiguite': True, + 'creation_date': '2015-12-10T15:04:28.028229+00:00', + 'blocs_reponses': [{ + 'activites_affichage_immediat': [{ + 'machine_learning_source': 'rr', + 'ordre': 1, + 'rubriques': [{ + 'code_an9': '54053000', + 'libelle_rubrique': 'restaurants', + 'code_an8': '693780' + }, { + 'code_an9': '00000706', + 'libelle_rubrique': 'restaurants asiatiques', + 'code_an8': '000706' + }], + 'type_bloc_activite': 'IMMEDIAT', + 'identifications_bloc_reponse_activite': [{ + 'origine_bloc_reponse': 'MANUEL', + 'identifiant_bloc_reponse': '130749' + }], + 'libelle': 'RESTAURANTS THAÏLANDAIS', + 'correction': False, + 'identifiant': 'ac1_2', + 'machine_learning_etat': 'valide', + 'forme_canonique': 'restaurant thaïlandais', + 'expressions': [{ + 'formes_normales': ['RESTAURANT :: THAILANDAIS'], + 'rubriques': [{ + 'code_an9': '54053000', + 'libelle_rubrique': '', + 'code_an8': '693780' + }, { + 'code_an9': '00000706', + 'libelle_rubrique': '', + 'code_an8': '000706' + }], + 'rubriques_fines': [{ + 'code_an9': '00000796', + 'libelle_rubrique': '', + 'code_an8': '000796' + }], + 'formes_brutes': ['restaurant', 'thaïlandais'], + 'type_crc': 'C', + 'type_expression': 'RESTRICTION_FAIBLE', + 'libelle': 'thaïlandaise', + 'code': 'ObjetCrc_restaurant thaïlandais_5825-693780-50693780-000706-789300-789350-680700_Principale', + 'chaine_saisie': 'restaurant thaïlandais' + }], + 'suggestion_editoriale': False, + 'scoring_qui_quoi': 'FORT' + }], + 'type_interpretation': 'QUOI', + 'identifiant_de_bloc': 'ac1' + }], + 'mots_signifiants': ['restaurant', 'thaïlandais'] + } + mapping = [{'path': '', 'id': 'id'}, {'path': 'blocs_reponses', 'id': 'identifiant_de_bloc'}, {'path': 'blocs_reponses.activites_affichage_immediat', 'id': 'identifiant'}] + ignored_field = ['creation_date', 'auto_state', 'user', 'status', 'comments'] + diff = get_diff(a, b, [], mapping, ignored_field) + + assert diff == []