tests/constants.py
def assert_has_edge(
    self: unittest.TestCase,
    u: BaseEntity,
    v: BaseEntity,
    graph: BELGraph,
    *,
    only: bool = False,
    permissive: bool = True,
    use_identifiers: bool = False,
    **expected_edge_data
):
    """A helper function for checking if an edge with the given properties is contained within a graph."""
    self.assertIsInstance(u, BaseEntity)
    self.assertIsInstance(v, BaseEntity)

    self.assertTrue(
        graph.has_edge(u, v),
        msg='Edge ({}, {}) not in graph. Other edges:\n{}'.format(u, v, '\n'.join(
            edge_to_bel(u, v, d, use_identifiers=use_identifiers)
            for u, v, d in graph.edges(data=True)
        ))
    )

    if not expected_edge_data:
        return

    if ANNOTATIONS in expected_edge_data:
        expected_edge_data[ANNOTATIONS] = graph._clean_annotations(expected_edge_data[ANNOTATIONS])

    if only:
        _key, actual_edge_data = list(graph[u][v].items())[0]
        self.assertEqual(_remove_line(expected_edge_data), _remove_line(actual_edge_data), msg='Only entry not equal')
    else:
        actual_dicts = {
            k: _remove_line(v)
            for k, v in graph[u][v].items()
        }
        if permissive:
            matches = any_subdict_matches(actual_dicts, _remove_line(expected_edge_data))
        else:
            matches = any_dict_matches(actual_dicts, _remove_line(expected_edge_data))

        msg = 'No edge ({}, {}) with correct properties. expected:\n {}\nbut got:\n{}'.format(
            u,
            v,
            dumps(expected_edge_data, indent=2, sort_keys=True),
            dumps(actual_dicts, indent=2, sort_keys=True),
        )
        self.assertTrue(matches, msg=msg)
A helper function for checking if an edge with the given properties is contained within a graph.
A helper function for checking if an edge with the given properties is contained within a graph.
A helper function for checking if an edge with the given properties is contained within a graph .
def assert_has_edge(
    self: unittest.TestCase,
    u: BaseEntity,
    v: BaseEntity,
    graph: BELGraph,
    *,
    only: bool = False,
    permissive: bool = True,
    use_identifiers: bool = False,
    **expected_edge_data
):
    self.assertIsInstance(u, BaseEntity)
    self.assertIsInstance(v, BaseEntity)
    self.assertTrue(
        graph.has_edge(u, v),
        msg='Edge ({}, {}) not in graph. Other edges:\n{}'.format(u, v, '\n'.join(
            edge_to_bel(u, v, d, use_identifiers=use_identifiers)
            for u, v, d in graph.edges(data=True)
        ))
    )
    if not expected_edge_data:
        return
    if ANNOTATIONS in expected_edge_data:
        expected_edge_data[ANNOTATIONS] = graph._clean_annotations(expected_edge_data[ANNOTATIONS])
    if only:
        _key, actual_edge_data = list(graph[u][v].items())[0]
        self.assertEqual(_remove_line(expected_edge_data), _remove_line(actual_edge_data), msg='Only entry not equal')
    else:
        actual_dicts = {
            k: _remove_line(v)
            for k, v in graph[u][v].items()
        }
        if permissive:
            matches = any_subdict_matches(actual_dicts, _remove_line(expected_edge_data))
        else:
            matches = any_dict_matches(actual_dicts, _remove_line(expected_edge_data))
        msg = 'No edge ({}, {}) with correct properties. expected:\n {}\nbut got:\n{}'.format(
            u,
            v,
            dumps(expected_edge_data, indent=2, sort_keys=True),
            dumps(actual_dicts, indent=2, sort_keys=True),
        )
        self.assertTrue(matches, msg=msg)
def assert_has_edge ( self : unittest . TestCase , u : BaseEntity , v : BaseEntity , graph : BELGraph , * , only : bool = False , permissive : bool = True , use_identifiers : bool = False , ** expected_edge_data ) : self . assertIsInstance ( u , BaseEntity ) self . assertIsInstance ( v , BaseEntity ) self . assertTrue ( graph . has_edge ( u , v ) , msg = 'Edge ({}, {}) not in graph. Other edges:\n{}' . format ( u , v , '\n' . join ( edge_to_bel ( u , v , d , use_identifiers = use_identifiers ) for u , v , d in graph . edges ( data = True ) ) ) ) if not expected_edge_data : return if ANNOTATIONS in expected_edge_data : expected_edge_data [ ANNOTATIONS ] = graph . _clean_annotations ( expected_edge_data [ ANNOTATIONS ] ) if only : _key , actual_edge_data = list ( graph [ u ] [ v ] . items ( ) ) [ 0 ] self . assertEqual ( _remove_line ( expected_edge_data ) , _remove_line ( actual_edge_data ) , msg = 'Only entry not equal' ) else : actual_dicts = { k : _remove_line ( v ) for k , v in graph [ u ] [ v ] . items ( ) } if permissive : matches = any_subdict_matches ( actual_dicts , _remove_line ( expected_edge_data ) ) else : matches = any_dict_matches ( actual_dicts , _remove_line ( expected_edge_data ) ) msg = 'No edge ({}, {}) with correct properties. expected:\n {}\nbut got:\n{}' . format ( u , v , dumps ( expected_edge_data , indent = 2 , sort_keys = True ) , dumps ( actual_dicts , indent = 2 , sort_keys = True ) , ) self . assertTrue ( matches , msg = msg )
A helper function for checking if an edge with the given properties is contained within a graph.
A helper function for checking if an edge with the given properties is contained within a graph .
"""A helper function for checking if an edge with the given properties is contained within a graph."""
self
unittest.TestCase
u
BaseEntity
v
BaseEntity
graph
BELGraph
only
bool
permissive
bool
use_identifiers
bool