def test_sankey_definition(): nodes = {} bundles = {} ordering = Ordering([]) vd = SankeyDefinition(nodes, bundles, ordering) assert vd.nodes is nodes assert vd.bundles is bundles assert vd.ordering is ordering
def test_sankey_definition_checks_nodes_exist(): nodes = { 'a': ProcessGroup(selection=('a1')), 'b': ProcessGroup(selection=('b1')), 'waypoint': ProcessGroup(), } ordering = Ordering([]) with pytest.raises(ValueError): bundles = [Bundle('does not exist', 'b')] SankeyDefinition(nodes, bundles, ordering) with pytest.raises(ValueError): bundles = [Bundle('a', 'b', waypoints=['does not exist'])] SankeyDefinition(nodes, bundles, ordering)
def test_ordering_indices(): a = Ordering([ [['a', 'b'], ['c']], [[], ['d']], ]) assert a.indices('a') == (0, 0, 0) assert a.indices('b') == (0, 0, 1) assert a.indices('c') == (0, 1, 0) assert a.indices('d') == (1, 1, 0) with pytest.raises(ValueError): a.indices('e')
def test_ordering_insert(): a = Ordering([ [['a', 'b'], ['c']], [[], ['d']], ]) assert a.insert(0, 0, 0, 'x') == Ordering([ [['x', 'a', 'b'], ['c']], [[], ['d']], ]) assert a.insert(0, 0, 1, 'x') == Ordering([ [['a', 'x', 'b'], ['c']], [[], ['d']], ]) assert a.insert(1, 1, 1, 'x') == Ordering([ [['a', 'b'], ['c']], [[], ['d', 'x']], ])
def test_ordering_remove(): a = Ordering([ [['a', 'b'], ['c']], [[], ['d']], ]) assert a.remove('a') == Ordering([ [['b'], ['c']], [[], ['d']], ]) assert a.remove('d') == Ordering([ [['a', 'b'], ['c']], ]) assert a == Ordering([ [['a', 'b'], ['c']], [[], ['d']], ])
def test_sankey_definition_checks_bundles(): nodes = { 'a': ProcessGroup(selection=('a1')), 'b': ProcessGroup(selection=('b1')), 'waypoint': Waypoint(), } ordering = Ordering([]) with pytest.raises(ValueError): bundles = {0: Bundle('waypoint', 'b')} SankeyDefinition(nodes, bundles, ordering) with pytest.raises(ValueError): bundles = {0: Bundle('b', 'waypoint')} SankeyDefinition(nodes, bundles, ordering) # should work bundles = {0: Bundle('a', 'b')} assert SankeyDefinition(nodes, bundles, ordering) # also accepts a list bundles = [Bundle('a', 'b')] assert SankeyDefinition(nodes, bundles, ordering).bundles \ == {0: Bundle('a', 'b')}
def test_ordering_normalisation(): o1 = Ordering([['a', 'b'], ['c']]) o2 = Ordering([[['a', 'b']], [['c']]]) assert o1 == o2