Skip to content

Commit

Permalink
Merge 343f3c1 into 596bb01
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyonel committed Mar 4, 2019
2 parents 596bb01 + 343f3c1 commit 277702a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 5 additions & 3 deletions dictdiffer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

from ._compat import (PY2, Iterable, MutableMapping, MutableSequence,
MutableSet, string_types, text_type)
from .utils import EPSILON, PathLimit, are_different, dot_lookup
from .utils import (EPSILON, PathLimit, are_different, dot_lookup,
DottedIgnoreKey)
from .version import __version__

(ADD, REMOVE, CHANGE) = (
Expand Down Expand Up @@ -123,6 +124,8 @@ def _process_ignore_value(value):
return value,
elif isinstance(value, list):
return tuple(value)
elif isinstance(value, DottedIgnoreKey):
return str(value),
return value

ignore = type(ignore)(_process_ignore_value(value) for value in ignore)
Expand All @@ -147,8 +150,7 @@ def _diff_recursive(_first, _second, _node=None):
def check(key):
"""Test if key in current node should be ignored."""
return ignore is None or (
dotted(_node + [key],
default_type=tuple) not in ignore and
dotted(_node + [key], default_type=tuple) not in ignore and
tuple(_node + [key]) not in ignore
)

Expand Down
9 changes: 9 additions & 0 deletions dictdiffer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
EPSILON = sys.float_info.epsilon


class DottedIgnoreKey(str):
"""Custom type to specify dotted ignore key.
This custom type help to desactivate dotted interpretation.
"""

pass


class WildcardDict(dict):
"""Provide possibility to use special wildcard keys to access values.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_dictdiffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
# details.

import unittest
from collections import OrderedDict

from dictdiffer import HAS_NUMPY, diff, dot_lookup, patch, revert, swap
from dictdiffer._compat import MutableMapping, MutableSequence, MutableSet
from dictdiffer.utils import PathLimit
from dictdiffer.utils import DottedIgnoreKey, PathLimit

if not hasattr(unittest, 'skipIf'):
import unittest2 as unittest # Python 2.6 support
Expand Down Expand Up @@ -280,6 +281,20 @@ def test_ignore_dotted_key(self):
diffed = next(diff(first, second, ignore=['a.aa']))
assert ('change', 'a.ac', ('C', 3)) == diffed

def test_ignore_dotted_ignore_key(self):
key_to_ignore = u'nifi.zookeeper.session.timeout'
config_dict = OrderedDict(
[('address', 'devops011-slv-01.gvs.ggn'),
(key_to_ignore, '3 secs')])

ref_dict = OrderedDict(
[('address', 'devops011-slv-01.gvs.ggn'),
(key_to_ignore, '4 secs')])

assert len(
list(diff(config_dict, ref_dict,
ignore=[DottedIgnoreKey(key_to_ignore)]))) == 0

def test_ignore_with_unicode_sub_keys(self):
first = {u'a': {u'aא': {u'aa': 'A'}}}
second = {u'a': {u'aא': {u'aa': 'B'}}}
Expand Down

0 comments on commit 277702a

Please sign in to comment.