Skip to content

Commit

Permalink
diff: respect dot_notation flag in ignore argument
Browse files Browse the repository at this point in the history
(closes #107)
  • Loading branch information
yoyonel authored and jirikuncar committed Mar 17, 2019
1 parent 033d00e commit b341695
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dictdiffer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright (C) 2013 Fatih Erikli.
# Copyright (C) 2013, 2014, 2015, 2016 CERN.
# Copyright (C) 2017, 2018 ETH Zurich, Swiss Data Science Center, Jiri Kuncar.
# Copyright (C) 2017-2019 ETH Zurich, Swiss Data Science Center, Jiri Kuncar.
#
# Dictdiffer is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -134,6 +134,8 @@ def _process_ignore_value(value):
return value,
elif isinstance(value, list):
return tuple(value)
elif not dot_notation and isinstance(value, string_types):
return value,
return value

ignore = type(ignore)(_process_ignore_value(value) for value in ignore)
Expand All @@ -159,8 +161,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
27 changes: 27 additions & 0 deletions tests/test_dictdiffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# details.

import unittest
from collections import OrderedDict

import pytest

from dictdiffer import HAS_NUMPY, diff, dot_lookup, patch, revert, swap
from dictdiffer._compat import MutableMapping, MutableSequence, MutableSet
Expand Down Expand Up @@ -664,5 +667,29 @@ def test_invalit_lookup_type(self):
self.assertRaises(TypeError, dot_lookup, {0: '0'}, 0)


@pytest.mark.parametrize(
'ignore,dot_notation,diff_size', [
(u'nifi.zookeeper.session.timeout', True, 1),
(u'nifi.zookeeper.session.timeout', False, 0),
((u'nifi.zookeeper.session.timeout', ), True, 0),
((u'nifi.zookeeper.session.timeout', ), False, 0),
],
)
def test_ignore_dotted_ignore_key(ignore, dot_notation, diff_size):
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 diff_size == len(
list(diff(config_dict, ref_dict,
dot_notation=dot_notation,
ignore=[ignore])))


if __name__ == "__main__":
unittest.main()

0 comments on commit b341695

Please sign in to comment.