Esempio n. 1
0
 def test_dict_matches_3(self):
     target = {
         'k1': 'v1',
     }
     query = {
         'k1': 'v1',
         'k2': 'v2'
     }
     self.assertFalse(subdict_matches(target, query))
Esempio n. 2
0
 def test_dict_matches_6(self):
     target = {
         'k1': 'v1',
         'k2': ['v2', 'v3']
     }
     query = {
         'k1': 'v1',
         'k2': 'v4'
     }
     self.assertFalse(subdict_matches(target, query))
Esempio n. 3
0
 def test_dict_matches_5(self):
     target = {
         'k1': 'v1',
         'k2': 'v2'
     }
     query = {
         'k1': 'v1',
         'k2': ['v2', 'v3']
     }
     self.assertTrue(subdict_matches(target, query))
Esempio n. 4
0
def any_subdict_matches(dict_of_dicts, query_dict) -> bool:
    """Checks if dictionary target_dict matches one of the subdictionaries of a

    :param dict[any,dict] dict_of_dicts: dictionary of dictionaries
    :param dict query_dict: dictionary
    :return: if dictionary target_dict matches one of the subdictionaries of a
    """
    return any(
        subdict_matches(sub_dict, query_dict)
        for sub_dict in dict_of_dicts.values())
Esempio n. 5
0
    def test_dict_matches_7_exact(self):
        """Test a partial match."""
        target = {
            'k1': 'v1',
            'k2': 'v2'
        }
        query = {
            'k1': 'v1',
            'k2': {'v2': 'v3'}
        }

        self.assertFalse(subdict_matches(target, query, partial_match=False))
Esempio n. 6
0
    def test_dict_matches_7_partial(self):
        """Tests a partial match"""
        target = {
            'k1': 'v1',
            'k2': 'v2'
        }
        query = {
            'k1': 'v1',
            'k2': {'v2': 'v3'}
        }

        self.assertFalse(subdict_matches(target, query))
Esempio n. 7
0
    def test_dict_matches_8_partial(self):
        """Test a partial match."""
        target = {
            'k1': 'v1',
            'k2': {'v2': 'v3', 'v4': 'v5'}
        }
        query = {
            'k1': 'v1',
            'k2': {'v2': 'v3'}
        }

        self.assertTrue(subdict_matches(target, query))
Esempio n. 8
0
 def annotation_dict_filter(graph, u, v, k, d):
     """A filter that matches edges with the given dictionary as a subdictionary"""
     return subdict_matches(d, annotations, partial_match=partial_match)
Esempio n. 9
0
 def annotation_dict_filter(data: EdgeData) -> bool:
     """Match edges with the given dictionary as a sub-dictionary."""
     return subdict_matches(data, annotations, partial_match=partial_match)
Esempio n. 10
0
 def annotation_dict_filter(data):
     """A filter that matches edges with the given dictionary as a subdictionary"""
     return subdict_matches(data[ANNOTATIONS],
                            annotations,
                            partial_match=partial_match)