Comments (2)
A simpler (better) approach with simple custom type to indicate dotted ignore key: feature/Issue#107_oo
Custom type in utils.py:
class DottedIgnoreKey(str):
"""Custom type to specify dotted ignore key.
This custom type help to desactivate dotted interpretation.
"""
pass
Using in diff function in init.py:
def _process_ignore_value(value):
if isinstance(value, int):
return value,
elif isinstance(value, list):
return tuple(value)
elif isinstance(value, DottedIgnoreKey):
return str(value),
return value
and finally in unit test test_dictdiffer.py:
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
Work fine with minimal modifications impact in code base :-D
from dictdiffer.
I write a fix/patch to workaround this problem: feature/Issue#107
My solution is to provide a function to generate raw
ignored keys.
I define a RAW_IGNORE_KEY_TOKEN
to generate (prefix) raw ignored keys (in utils.py).
I use this functionnality in diff
function for updating elements in ignore list keys:
if isinstance(ignore, Iterable):
def _unmake_raw_ignore_key(key):
return key[len(RAW_IGNORE_KEY_TOKEN):]
def _is_raw_ignore_key(key):
return key.startswith(RAW_IGNORE_KEY_TOKEN)
def _process_ignore_value(value):
if isinstance(value, int):
return value,
elif isinstance(value, list):
return tuple(value)
elif isinstance(value, string_types) and _is_raw_ignore_key(value):
return _unmake_raw_ignore_key(value),
return value
ignore = type(ignore)(_process_ignore_value(value) for value in ignore)
Usage in unittest:
def test_ignore_dotted_key_disable(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=[make_raw_ignore_key(key_to_ignore)]))) == 0
@jirikuncar Sound good for you ? (if yes, i can PR my branch)
from dictdiffer.
Related Issues (20)
- For removed items in .patch() first check if exists before deleting HOT 6
- global: migration to github-actions from travis
- Float comparator does not handle inf correctly
- CI: Exclude Python 3.8 with min configuration
- revert(result, patched) - IndexError: list assignment index out of range HOT 2
- 0.8.1: pytest based test suite is failing HOT 5
- Support for diffing and patching data holder objects
- Patch only 'changes' ignore add/remove HOT 1
- version 0.9.0 has dropped PY2 support but is still installable HOT 1
- pytest-runner not required HOT 1
- CI failing due to Sphinx/Jinja mismatch
- ignore_order
- Generate new dict from diff - dict of changes HOT 1
- get wrong result with path_limit
- 'KeyError': index out of bounds on patch.remove
- Toggling remove, add, change when patching HOT 1
- Removing more than two items from a list
- Сomparing large numbers doesn't work HOT 1
- Removing an item from a list causes a cascade of "changes", rather than "removes" HOT 1
- Project abandoned ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dictdiffer.