How to use the deepdiff.DeepSearch 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 / tests / test_search.py View on Github external
def test_custom_object_verbose(self):
        obj = CustomClass('here, something', 'somewhere out there')
        result = {'matched_values': {'root.b': 'somewhere out there'}}
        ds = DeepSearch(obj, item, verbose_level=2)
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_int_in_dictionary(self):
        obj = {"long": "somewhere", "num": 2, 0: 0, "somewhere": "around"}
        item = 2
        result = {'matched_values': {"root['num']"}}
        ds = DeepSearch(obj, item, verbose_level=1)
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_string_in_list(self):
        obj = ["long", "string", 0, "somewhere"]
        result = {"matched_values": {'root[3]'}}
        self.assertEqual(DeepSearch(obj, item, verbose_level=1), result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_custom_object(self):
        obj = CustomClass('here, something', 'somewhere')
        result = {'matched_values': {'root.b'}}
        ds = DeepSearch(obj, item, verbose_level=1)
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_skip_list_path(self):
        obj = ['a', 'somewhere']
        ds = DeepSearch(obj, item, exclude_paths=['root[1]'])
        result = {}
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_skip_type_str(self):
        obj = "long string somewhere"
        result = {}
        ds = DeepSearch(obj, item, verbose_level=1, exclude_types=[str])
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_bad_attribute(self):
        class Bad(object):
            __slots__ = ['x', 'y']

            def __getattr__(self, key):
                raise AttributeError("Bad item")

            def __str__(self):
                return "Bad Object"

        obj = Bad()

        ds = DeepSearch(obj, item, verbose_level=1)
        result = {'unprocessed': ['root']}
        self.assertEqual(ds, result)
        ds = DeepSearch(obj, item, verbose_level=2)
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_skip_path1(self):
        obj = {
            "for life": "vegan",
            "ingredients": ["no meat", "no eggs", "no dairy", "somewhere"]
        }
        ds = DeepSearch(obj, item, exclude_paths={"root['ingredients']"})
        self.assertEqual(ds, {})
github seperman / deepdiff / tests / test_search.py View on Github external
def test_loop_in_lists(self):
        obj = [1, 2, 'somewhere']
        obj.append(obj)

        ds = DeepSearch(obj, item, verbose_level=1)
        result = {'matched_values': {'root[2]'}}
        self.assertEqual(ds, result)
github seperman / deepdiff / tests / test_search.py View on Github external
def test_string_in_set_verbose(self):
        obj = {"long", "string", 0, "somewhere"}
        # result = {"matched_values": {'root[3]': "somewhere"}}
        ds = DeepSearch(obj, item, verbose_level=2)
        self.assertEqual(list(ds["matched_values"].values())[0], item)