<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import unittest2 <EOL> from anvil . graph import * <EOL> from anvil . module import * <EOL> from anvil . rule import * <EOL> from anvil . project import * <EOL> class RuleGraphTest ( unittest2 . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( RuleGraphTest , self ) . setUp ( ) <EOL> self . module_1 = Module ( '<STR_LIT>' , rules = [ <EOL> Rule ( '<STR_LIT>' ) , <EOL> Rule ( '<STR_LIT>' ) , <EOL> Rule ( '<STR_LIT>' ) , <EOL> Rule ( '<STR_LIT:b>' , srcs = [ '<STR_LIT>' , '<STR_LIT>' ] , deps = [ '<STR_LIT>' ] , ) , <EOL> Rule ( '<STR_LIT:c>' , deps = [ '<STR_LIT>' ] , ) , ] ) <EOL> self . module_2 = Module ( '<STR_LIT>' , rules = [ <EOL> Rule ( '<STR_LIT:p>' , deps = [ '<STR_LIT>' ] , ) ] ) <EOL> self . project = Project ( modules = [ self . module_1 , self . module_2 ] ) <EOL> def testConstruction ( self ) : <EOL> project = Project ( ) <EOL> graph = RuleGraph ( project ) <EOL> self . assertIs ( graph . project , project ) <EOL> project = self . project <EOL> graph = RuleGraph ( project ) <EOL> self . assertIs ( graph . project , project ) <EOL> def testAddRulesFromModule ( self ) : <EOL> graph = RuleGraph ( self . project ) <EOL> graph . add_rules_from_module ( self . module_1 ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> graph . add_rules_from_module ( self . module_2 ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> graph = RuleGraph ( self . project ) <EOL> graph . add_rules_from_module ( self . module_2 ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> def testCycle ( self ) : <EOL> module = Module ( '<STR_LIT>' , rules = [ <EOL> Rule ( '<STR_LIT:a>' , deps = [ '<STR_LIT>' ] ) , <EOL> Rule ( '<STR_LIT:b>' , deps = [ '<STR_LIT>' ] ) ] ) <EOL> project = Project ( modules = [ module ] ) <EOL> graph = RuleGraph ( project ) <EOL> with self . assertRaises ( ValueError ) : <EOL> graph . add_rules_from_module ( module ) <EOL> module_1 = Module ( '<STR_LIT>' , rules = [ Rule ( '<STR_LIT:a>' , deps = [ '<STR_LIT>' ] ) ] ) <EOL> module_2 = Module ( '<STR_LIT>' , rules = [ Rule ( '<STR_LIT:a>' , deps = [ '<STR_LIT>' ] ) ] ) <EOL> project = Project ( modules = [ module_1 , module_2 ] ) <EOL> graph = RuleGraph ( project ) <EOL> with self . assertRaises ( ValueError ) : <EOL> graph . add_rules_from_module ( module_1 ) <EOL> def testHasRule ( self ) : <EOL> graph = RuleGraph ( self . project ) <EOL> graph . add_rules_from_module ( self . module_1 ) <EOL> self . assertTrue ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_rule ( '<STR_LIT>' ) ) <EOL> def testHasDependency ( self ) : <EOL> graph = RuleGraph ( Project ( ) ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> graph = RuleGraph ( self . project ) <EOL> graph . add_rules_from_module ( self . module_1 ) <EOL> self . assertTrue ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertTrue ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertFalse ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def testCalculateRuleSequence ( self ) : <EOL> graph = RuleGraph ( self . project ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . calculate_rule_sequence ( '<STR_LIT>' ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . calculate_rule_sequence ( [ '<STR_LIT>' ] ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . calculate_rule_sequence ( [ '<STR_LIT>' ] ) <EOL> seq = graph . calculate_rule_sequence ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( seq ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( seq [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> seq = graph . calculate_rule_sequence ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( seq ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( seq [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> seq = graph . calculate_rule_sequence ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( seq ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( ( seq [ <NUM_LIT:0> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) or <EOL> ( seq [ <NUM_LIT:1> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( seq [ <NUM_LIT:2> ] . name , '<STR_LIT:b>' ) <EOL> seq = graph . calculate_rule_sequence ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( seq ) , <NUM_LIT:3> ) <EOL> self . assertTrue ( ( seq [ <NUM_LIT:0> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) or <EOL> ( seq [ <NUM_LIT:1> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertEqual ( seq [ <NUM_LIT:2> ] . name , '<STR_LIT:b>' ) <EOL> seq = graph . calculate_rule_sequence ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( seq ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( ( seq [ <NUM_LIT:0> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) or <EOL> ( seq [ <NUM_LIT:1> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> module = Module ( '<STR_LIT>' , rules = [ Rule ( '<STR_LIT:a>' , deps = [ '<STR_LIT>' ] ) ] ) <EOL> project = Project ( modules = [ module ] ) <EOL> graph = RuleGraph ( project ) <EOL> with self . assertRaises ( KeyError ) : <EOL> graph . calculate_rule_sequence ( '<STR_LIT>' ) <EOL> def testCrossModuleRules ( self ) : <EOL> graph = RuleGraph ( self . project ) <EOL> seq = graph . calculate_rule_sequence ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( len ( seq ) , <NUM_LIT:5> ) <EOL> self . assertTrue ( ( seq [ <NUM_LIT:0> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) or <EOL> ( seq [ <NUM_LIT:1> ] . name in [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . assertTrue ( seq [ <NUM_LIT:4> ] . path , '<STR_LIT>' ) <EOL> self . assertTrue ( graph . has_dependency ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest2 . main ( ) </s>
