<s> """<STR_LIT>""" <EOL> import unittest <EOL> import yaml <EOL> from chassis . test . example_classes import Bar <EOL> from chassis . test . example_classes import Baz <EOL> from chassis . test . example_classes import Foo <EOL> from chassis . test . example_classes import Spam <EOL> from chassis . test . example_classes import Qux <EOL> from chassis . test . example_classes import Wobble <EOL> from chassis . test . example_classes import TestLogger <EOL> import chassis . services . dependency_injection . resolver as resolver <EOL> from chassis . util . tree import DependencyTree <EOL> def get_config_yaml ( ) : <EOL> """<STR_LIT>""" <EOL> return yaml . load ( open ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:r>' ) ) or { } <EOL> class DetectCircleTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_detect_circle_raises_circular_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( resolver . CircularDependencyException , <EOL> resolver . detect_circle , <EOL> { '<STR_LIT:a>' : set ( [ '<STR_LIT:b>' ] ) , <EOL> '<STR_LIT:b>' : set ( [ '<STR_LIT:a>' ] ) } ) <EOL> self . assertRaises ( resolver . CircularDependencyException , <EOL> resolver . detect_circle , <EOL> { '<STR_LIT:a>' : set ( [ '<STR_LIT:b>' ] ) , <EOL> '<STR_LIT:b>' : set ( [ '<STR_LIT:c>' ] ) , <EOL> '<STR_LIT:c>' : set ( [ '<STR_LIT:a>' ] ) } ) <EOL> def test_detect_circle_raises_type_exception ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( TypeError , <EOL> resolver . _detect_circle , <EOL> '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , <EOL> resolver . _detect_circle , <EOL> { '<STR_LIT:a>' : ( ) } , <EOL> '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , <EOL> resolver . _detect_circle , <EOL> { '<STR_LIT:a>' : ( ) } , <EOL> ( ) , <EOL> '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , <EOL> resolver . _detect_circle , <EOL> { '<STR_LIT:a>' : ( ) } , <EOL> ( ) , <EOL> [ ] , <EOL> '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , <EOL> resolver . _detect_circle , <EOL> { '<STR_LIT:a>' : ( ) } , <EOL> ( ) , <EOL> [ ] , <EOL> <NUM_LIT:0> , <EOL> '<STR_LIT>' ) <EOL> def test_detect_circle_2 ( self ) : <EOL> """<STR_LIT>""" <EOL> graph = { <EOL> '<STR_LIT:a>' : set ( [ '<STR_LIT:b>' ] ) , <EOL> '<STR_LIT:b>' : set ( [ '<STR_LIT:c>' , '<STR_LIT:d>' ] ) , <EOL> '<STR_LIT:c>' : set ( [ '<STR_LIT:e>' ] ) , <EOL> '<STR_LIT:d>' : set ( [ '<STR_LIT:e>' ] ) , <EOL> '<STR_LIT:e>' : set ( ) <EOL> } <EOL> tree = resolver . detect_circle ( graph ) <EOL> assert isinstance ( tree , DependencyTree ) <EOL> def test_detect_circle ( self ) : <EOL> """<STR_LIT>""" <EOL> graph = { <EOL> '<STR_LIT:a>' : set ( [ '<STR_LIT:f>' , '<STR_LIT:c>' ] ) , <EOL> '<STR_LIT:b>' : set ( ) , <EOL> '<STR_LIT:c>' : set ( [ '<STR_LIT:b>' ] ) , <EOL> '<STR_LIT:d>' : set ( ) , <EOL> '<STR_LIT:e>' : set ( '<STR_LIT:d>' ) , <EOL> '<STR_LIT:f>' : set ( ) , <EOL> '<STR_LIT:g>' : set ( [ '<STR_LIT:a>' ] ) <EOL> } <EOL> tree = resolver . detect_circle ( graph ) <EOL> assert isinstance ( tree , DependencyTree ) <EOL> self . assertEquals ( <NUM_LIT:7> , tree . head_count ) <EOL> self . assertEquals ( <EOL> set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' ] ) , <EOL> tree . head_values <EOL> ) <EOL> class DependencyNameTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_names ( self ) : <EOL> """<STR_LIT>""" <EOL> assert resolver . is_dependency_name ( '<STR_LIT>' ) <EOL> assert not resolver . is_dependency_name ( '<STR_LIT:foo>' ) <EOL> class ResolverTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_init_nodes ( self ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT:foo>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> rslvr = resolver . Resolver ( config ) <EOL> nodes = rslvr . nodes <EOL> self . assertEquals ( nodes [ '<STR_LIT:foo>' ] , set ( ) ) <EOL> def test_init_nodes_with_a_dependency ( self ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT:foo>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:bar>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : '<STR_LIT>' , <EOL> '<STR_LIT:args>' : [ '<STR_LIT>' ] <EOL> } <EOL> } <EOL> rslvr = resolver . Resolver ( config ) <EOL> nodes = rslvr . nodes <EOL> self . assertEquals ( nodes [ '<STR_LIT:foo>' ] , set ( ) ) <EOL> self . assertEquals ( nodes [ '<STR_LIT:bar>' ] , set ( [ '<STR_LIT:foo>' ] ) ) <EOL> def test_init_nodes_complicated ( self ) : <EOL> """<STR_LIT>""" <EOL> config = get_config_yaml ( ) <EOL> rslvr = resolver . Resolver ( config ) <EOL> nodes = rslvr . nodes <EOL> self . assertEquals ( nodes [ '<STR_LIT>' ] , set ( ) ) <EOL> self . assertEquals ( nodes [ '<STR_LIT:foo>' ] , set ( ) ) <EOL> self . assertEquals ( nodes [ '<STR_LIT:bar>' ] , set ( [ '<STR_LIT:foo>' ] ) ) <EOL> self . assertEquals ( nodes [ '<STR_LIT>' ] , set ( [ '<STR_LIT:foo>' , '<STR_LIT:bar>' , '<STR_LIT>' ] ) ) <EOL> def test_do_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> rslvr = resolver . Resolver ( { <EOL> '<STR_LIT:foo>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> services = rslvr . do ( ) <EOL> self . assertTrue ( '<STR_LIT:foo>' in services ) <EOL> assert isinstance ( services [ '<STR_LIT:foo>' ] , Foo ) <EOL> def test_advanced ( self ) : <EOL> """<STR_LIT>""" <EOL> config = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:class>' : '<STR_LIT>' , <EOL> '<STR_LIT:args>' : [ <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT:port>' : '<STR_LIT>' <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> scalars = { '<STR_LIT>' : <NUM_LIT> } <EOL> rslvr = resolver . Resolver ( config , scalars ) <EOL> services = rslvr . do ( ) <EOL> logger = services [ '<STR_LIT>' ] <EOL> assert isinstance ( logger , TestLogger ) <EOL> self . assertEquals ( <EOL> { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT:port>' : <NUM_LIT> <EOL> } , <EOL> logger . config <EOL> ) <EOL> def test_do_complicated ( self ) : <EOL> """<STR_LIT>""" <EOL> config = get_config_yaml ( ) <EOL> rslvr = resolver . Resolver ( config ) <EOL> services = rslvr . do ( ) <EOL> assert isinstance ( services [ '<STR_LIT:foo>' ] , Foo ) <EOL> assert isinstance ( services [ '<STR_LIT:bar>' ] , Bar ) <EOL> assert isinstance ( services [ '<STR_LIT>' ] , Baz ) <EOL> assert isinstance ( services [ '<STR_LIT>' ] , Qux ) <EOL> assert isinstance ( services [ '<STR_LIT>' ] , Wobble ) <EOL> assert isinstance ( services [ '<STR_LIT>' ] , Spam ) <EOL> spam = services [ '<STR_LIT>' ] <EOL> self . assertEquals ( spam . ham , '<STR_LIT>' ) <EOL> self . assertEquals ( spam . eggs , '<STR_LIT>' ) <EOL> wobble = services [ '<STR_LIT>' ] <EOL> assert isinstance ( wobble . foo , Foo ) <EOL> assert isinstance ( wobble . bar , Bar ) <EOL> assert isinstance ( wobble . baz , Baz ) <EOL> assert isinstance ( wobble . spam , Spam ) </s>
