<s> from briefly . dag import * <EOL> from briefly . properties import * <EOL> import unittest <EOL> class TestGraphNode ( unittest . TestCase ) : <EOL> myattrs = { '<STR_LIT>' : <NUM_LIT:1> } <EOL> def test_no_attrs ( self ) : <EOL> graph_node = GraphNode ( ) <EOL> self . assertTrue ( hasattr ( graph_node , '<STR_LIT>' ) ) <EOL> self . assertTrue ( hasattr ( graph_node , '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph_node . attributes is None ) <EOL> dummy_key = <NUM_LIT:1> <EOL> key = graph_node . unpack ( dummy_key ) <EOL> self . assertTrue ( key == dummy_key ) <EOL> def test_attrs ( self ) : <EOL> graph_node = GraphNode ( self . myattrs ) <EOL> self . assertTrue ( len ( graph_node . attributes ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( graph_node . attributes [ '<STR_LIT>' ] == <NUM_LIT:1> ) <EOL> def test_int_attrs ( self ) : <EOL> metadata = <NUM_LIT:3> <EOL> graph_node = GraphNode ( metadata ) <EOL> self . assertTrue ( graph_node . attributes == metadata ) <EOL> dummy_key = <NUM_LIT:1> <EOL> key , attrs = graph_node . unpack ( dummy_key ) <EOL> self . assertTrue ( attrs == metadata ) <EOL> self . assertTrue ( key == dummy_key ) <EOL> def test_attr_err ( self ) : <EOL> graph_node = GraphNode ( ) <EOL> expected = False <EOL> try : <EOL> graph_node . parents = set ( [ <NUM_LIT:2> ] ) <EOL> except AttributeError : <EOL> expected = True <EOL> self . assertTrue ( expected ) <EOL> class TestCaseIslands ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . nodes = set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . g = DependencyGraph ( ) <EOL> self . g . add_node ( <NUM_LIT:1> ) <EOL> self . g . add_node ( <NUM_LIT:2> ) <EOL> self . g . add_node ( <NUM_LIT:3> ) <EOL> self . g . add_edge ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> def test_nodes ( self ) : <EOL> wait = False <EOL> self . assertTrue ( len ( self . g ) == <NUM_LIT:3> ) <EOL> for n in self . nodes : <EOL> self . assertTrue ( n in self . g ) <EOL> for n in self . g . nodes : <EOL> self . assertTrue ( n in self . nodes ) <EOL> self . g . remove ( <NUM_LIT:2> ) <EOL> self . assertTrue ( <NUM_LIT:1> in self . g ) <EOL> self . assertTrue ( <NUM_LIT:3> in self . g ) <EOL> self . assertFalse ( <NUM_LIT:2> in self . g ) <EOL> self . assertFalse ( <NUM_LIT:4> in self . g ) <EOL> self . assertTrue ( len ( self . g ) == <NUM_LIT:2> ) <EOL> self . assertFalse ( self . g . is_empty ( ) ) <EOL> self . g . remove ( <NUM_LIT:1> ) <EOL> self . g . remove ( <NUM_LIT:3> ) <EOL> self . assertTrue ( self . g . is_empty ( ) ) <EOL> class TestCaseSanity ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . edges = [ ( x , x + <NUM_LIT:1> ) for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> ) ] <EOL> self . g = DependencyGraph ( ) <EOL> for p , c in [ ( x , x + <NUM_LIT:1> ) for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> ) ] : <EOL> self . g . add_node ( p ) <EOL> self . g . add_node ( c ) <EOL> self . g . add_edges ( self . edges ) <EOL> repr ( self . g ) <EOL> def _test_bridge_nodes ( self , iterable ) : <EOL> for x in iterable : <EOL> bridge_nodes = list ( self . g . get_bridge_nodes ( x ) ) <EOL> self . assertTrue ( len ( bridge_nodes ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( bridge_nodes [ <NUM_LIT:0> ] == x + <NUM_LIT:1> ) <EOL> def _test_node_exists ( self , iterable ) : <EOL> for x in iterable : <EOL> self . assertTrue ( x in self . g ) <EOL> def test_nodes ( self ) : <EOL> self . _test_node_exists ( xrange ( <NUM_LIT:1> , <NUM_LIT:7> ) ) <EOL> for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> ) : <EOL> self . assertTrue ( self . g . has_child ( x ) ) <EOL> for x in xrange ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> self . assertTrue ( self . g . has_parent ( x ) ) <EOL> for p , c in self . edges : <EOL> self . assertTrue ( self . g . has_edge ( p , c ) ) <EOL> for key in self . g : <EOL> self . assertTrue ( self . g . has_node ( key ) ) <EOL> def test_bridge_nodes ( self ) : <EOL> self . _test_bridge_nodes ( xrange ( <NUM_LIT:1> , <NUM_LIT:5> ) ) <EOL> self . g . remove <EOL> def test_remove ( self ) : <EOL> for s in xrange ( <NUM_LIT:1> , <NUM_LIT:5> ) : <EOL> self . assertTrue ( s in self . g ) <EOL> self . g . remove ( s ) <EOL> self . assertFalse ( s in self . g ) <EOL> self . _test_node_exists ( xrange ( s + <NUM_LIT:1> , <NUM_LIT:7> ) ) <EOL> self . _test_bridge_nodes ( xrange ( s + <NUM_LIT:1> , <NUM_LIT:5> ) ) <EOL> def test_remove_middle ( self ) : <EOL> self . assertTrue ( <NUM_LIT:2> in self . g ) <EOL> self . g . remove ( <NUM_LIT:2> ) <EOL> self . assertFalse ( <NUM_LIT:2> in self . g ) <EOL> self . assertTrue ( <NUM_LIT:1> in self . g ) <EOL> self . assertFalse ( self . g . has_child ( <NUM_LIT:1> ) ) <EOL> for n in xrange ( <NUM_LIT:3> , <NUM_LIT:7> ) : <EOL> self . assertTrue ( n in self . g ) <EOL> for x in xrange ( <NUM_LIT:3> , <NUM_LIT:6> ) : <EOL> self . assertTrue ( self . g . has_child ( x ) ) <EOL> class TestCaseParallel ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . edges = [ ( x , x + <NUM_LIT:1> ) for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:2> ) ] <EOL> self . g = DependencyGraph ( ) <EOL> for p , c in [ ( x , x + <NUM_LIT:1> ) for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:2> ) ] : <EOL> self . g . add_node ( p ) <EOL> self . g . add_node ( c ) <EOL> self . g . add_edges ( self . edges ) <EOL> def test_start_nodes ( self ) : <EOL> start_nodes = set ( self . g . get_start_nodes ( ) ) <EOL> self . assertTrue ( len ( start_nodes ) == <NUM_LIT:3> ) <EOL> for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:2> ) : <EOL> self . assertTrue ( x in start_nodes ) <EOL> def test_bridge_nodes ( self ) : <EOL> for x in xrange ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:2> ) : <EOL> bnodes = list ( self . g . get_bridge_nodes ( x ) ) <EOL> self . assertTrue ( len ( bnodes ) == <NUM_LIT:1> ) <EOL> self . assertTrue ( x + <NUM_LIT:1> == bnodes [ <NUM_LIT:0> ] ) <EOL> for x in xrange ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:2> ) : <EOL> bnodes = list ( self . g . get_bridge_nodes ( x ) ) <EOL> self . assertTrue ( len ( bnodes ) == <NUM_LIT:0> ) <EOL> class TestAttributeGraph ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . g = DependencyGraph ( ) <EOL> self . g . add_node ( <NUM_LIT:1> , { '<STR_LIT:name>' : <NUM_LIT:1> } ) <EOL> self . g . add_node ( <NUM_LIT:2> , { '<STR_LIT:name>' : <NUM_LIT:2> } ) <EOL> self . g . add_edge ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> def test_attribute ( self ) : <EOL> for n , attr in self . g . nodes : <EOL> self . assertTrue ( attr [ '<STR_LIT:name>' ] == n ) <EOL> def test_start_nodes ( self ) : <EOL> start_nodes = list ( self . g . get_start_nodes ( ) ) <EOL> self . assertTrue ( len ( start_nodes ) == <NUM_LIT:1> ) <EOL> node , attr = start_nodes [ <NUM_LIT:0> ] <EOL> self . assertTrue ( node == <NUM_LIT:1> ) <EOL> self . assertTrue ( node == <NUM_LIT:1> ) <EOL> def test_bridge_nodes ( self ) : <EOL> bridge_nodes = list ( self . g . get_bridge_nodes ( <NUM_LIT:1> ) ) <EOL> self . assertTrue ( len ( bridge_nodes ) == <NUM_LIT:1> ) <EOL> node , attr = bridge_nodes [ <NUM_LIT:0> ] <EOL> self . assertTrue ( node == <NUM_LIT:2> ) <EOL> self . assertTrue ( attr [ '<STR_LIT:name>' ] == <NUM_LIT:2> ) <EOL> class TestPropertiesGraph ( unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> self . g = DependencyGraph ( ) <EOL> self . g . add_node ( <NUM_LIT:1> , Properties ( name = <NUM_LIT:1> ) ) <EOL> self . g . add_node ( <NUM_LIT:2> , Properties ( name = <NUM_LIT:2> ) ) <EOL> self . g . add_edge ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> def test_properties ( self ) : <EOL> for n , prop in self . g . nodes : <EOL> self . assertTrue ( prop . name == n ) <EOL> def test_bridge_nodes ( self ) : <EOL> bridge_nodes = list ( self . g . get_bridge_nodes ( <NUM_LIT:1> ) ) <EOL> self . assertTrue ( len ( bridge_nodes ) == <NUM_LIT:1> ) <EOL> node , prop = bridge_nodes [ <NUM_LIT:0> ] <EOL> self . assertTrue ( prop . name == <NUM_LIT:2> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
