<s> import unittest2 as unittest <EOL> import digraphtools <EOL> import digraphtools . topsort as topsort <EOL> import core . bits as bits <EOL> import core . deptools as deptools <EOL> import core . store <EOL> class BitTests ( unittest . TestCase ) : <EOL> def testTask ( self ) : <EOL> task = bits . Task ( tuple ( ) , None , bits . TaskComplete ( [ '<STR_LIT>' ] ) ) <EOL> task = bits . Task ( ( '<STR_LIT>' , '<STR_LIT>' ) , None , bits . TaskComplete ( [ '<STR_LIT>' ] ) ) <EOL> class GraphStrategyTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> class C ( bits . Item ) : pass <EOL> class B ( bits . Item ) : depends = ( C , ) <EOL> class A ( bits . Item ) : depends = ( B , C ) <EOL> self . A , self . B , self . C = A , B , C <EOL> def test_get_graph ( self ) : <EOL> A , B , C = self . A , self . B , self . C <EOL> g = deptools . GraphDependencyStrategy . get_graph ( A ) <EOL> ref = [ A , [ [ B , [ [ C , [ ] ] ] ] , [ C , [ ] ] ] ] <EOL> self . assertEqual ( g , ref ) <EOL> def test_iterate_item_dependencies ( self ) : <EOL> toporder = deptools . GraphDependencyStrategy . iterate_item_dependencies ( self . A ) <EOL> self . assertEqual ( list ( toporder ) , [ self . C , self . B , self . A ] ) <EOL> def test_item_factory ( self ) : <EOL> a = deptools . GraphDependencyStrategy . item_factory ( self . A ) <EOL> self . assertIsInstance ( a , self . A ) <EOL> clstoporder = deptools . GraphDependencyStrategy . iterate_item_dependencies ( self . A ) <EOL> insttoporder = deptools . GraphDependencyStrategy . iterate_item_dependencies ( a ) <EOL> for cls , inst in zip ( clstoporder , insttoporder ) : <EOL> self . assertIsInstance ( inst , cls ) <EOL> class DigraphStrategyTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> class C ( bits . Item ) : pass <EOL> class B ( bits . Item ) : depends = ( C , ) <EOL> class A ( bits . Item ) : depends = ( B , C ) <EOL> self . A , self . B , self . C = A , B , C <EOL> def test_iterate_item_dependencies ( self ) : <EOL> toporder = deptools . DigraphDependencyStrategy . iterate_item_dependencies ( self . A ) <EOL> self . assertEqual ( list ( toporder ) , [ self . C , self . B , self . A ] ) <EOL> def test_item_factory ( self ) : <EOL> a = deptools . DigraphDependencyStrategy . item_factory ( self . A ) <EOL> self . assertIsInstance ( a , self . A ) <EOL> clstoporder = deptools . DigraphDependencyStrategy . iterate_item_dependencies ( self . A ) <EOL> insttoporder = deptools . DigraphDependencyStrategy . iterate_item_dependencies ( a ) <EOL> for cls , inst in zip ( clstoporder , insttoporder ) : <EOL> self . assertIsInstance ( inst , cls ) <EOL> def test_find_goal_nodes ( self ) : <EOL> goals = deptools . DigraphDependencyStrategy . find_goal_nodes ( [ self . A , self . B , self . C ] ) <EOL> self . assertEqual ( set ( [ self . A ] ) , goals ) <EOL> class SimpleStrategyTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> class C ( bits . Item ) : pass <EOL> class B ( bits . Item ) : depends = ( C , ) <EOL> class A ( bits . Item ) : depends = ( B , C ) <EOL> self . A , self . B , self . C = A , B , C <EOL> def test_iterate_item_dependencies ( self ) : <EOL> toporder = deptools . SimpleDependencyStrategy . iterate_item_dependencies ( self . A ) <EOL> self . assertEqual ( list ( toporder ) , [ self . C , self . B , self . A ] ) <EOL> class TopsortTests ( unittest . TestCase ) : <EOL> def test_vr_topsort ( self ) : <EOL> n = <NUM_LIT:5> <EOL> partial_order = [ ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:1> , <NUM_LIT:5> ) ] <EOL> g = digraphtools . graph_from_edges ( digraphtools . from_partial_order ( partial_order ) ) <EOL> grid = topsort . partial_order_to_grid ( partial_order , n ) <EOL> for le in topsort . vr_topsort ( n , grid ) : <EOL> digraphtools . verify_partial_order ( digraphtools . iter_partial_order ( g ) , le ) <EOL> class StoreTests ( unittest . TestCase ) : <EOL> sample_json = '<STR_LIT>' <EOL> def _dont_test_memorystore ( self ) : <EOL> uuid = '<STR_LIT>' <EOL> ms = core . store . MemoryStore ( ) <EOL> self . assertFalse ( ms . exists ( uuid ) ) <EOL> self . assertFalse ( ms . exists ( uuid , '<STR_LIT>' ) ) <EOL> ms . new_task ( uuid ) <EOL> self . assertTrue ( ms . exists ( uuid ) ) <EOL> self . assertFalse ( ms . exists ( uuid , '<STR_LIT>' ) ) <EOL> ms . store ( uuid , '<STR_LIT>' , self . sample_json ) <EOL> self . assertEqual ( ms . retrieve ( uuid , '<STR_LIT>' ) , self . sample_json ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
