How to use the deepdiff.model.ResultDict function in deepdiff

To help you get started, we’ve selected a few deepdiff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github seperman / deepdiff / deepdiff / diff.py View on Github external
from deepdiff.model import DictRelationship, AttributeRelationship
from deepdiff.model import SubscriptableIterableRelationship, NonSubscriptableIterableRelationship, SetRelationship
from deepdiff.deephash import DeepHash
from deepdiff.base import Base

logger = logging.getLogger(__name__)
warnings.simplefilter('once', DeprecationWarning)

TREE_VIEW = 'tree'
TEXT_VIEW = 'text'


doc = get_doc('diff_doc.rst')


class DeepDiff(ResultDict, Base):
    __doc__ = doc

    def __init__(self,
                 t1,
                 t2,
                 ignore_order=False,
                 report_repetition=False,
                 significant_digits=None,
                 number_format_notation="f",
                 exclude_paths=None,
                 exclude_regex_paths=None,
                 exclude_types=None,
                 ignore_type_in_groups=None,
                 ignore_string_type_changes=False,
                 ignore_numeric_type_changes=False,
                 ignore_type_subclasses=False,
github seperman / deepdiff / deepdiff / model.py View on Github external
repetition = Repetition()


class ResultDict(RemapDict):
    def cleanup(self):
        """
        Remove empty keys from this object. Should always be called after the result is final.
        :return:
        """
        empty_keys = [k for k, v in getattr(self, items)() if not v]

        for k in empty_keys:
            del self[k]


class DiffTreeResult(ResultDict):
    def __init__(self):
        for key in DIFF_REPORT_KEYS:
            self[key] = set()


class DiffTextResult(ResultDict):
    def __init__(self, tree_results=None):

        # TODO: centralize keys
        self.update({
            "type_changes": {},
            "dictionary_item_added": self.__set_or_dict(),
            "dictionary_item_removed": self.__set_or_dict(),
            "values_changed": {},
            "unprocessed": [],
            "iterable_item_added": {},
github seperman / deepdiff / deepdiff / model.py View on Github external
def _from_tree_repetition_change(self, tree):
        if 'repetition_change' in tree:
            for change in tree['repetition_change']:
                path = change.path(force=FORCE_DEFAULT)
                self['repetition_change'][path] = RemapDict(change.additional[
                    'repetition'])
                self['repetition_change'][path]['value'] = change.t1


class HashTreeResult(ResultDict):
    def __init__(self):
        for key in HASH_REPORT_KEYS:
            self[key] = set()


class HashTextResult(ResultDict):
    """
    DeepHash's text style result is actually a flat view of all
    objects in the tree.
    Guess we should rename this.
    """
    def __init__(self, tree_results=None):
        for key in HASH_REPORT_KEYS:
            self[key] = set()
        if tree_results:
            self._from_tree_results(tree_results)

    def _from_tree_results(self, tree):
        """
        Populate this object by parsing an existing reference-style result dictionary.
        :param DiffTreeResult tree: Source data
        :return:
github seperman / deepdiff / deepdiff / model.py View on Github external
Remove empty keys from this object. Should always be called after the result is final.
        :return:
        """
        empty_keys = [k for k, v in getattr(self, items)() if not v]

        for k in empty_keys:
            del self[k]


class DiffTreeResult(ResultDict):
    def __init__(self):
        for key in DIFF_REPORT_KEYS:
            self[key] = set()


class DiffTextResult(ResultDict):
    def __init__(self, tree_results=None):

        # TODO: centralize keys
        self.update({
            "type_changes": {},
            "dictionary_item_added": self.__set_or_dict(),
            "dictionary_item_removed": self.__set_or_dict(),
            "values_changed": {},
            "unprocessed": [],
            "iterable_item_added": {},
            "iterable_item_removed": {},
            "attribute_added": self.__set_or_dict(),
            "attribute_removed": self.__set_or_dict(),
            "set_item_removed": set(),
            "set_item_added": set(),
            "repetition_change": {}
github seperman / deepdiff / deepdiff / model.py View on Github external
self._from_tree_create_all_entries(branch.child_rel.param_hash["hash"])

        if level.status is unprocessed:
            self[id(level.obj)] = unprocessed
        elif level.status is skipped:
            self[id(level.obj)] = skipped
        elif isinstance(level.obj, numbers):
            pass  # we don't include numbers in text view
        else:
            entry = level.text_view_hash()
            if entry != "":
                #print(str(id(level.obj)) + ":" + entry)
                self[id(level.obj)] = entry


class SearchTreeResult(ResultDict):
    pass


class SearchTextResult(ResultDict):
    pass


class BaseLevel(object):
    """
    Common abstract base class for DiffLevel, ... (more to come ;) )
    """

    def __init__(self,
                 objs=[],
                 down=None,
                 up=None,
github seperman / deepdiff / deepdiff / model.py View on Github external
item = change.t2
                if isinstance(item, strings):
                    item = "'%s'" % item
                self['set_item_added'].add("%s[%s]" % (path, str(item)))
                # this syntax is rather peculiar, but it's DeepDiff 2.x compatible)

    def _from_tree_repetition_change(self, tree):
        if 'repetition_change' in tree:
            for change in tree['repetition_change']:
                path = change.path(force=FORCE_DEFAULT)
                self['repetition_change'][path] = RemapDict(change.additional[
                    'repetition'])
                self['repetition_change'][path]['value'] = change.t1


class HashTreeResult(ResultDict):
    def __init__(self):
        for key in HASH_REPORT_KEYS:
            self[key] = set()


class HashTextResult(ResultDict):
    """
    DeepHash's text style result is actually a flat view of all
    objects in the tree.
    Guess we should rename this.
    """
    def __init__(self, tree_results=None):
        for key in HASH_REPORT_KEYS:
            self[key] = set()
        if tree_results:
            self._from_tree_results(tree_results)
github seperman / deepdiff / deepdiff / model / diffresult.py View on Github external
# -*- coding: utf-8 -*-

from . import DIFF_REPORT_KEYS, FORCE_DEFAULT
from . import ResultDict, notpresent
from ..helper import RemapDict, Verbose, strings


class DiffTreeResult(ResultDict):
    def __init__(self):
        for key in DIFF_REPORT_KEYS:
            self[key] = set()


class DiffTextResult(ResultDict):
    def __init__(self, tree_results=None):

        # TODO: centralize keys
        self.update({
            "type_changes": {},
            "dictionary_item_added": self.__set_or_dict(),
            "dictionary_item_removed": self.__set_or_dict(),
            "values_changed": {},
            "unprocessed": [],
            "iterable_item_added": {},
            "iterable_item_removed": {},
            "attribute_added": self.__set_or_dict(),
            "attribute_removed": self.__set_or_dict(),
            "set_item_removed": set(),
            "set_item_added": set(),
            "repetition_change": {}
github seperman / deepdiff / deepdiff / model / diffresult.py View on Github external
# -*- coding: utf-8 -*-

from . import DIFF_REPORT_KEYS, FORCE_DEFAULT
from . import ResultDict, notpresent
from ..helper import RemapDict, Verbose, strings


class DiffTreeResult(ResultDict):
    def __init__(self):
        for key in DIFF_REPORT_KEYS:
            self[key] = set()


class DiffTextResult(ResultDict):
    def __init__(self, tree_results=None):

        # TODO: centralize keys
        self.update({
            "type_changes": {},
            "dictionary_item_added": self.__set_or_dict(),
            "dictionary_item_removed": self.__set_or_dict(),
            "values_changed": {},
            "unprocessed": [],
            "iterable_item_added": {},
github seperman / deepdiff / deepdiff / model.py View on Github external
elif level.status is skipped:
            self[id(level.obj)] = skipped
        elif isinstance(level.obj, numbers):
            pass  # we don't include numbers in text view
        else:
            entry = level.text_view_hash()
            if entry != "":
                #print(str(id(level.obj)) + ":" + entry)
                self[id(level.obj)] = entry


class SearchTreeResult(ResultDict):
    pass


class SearchTextResult(ResultDict):
    pass


class BaseLevel(object):
    """
    Common abstract base class for DiffLevel, ... (more to come ;) )
    """

    def __init__(self,
                 objs=[],
                 down=None,
                 up=None,
                 child_rels=[],
                 additional=None):
        """
        :param list objs: A list of content or "payload" objects corresponding