<s> import unittest <EOL> from pybuilder . core import Logger <EOL> from pybuilder . errors import MissingTaskDependencyException , CircularTaskDependencyException , NoSuchTaskException , MissingActionDependencyException , InvalidNameException , RequiredTaskExclusionException <EOL> from pybuilder . execution import as_task_name_list , Action , Executable , ExecutionManager , Task , DependenciesNotResolvedException , Initializer , TaskDependency <EOL> from test_utils import Mock , ANY , call <EOL> class AsTaskNameList ( unittest . TestCase ) : <EOL> def test_should_return_list_of_strings_when_string_given ( self ) : <EOL> self . assertEquals ( [ "<STR_LIT>" ] , as_task_name_list ( "<STR_LIT>" ) ) <EOL> def test_should_return_list_of_strings_when_list_of_strings_given ( self ) : <EOL> self . assertEquals ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , as_task_name_list ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_should_return_list_of_strings_when_function_given ( self ) : <EOL> def spam ( ) : <EOL> pass <EOL> self . assertEquals ( [ "<STR_LIT>" ] , as_task_name_list ( spam ) ) <EOL> def test_should_return_list_of_strings_when_list_of_functions_given ( self ) : <EOL> def spam ( ) : <EOL> pass <EOL> def eggs ( ) : <EOL> pass <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" ] , as_task_name_list ( [ spam , eggs ] ) ) <EOL> class ExecutableTest ( unittest . TestCase ) : <EOL> def test_should_raise_exception_when_passing_non_function_to_constructor ( self ) : <EOL> self . assertRaises ( TypeError , Executable , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_should_raise_exception_when_executable_name_is_invalid ( self ) : <EOL> def callable ( ) : <EOL> pass <EOL> self . assertRaises ( InvalidNameException , Executable , "<STR_LIT>" , callable ) <EOL> self . assertRaises ( InvalidNameException , Executable , "<STR_LIT>" , callable ) <EOL> self . assertRaises ( <EOL> InvalidNameException , Executable , "<STR_LIT>" , callable ) <EOL> self . assertRaises ( InvalidNameException , Executable , "<STR_LIT:@>" , callable ) <EOL> self . assertRaises ( InvalidNameException , Executable , "<STR_LIT:$>" , callable ) <EOL> self . assertRaises ( InvalidNameException , Executable , "<STR_LIT:%>" , callable ) <EOL> def test_should_execute_callable_without_arguments ( self ) : <EOL> def callable ( ) : <EOL> callable . called = True <EOL> callable . called = False <EOL> Executable ( "<STR_LIT>" , callable ) . execute ( { } ) <EOL> self . assertTrue ( callable . called ) <EOL> def test_should_execute_callable_with_single_arguments ( self ) : <EOL> def callable ( spam ) : <EOL> callable . called = True <EOL> callable . spam = spam <EOL> callable . called = False <EOL> Executable ( "<STR_LIT>" , callable ) . execute ( { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertTrue ( callable . called ) <EOL> self . assertEquals ( "<STR_LIT>" , callable . spam ) <EOL> def test_should_raise_exception_when_callable_argument_cannot_be_satisfied ( self ) : <EOL> def callable ( spam ) : <EOL> pass <EOL> executable = Executable ( "<STR_LIT>" , callable ) <EOL> self . assertRaises ( ValueError , executable . execute , { } ) <EOL> class ActionTest ( unittest . TestCase ) : <EOL> def test_should_initialize_fields ( self ) : <EOL> def callable ( ) : <EOL> pass <EOL> action = Action ( "<STR_LIT>" , callable , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:description>" ) <EOL> self . assertEquals ( [ "<STR_LIT>" ] , action . execute_before ) <EOL> self . assertEquals ( [ "<STR_LIT>" ] , action . execute_after ) <EOL> self . assertEquals ( "<STR_LIT:description>" , action . description ) <EOL> class TaskTest ( unittest . TestCase ) : <EOL> def test_should_sort_tasks_by_name ( self ) : <EOL> task_a = Task ( "<STR_LIT>" , lambda : None , "<STR_LIT>" , "<STR_LIT:description>" ) <EOL> task_b = Task ( "<STR_LIT>" , lambda : None , "<STR_LIT>" , "<STR_LIT:description>" ) <EOL> task_list = [ task_b , task_a ] <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" ] , [ <EOL> task . name for task in sorted ( task_list ) ] ) <EOL> def test_should_initialize_fields ( self ) : <EOL> def callable ( ) : <EOL> pass <EOL> task = Task ( "<STR_LIT>" , callable , "<STR_LIT>" , "<STR_LIT:description>" ) <EOL> self . assertEquals ( [ "<STR_LIT>" ] , task . dependencies ) <EOL> self . assertEquals ( [ "<STR_LIT:description>" ] , task . description ) <EOL> def test_should_execute_callable_without_arguments ( self ) : <EOL> def callable ( ) : <EOL> callable . called = True <EOL> callable . called = False <EOL> Task ( "<STR_LIT>" , callable ) . execute ( Mock ( ) , { } ) <EOL> self . assertTrue ( callable . called ) <EOL> def test_should_execute_callable_with_single_arguments ( self ) : <EOL> def callable ( spam ) : <EOL> callable . called = True <EOL> callable . spam = spam <EOL> callable . called = False <EOL> Task ( "<STR_LIT>" , callable ) . execute ( Mock ( ) , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertTrue ( callable . called ) <EOL> self . assertEquals ( "<STR_LIT>" , callable . spam ) <EOL> def test_should_raise_exception_when_callable_argument_cannot_be_satisfied ( self ) : <EOL> def callable ( spam ) : <EOL> pass <EOL> executable = Task ( "<STR_LIT>" , callable ) <EOL> self . assertRaises ( ValueError , executable . execute , Mock ( ) , { } ) <EOL> class TaskExtensionTest ( unittest . TestCase ) : <EOL> def test_should_extend_task_with_values_from_other_task ( self ) : <EOL> def callable_one ( ) : <EOL> pass <EOL> def callable_two ( param ) : <EOL> pass <EOL> task = Task ( "<STR_LIT>" , callable_one , "<STR_LIT>" , "<STR_LIT:description>" ) <EOL> replacement = Task ( "<STR_LIT>" , callable_two , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> task . extend ( replacement ) <EOL> self . assertEquals ( "<STR_LIT>" , task . name ) <EOL> self . assertEquals ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] , task . dependencies ) <EOL> self . assertEquals ( <EOL> [ "<STR_LIT:description>" , "<STR_LIT>" ] , task . description ) <EOL> def test_should_execute_both_callables_when_extending_task ( self ) : <EOL> def callable_one ( ) : <EOL> callable_one . called = True <EOL> callable_one . called = False <EOL> def callable_two ( param ) : <EOL> callable_two . called = True <EOL> callable_two . called = False <EOL> task_one = Task ( "<STR_LIT>" , callable_one ) <EOL> task_two = Task ( "<STR_LIT>" , callable_two ) <EOL> task_one . extend ( task_two ) <EOL> task_one . execute ( Mock ( ) , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertTrue ( callable_one . called ) <EOL> self . assertTrue ( callable_two . called ) <EOL> class InitializerTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> def callable ( ) : <EOL> pass <EOL> self . callable = callable <EOL> def test_should_return_true_when_invoking_is_applicable_without_environment_and_initializer_does_not_define_environments ( <EOL> self ) : <EOL> initializer = Initializer ( "<STR_LIT>" , self . callable ) <EOL> self . assertTrue ( initializer . is_applicable ( ) ) <EOL> def test_should_return_true_when_invoking_is_applicable_with_environment_and_initializer_does_not_define_environments ( <EOL> self ) : <EOL> initializer = Initializer ( "<STR_LIT>" , self . callable ) <EOL> self . assertTrue ( initializer . is_applicable ( "<STR_LIT>" ) ) <EOL> def test_should_return_true_when_invoking_is_applicable_with_environment_and_initializer_defines_environment ( self ) : <EOL> initializer = Initializer ( <EOL> "<STR_LIT>" , self . callable , "<STR_LIT>" ) <EOL> self . assertTrue ( initializer . is_applicable ( "<STR_LIT>" ) ) <EOL> def test_should_return_true_when_invoking_is_applicable_with_environments_and_initializer_defines_environment ( self ) : <EOL> initializer = Initializer ( <EOL> "<STR_LIT>" , self . callable , "<STR_LIT>" ) <EOL> self . assertTrue ( initializer . is_applicable ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_should_return_false_when_invoking_is_applicable_with_environment_and_initializer_defines_environment ( self ) : <EOL> initializer = Initializer ( <EOL> "<STR_LIT>" , self . callable , "<STR_LIT>" ) <EOL> self . assertFalse ( initializer . is_applicable ( "<STR_LIT>" ) ) <EOL> def test_should_return_false_when_invoking_is_applicable_without_environment_and_initializer_defines_environment ( <EOL> self ) : <EOL> initializer = Initializer ( <EOL> "<STR_LIT>" , self . callable , "<STR_LIT>" ) <EOL> self . assertFalse ( initializer . is_applicable ( ) ) <EOL> def test_should_return_true_when_invoking_is_applicable_with_environment_and_initializer_defines_multiple_environments ( <EOL> self ) : <EOL> initializer = Initializer ( <EOL> "<STR_LIT>" , self . callable , [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertTrue ( initializer . is_applicable ( [ "<STR_LIT>" ] ) ) <EOL> class ExecutionManagerTestBase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . execution_manager = ExecutionManager ( Mock ( Logger ) ) <EOL> class ExecutionManagerInitializerTest ( ExecutionManagerTestBase ) : <EOL> def test_ensure_that_initializer_is_added_when_calling_register_initializer ( self ) : <EOL> initializer = Mock ( ) <EOL> self . execution_manager . register_initializer ( initializer ) <EOL> self . assertEquals ( [ initializer ] , self . execution_manager . initializers ) <EOL> def test_ensure_that_registered_initializers_are_executed_when_calling_execute_initializers ( self ) : <EOL> initializer_1 = Mock ( ) <EOL> initializer_1 . is_applicable . return_value = True <EOL> self . execution_manager . register_initializer ( initializer_1 ) <EOL> initializer_2 = Mock ( ) <EOL> initializer_2 . is_applicable . return_value = True <EOL> self . execution_manager . register_initializer ( initializer_2 ) <EOL> self . execution_manager . execute_initializers ( a = <NUM_LIT:1> ) <EOL> initializer_1 . execute . assert_called_with ( { "<STR_LIT:a>" : <NUM_LIT:1> } ) <EOL> initializer_2 . execute . assert_called_with ( { "<STR_LIT:a>" : <NUM_LIT:1> } ) <EOL> def test_ensure_that_registered_initializers_are_not_executed_when_environments_do_not_match ( self ) : <EOL> initializer = Mock ( ) <EOL> initializer . is_applicable . return_value = False <EOL> self . execution_manager . register_initializer ( initializer ) <EOL> environments = [ ] <EOL> self . execution_manager . execute_initializers ( environments , a = <NUM_LIT:1> ) <EOL> initializer . is_applicable . assert_called_with ( environments ) <EOL> initializer . execute . assert_not_called ( ) <EOL> class ExecutionManagerTaskTest ( ExecutionManagerTestBase ) : <EOL> def test_ensure_task_is_added_when_calling_register_task ( self ) : <EOL> task = Mock ( ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . assertEquals ( [ task ] , self . execution_manager . tasks ) <EOL> def test_ensure_task_is_replaced_when_registering_two_tasks_with_same_name ( self ) : <EOL> original = Mock ( name = "<STR_LIT>" ) <EOL> replacement = Mock ( name = "<STR_LIT>" ) <EOL> self . execution_manager . register_task ( original ) <EOL> self . execution_manager . register_task ( replacement ) <EOL> original . extend . assert_called_with ( replacement ) <EOL> def test_should_raise_exception_when_calling_execute_task_before_resolve_dependencies ( self ) : <EOL> self . assertRaises ( DependenciesNotResolvedException , <EOL> self . execution_manager . execute_task , <EOL> Mock ( ) ) <EOL> def test_ensure_task_is_executed_when_calling_execute_task ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_task ( task , a = <NUM_LIT:1> ) <EOL> task . execute . assert_called_with ( ANY , { "<STR_LIT:a>" : <NUM_LIT:1> } ) <EOL> def test_ensure_before_action_is_executed_when_task_is_executed ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> action = Mock ( name = "<STR_LIT:action>" , execute_before = [ "<STR_LIT>" ] , execute_after = [ ] ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_task ( task ) <EOL> action . execute . assert_called_with ( { } ) <EOL> task . execute . assert_called_with ( ANY , { } ) <EOL> def test_ensure_after_action_is_executed_when_task_is_executed ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> action = Mock ( name = "<STR_LIT:action>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_task ( task ) <EOL> action . execute . assert_called_with ( { } ) <EOL> task . execute . assert_called_with ( ANY , { } ) <EOL> def test_ensure_after_action_teardown_is_executed_when_task_fails ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> task . execute . side_effect = ValueError ( "<STR_LIT>" ) <EOL> action = Mock ( name = "<STR_LIT:action>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = True ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> try : <EOL> self . execution_manager . execute_task ( task ) <EOL> self . assertTrue ( False , "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . assertEquals ( type ( e ) , ValueError ) <EOL> self . assertEquals ( str ( e ) , "<STR_LIT>" ) <EOL> action . execute . assert_called_with ( { } ) <EOL> task . execute . assert_called_with ( ANY , { } ) <EOL> def test_ensure_after_action_teardown_is_executed_when_action_fails ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> action_regular = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = False ) <EOL> action_regular . name = "<STR_LIT>" <EOL> action_regular . execute . side_effect = ValueError ( "<STR_LIT>" ) <EOL> action_teardown = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = True ) <EOL> action_after_teardown = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , <EOL> teardown = False ) <EOL> self . execution_manager . register_action ( action_regular ) <EOL> self . execution_manager . register_action ( action_teardown ) <EOL> self . execution_manager . register_action ( action_after_teardown ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> try : <EOL> self . execution_manager . execute_task ( task ) <EOL> self . assertTrue ( False , "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . assertEquals ( type ( e ) , ValueError ) <EOL> self . assertEquals ( str ( e ) , "<STR_LIT>" ) <EOL> task . execute . assert_called_with ( ANY , { } ) <EOL> action_regular . execute . assert_called_with ( { } ) <EOL> action_teardown . execute . assert_called_with ( { } ) <EOL> action_after_teardown . execute . assert_not_called ( ) <EOL> def test_ensure_after_action_teardown_suppression_works_when_action_fails ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> action_regular = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = False ) <EOL> action_regular . name = "<STR_LIT>" <EOL> action_regular . execute . side_effect = ValueError ( "<STR_LIT>" ) <EOL> action_teardown = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = True ) <EOL> action_after_teardown = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , <EOL> teardown = False ) <EOL> self . execution_manager . register_action ( action_regular ) <EOL> self . execution_manager . register_action ( action_teardown ) <EOL> self . execution_manager . register_action ( action_after_teardown ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> try : <EOL> self . execution_manager . execute_task ( task ) <EOL> self . assertTrue ( False , "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . assertEquals ( type ( e ) , ValueError ) <EOL> self . assertEquals ( str ( e ) , "<STR_LIT>" ) <EOL> task . execute . assert_called_with ( ANY , { } ) <EOL> action_regular . execute . assert_called_with ( { } ) <EOL> action_teardown . execute . assert_called_with ( { } ) <EOL> action_after_teardown . execute . assert_not_called ( ) <EOL> def test_ensure_after_action_teardown_is_executed_and_suppresses ( self ) : <EOL> task = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> task . execute . side_effect = ValueError ( "<STR_LIT>" ) <EOL> action_teardown1 = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = True , <EOL> source = "<STR_LIT>" ) <EOL> action_teardown1 . execute . side_effect = ValueError ( "<STR_LIT>" ) <EOL> action_teardown2 = Mock ( name = "<STR_LIT>" , execute_before = [ ] , execute_after = [ "<STR_LIT>" ] , teardown = True , <EOL> source = "<STR_LIT>" ) <EOL> self . execution_manager . register_action ( action_teardown1 ) <EOL> self . execution_manager . register_action ( action_teardown2 ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> try : <EOL> self . execution_manager . execute_task ( task ) <EOL> self . assertTrue ( False , "<STR_LIT>" ) <EOL> except Exception as e : <EOL> self . assertEquals ( type ( e ) , ValueError ) <EOL> self . assertEquals ( str ( e ) , "<STR_LIT>" ) <EOL> task . execute . assert_called_with ( ANY , { } ) <EOL> action_teardown1 . execute . assert_called_with ( { } ) <EOL> action_teardown2 . execute . assert_called_with ( { } ) <EOL> self . execution_manager . logger . error . assert_called_with ( <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , ANY ) <EOL> def test_should_return_single_task_name ( self ) : <EOL> self . execution_manager . register_task ( Mock ( name = "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ "<STR_LIT>" ] , self . execution_manager . task_names ) <EOL> def test_should_return_all_task_names ( self ) : <EOL> self . execution_manager . register_task ( <EOL> Mock ( name = "<STR_LIT>" ) , Mock ( name = "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ "<STR_LIT>" , "<STR_LIT>" ] , self . execution_manager . task_names ) <EOL> class ExecutionManagerActionTest ( ExecutionManagerTestBase ) : <EOL> def test_ensure_action_is_registered ( self ) : <EOL> action = Mock ( name = "<STR_LIT:action>" ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . assertEquals ( { "<STR_LIT:action>" : action } , self . execution_manager . _actions ) <EOL> def test_ensure_action_registered_for_two_tasks_is_executed_two_times ( self ) : <EOL> spam = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> eggs = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( spam , eggs ) <EOL> action = Mock ( name = "<STR_LIT:action>" , <EOL> execute_before = [ ] , <EOL> execute_after = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> only_once = False ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_execution_plan ( [ spam , eggs ] ) <EOL> action . execute . assert_has_calls ( [ call ( ANY ) , call ( ANY ) ] ) <EOL> def test_ensure_action_registered_for_two_tasks_is_executed_only_once_if_single_attribute_is_present ( self ) : <EOL> spam = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> eggs = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( spam , eggs ) <EOL> action = Mock ( name = "<STR_LIT:action>" , <EOL> execute_before = [ ] , <EOL> execute_after = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> only_once = True ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_execution_plan ( [ spam , eggs ] ) <EOL> action . execute . assert_called_with ( ANY ) <EOL> class ExecutionManagerResolveDependenciesTest ( ExecutionManagerTestBase ) : <EOL> def test_ensure_that_dependencies_are_resolved_when_no_task_is_given ( self ) : <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertTrue ( self . execution_manager . _dependencies_resolved ) <EOL> def test_ensure_that_dependencies_are_resolved_when_single_task_is_given ( self ) : <EOL> task = Mock ( dependencies = [ ] ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertTrue ( self . execution_manager . _dependencies_resolved ) <EOL> def test_should_raise_exception_when_task_depends_on_task_not_found ( self ) : <EOL> task = Mock ( dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( task ) <EOL> self . assertRaises ( MissingTaskDependencyException , <EOL> self . execution_manager . resolve_dependencies ) <EOL> def test_should_raise_exception_when_before_action_depends_on_task_not_found ( self ) : <EOL> action = Mock ( execute_before = [ "<STR_LIT>" ] , execute_after = [ ] ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . assertRaises ( MissingActionDependencyException , <EOL> self . execution_manager . resolve_dependencies ) <EOL> def test_should_raise_exception_when_after_action_depends_on_task_not_found ( self ) : <EOL> action = Mock ( execute_before = [ ] , execute_after = [ "<STR_LIT>" ] ) <EOL> self . execution_manager . register_action ( action ) <EOL> self . assertRaises ( MissingActionDependencyException , <EOL> self . execution_manager . resolve_dependencies ) <EOL> def test_ensure_that_dependencies_are_resolved_when_simple_dependency_is_found ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_ensure_that_dependencies_are_resolved_when_task_depends_on_multiple_tasks ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( <EOL> [ TaskDependency ( one ) , TaskDependency ( two ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_override_optional_dependency_with_required ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" , True ) , TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_ignore_required_override_with_optional_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" , True ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_ignore_second_optional_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" , True ) , TaskDependency ( "<STR_LIT>" , True ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one , True ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_ignore_second_required_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_verify_late_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . register_task ( three ) <EOL> self . execution_manager . register_late_task_dependencies ( { "<STR_LIT>" : [ TaskDependency ( "<STR_LIT>" ) ] } ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) , TaskDependency ( three ) ] , <EOL> self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , <EOL> self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_verify_duplicate_late_dependency_removed ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . register_task ( three ) <EOL> self . execution_manager . register_late_task_dependencies ( <EOL> { "<STR_LIT>" : [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" ) ] } ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ ] , self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) , TaskDependency ( three ) ] , <EOL> self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> self . assertEquals ( [ TaskDependency ( one ) ] , <EOL> self . execution_manager . _task_dependencies . get ( "<STR_LIT>" ) ) <EOL> def test_verify_error_unresolved_late_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . register_task ( three ) <EOL> self . execution_manager . register_late_task_dependencies ( <EOL> { "<STR_LIT>" : [ TaskDependency ( "<STR_LIT>" ) ] } ) <EOL> self . assertRaises ( NoSuchTaskException , self . execution_manager . resolve_dependencies ) <EOL> class ExecutionManagerBuildExecutionPlanTest ( ExecutionManagerTestBase ) : <EOL> def test_should_collect_all_tasks_when_there_are_no_dependencies ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( self . execution_manager . collect_all_transitive_tasks ( [ "<STR_LIT>" ] ) , set ( [ one ] ) ) <EOL> def test_should_collect_all_tasks_when_there_is_a_simple_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( self . execution_manager . collect_all_transitive_tasks ( [ "<STR_LIT>" ] ) , set ( [ one , two ] ) ) <EOL> def test_should_collect_all_tasks_when_there_is_a_transitive_dependency ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( self . execution_manager . collect_all_transitive_tasks ( [ "<STR_LIT>" ] ) , set ( [ one , two , three ] ) ) <EOL> def test_should_collect_all_tasks_when_several_tasks_given ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( self . execution_manager . collect_all_transitive_tasks ( [ "<STR_LIT>" , "<STR_LIT>" ] ) , set ( [ one , two , three ] ) ) <EOL> def test_should_only_collect_required_tasks ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( self . execution_manager . collect_all_transitive_tasks ( [ "<STR_LIT>" ] ) , set ( [ one , three ] ) ) <EOL> def test_should_raise_exception_when_building_execution_plan_and_dependencies_are_not_resolved ( self ) : <EOL> self . assertRaises ( DependenciesNotResolvedException , <EOL> self . execution_manager . build_execution_plan , ( "<STR_LIT>" , ) ) <EOL> def test_should_raise_exception_when_building_execution_plan_for_task_not_found ( self ) : <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertRaises ( <EOL> NoSuchTaskException , self . execution_manager . build_execution_plan , ( "<STR_LIT>" , ) ) <EOL> def test_should_return_execution_plan_with_single_task_when_single_task_is_to_be_executed ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( <EOL> [ one ] , self . execution_manager . build_execution_plan ( [ "<STR_LIT>" ] ) ) <EOL> def test_should_return_execution_plan_with_two_tasks_when_two_tasks_are_to_be_executed ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( <EOL> [ one , two ] , self . execution_manager . build_execution_plan ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_ensure_that_dependencies_are_executed_before_root_task ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( <EOL> [ one , two ] , self . execution_manager . build_execution_plan ( [ "<STR_LIT>" ] ) ) <EOL> def test_ensure_that_tasks_are_not_executed_multiple_times ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] , ) <EOL> self . execution_manager . register_task ( one ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( <EOL> [ one ] , self . execution_manager . build_execution_plan ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_ensure_that_tasks_are_not_executed_multiple_times_when_being_dependencies ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEqual ( <EOL> [ one , two ] , self . execution_manager . build_execution_plan ( [ "<STR_LIT>" , "<STR_LIT>" ] ) ) <EOL> def test_should_raise_exception_when_circular_reference_is_detected_on_single_task ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertRaises ( CircularTaskDependencyException , <EOL> self . execution_manager . build_execution_plan , [ "<STR_LIT>" ] ) <EOL> def test_should_raise_exception_when_circular_reference_is_detected_on_two_tasks ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertRaises ( CircularTaskDependencyException , <EOL> self . execution_manager . build_execution_plan , [ "<STR_LIT>" ] ) <EOL> def test_should_raise_exception_when_circular_reference_is_detected_on_three_tasks ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertRaises ( CircularTaskDependencyException , <EOL> self . execution_manager . build_execution_plan , [ "<STR_LIT>" ] ) <EOL> def test_should_raise_exception_when_circular_reference_is_detected_on_indirect_required_tasks ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertRaises ( CircularTaskDependencyException , <EOL> self . execution_manager . build_execution_plan , [ "<STR_LIT>" ] ) <EOL> def test_shortest_execution_plan_is_shortest ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . assertEquals ( [ one , two ] , self . execution_manager . build_execution_plan ( "<STR_LIT>" ) ) <EOL> self . execution_manager . _tasks_executed . append ( one ) <EOL> self . execution_manager . _tasks_executed . append ( two ) <EOL> self . assertEquals ( [ three ] , self . execution_manager . build_shortest_execution_plan ( "<STR_LIT>" ) ) <EOL> def test_shortest_execution_plan_always_executes_target ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . _tasks_executed . append ( one ) <EOL> self . execution_manager . _tasks_executed . append ( two ) <EOL> self . assertEquals ( [ three ] , self . execution_manager . build_shortest_execution_plan ( "<STR_LIT>" ) ) <EOL> self . execution_manager . _tasks_executed . append ( three ) <EOL> self . assertEquals ( [ three ] , self . execution_manager . build_shortest_execution_plan ( "<STR_LIT>" ) ) <EOL> def test_shortest_execution_plan_checks_circularity ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . _tasks_executed . append ( one ) <EOL> self . execution_manager . _current_task = two <EOL> self . assertRaises ( CircularTaskDependencyException , self . execution_manager . build_shortest_execution_plan , <EOL> [ "<STR_LIT>" ] ) <EOL> def test_shortest_execution_plan_reruns_on_demand ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . _tasks_executed . append ( one ) <EOL> self . execution_manager . _tasks_executed . append ( two ) <EOL> self . assertEquals ( [ two , three ] , self . execution_manager . build_shortest_execution_plan ( ( "<STR_LIT>" , "<STR_LIT>" ) ) ) <EOL> self . assertEquals ( [ two , three ] , self . execution_manager . build_shortest_execution_plan ( ( "<STR_LIT>" , "<STR_LIT>" ) ) ) <EOL> self . assertEquals ( [ one , two , three ] , self . execution_manager . build_shortest_execution_plan ( ( "<STR_LIT>" , "<STR_LIT>" ) ) ) <EOL> def test_ensure_that_optional_tasks_are_excluded ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" , True ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( exclude_optional_tasks = [ "<STR_LIT>" ] ) <EOL> execution_plan = self . execution_manager . build_execution_plan ( "<STR_LIT>" ) <EOL> self . assertEquals ( [ two ] , execution_plan ) <EOL> def test_ensure_that_optional_branch_is_excluded ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" , True ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( exclude_optional_tasks = [ "<STR_LIT>" ] ) <EOL> execution_plan = self . execution_manager . build_execution_plan ( "<STR_LIT>" ) <EOL> self . assertEquals ( [ three ] , execution_plan ) <EOL> def test_ensure_that_required_tasks_are_force_excluded ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( exclude_tasks = [ "<STR_LIT>" ] ) <EOL> execution_plan = self . execution_manager . build_execution_plan ( "<STR_LIT>" ) <EOL> self . assertEquals ( [ two ] , execution_plan ) <EOL> def test_ensure_that_required_branch_is_force_excluded ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( exclude_tasks = [ "<STR_LIT>" ] ) <EOL> execution_plan = self . execution_manager . build_execution_plan ( "<STR_LIT>" ) <EOL> self . assertEquals ( [ three ] , execution_plan ) <EOL> def test_ensure_that_required_tasks_are_not_optionally_excluded ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( exclude_optional_tasks = [ "<STR_LIT>" ] ) <EOL> self . assertRaises ( RequiredTaskExclusionException , self . execution_manager . build_execution_plan , "<STR_LIT>" ) <EOL> def test_ensure_that_required_tasks_branch_not_optionally_excluded ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( exclude_optional_tasks = [ "<STR_LIT>" ] ) <EOL> self . assertRaises ( RequiredTaskExclusionException , self . execution_manager . build_execution_plan , "<STR_LIT>" ) <EOL> def test_is_task_in_current_execution_plan ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) , TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( exclude_all_optional = True ) <EOL> self . execution_manager . _current_execution_plan = self . execution_manager . build_execution_plan ( "<STR_LIT>" ) <EOL> self . assertTrue ( self . execution_manager . is_task_in_current_execution_plan ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( self . execution_manager . is_task_in_current_execution_plan ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( self . execution_manager . is_task_in_current_execution_plan ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( self . execution_manager . is_task_in_current_execution_plan ( "<STR_LIT>" ) ) <EOL> class ExecutionManagerExecuteExecutionPlanTest ( ExecutionManagerTestBase ) : <EOL> def test_should_raise_exception_when_dependencies_are_not_resolved ( self ) : <EOL> self . assertRaises ( DependenciesNotResolvedException , <EOL> self . execution_manager . execute_execution_plan , [ "<STR_LIT>" ] ) <EOL> def test_ensure_tasks_are_executed ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> self . execution_manager . register_task ( one , two ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_execution_plan ( [ one , two ] ) <EOL> one . execute . assert_called_with ( ANY , { } ) <EOL> two . execute . assert_called_with ( ANY , { } ) <EOL> def test_shortest_execution_plan_executed ( self ) : <EOL> one = Mock ( name = "<STR_LIT>" , dependencies = [ ] ) <EOL> two = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> three = Mock ( name = "<STR_LIT>" , dependencies = [ TaskDependency ( "<STR_LIT>" ) ] ) <EOL> self . execution_manager . register_task ( one , two , three ) <EOL> self . execution_manager . resolve_dependencies ( ) <EOL> self . execution_manager . execute_execution_plan ( self . execution_manager . build_execution_plan ( "<STR_LIT>" ) ) <EOL> one . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> two . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> three . execute . assert_not_called ( ) <EOL> self . execution_manager . execute_execution_plan ( self . execution_manager . build_shortest_execution_plan ( "<STR_LIT>" ) ) <EOL> one . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> two . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> three . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> self . execution_manager . execute_execution_plan ( self . execution_manager . build_shortest_execution_plan ( "<STR_LIT>" ) ) <EOL> one . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> two . execute . assert_has_calls ( [ call ( ANY , { } ) ] ) <EOL> three . execute . assert_has_calls ( [ call ( ANY , { } ) , call ( ANY , { } ) ] ) </s>
