def test_cleanup(self): # ARRANGE # cases = { STEP__MAIN: { EXECUTION__HARD_ERROR: cleanup_phase_instruction_that(main=SH_HARD_ERROR), EXECUTION__INTERNAL_ERROR: cleanup_phase_instruction_that( main_initial_action=DO_RAISES_EXCEPTION), }, } # ACT & ASSERT # self._check_and_assert_sds_is_preserved_and_is_printed( phase_identifier.CLEANUP, cases)
def test_cleanup(self): # ARRANGE # cases = { EXECUTION__VALIDATION_ERROR: cleanup_phase_instruction_that(validate_pre_sds=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: cleanup_phase_instruction_that(validate_pre_sds=SVH_HARD_ERROR), EXECUTION__IMPLEMENTATION_ERROR: cleanup_phase_instruction_that(validate_pre_sds_initial_action=DO_RAISES_EXCEPTION), } # ACT & ASSERT # self._check_and_assert_sds_is_not_created_and_stdout_is_empty(phase_identifier.CLEANUP, cases)
def test_cleanup(self): # ARRANGE # cases = { STEP__MAIN: { EXECUTION__HARD_ERROR: cleanup_phase_instruction_that(main=SH_HARD_ERROR), EXECUTION__IMPLEMENTATION_ERROR: cleanup_phase_instruction_that(main_initial_action=DO_RAISES_EXCEPTION), }, } # ACT & ASSERT # self._check_and_assert_sds_is_preserved_and_is_printed(phase_identifier.CLEANUP, cases)
def test_cleanup(self): # ARRANGE # cases = { EXECUTION__VALIDATION_ERROR: cleanup_phase_instruction_that( validate_pre_sds=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: cleanup_phase_instruction_that(validate_pre_sds=SVH_HARD_ERROR), EXECUTION__INTERNAL_ERROR: cleanup_phase_instruction_that( validate_pre_sds_initial_action=DO_RAISES_EXCEPTION), } # ACT & ASSERT # self._check_and_assert_sds_is_not_created_and_stdout_is_empty( phase_identifier.CLEANUP, cases)
def _test_case(self) -> test_case_doc.TestCase: return full_test_case_with_instructions( [configuration_phase_instruction_that( main_initial_action=_RecordCurrDir(self.recorder, phase_step.CONFIGURATION__MAIN))], [setup_phase_instruction_that( validate_post_setup_initial_action=_RecordCurrDir(self.recorder, phase_step.SETUP__VALIDATE_POST_SETUP), main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.SETUP__MAIN))], [act_phase_instruction_with_source(LineSequence(1, ('not used',)))], [before_assert_phase_instruction_that( validate_post_setup_initial_action=_RecordCurrDir(self.recorder, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.BEFORE_ASSERT__MAIN))], [assert_phase_instruction_that( validate_post_setup_initial_action=_RecordCurrDir(self.recorder, phase_step.ASSERT__VALIDATE_POST_SETUP), main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.ASSERT__MAIN))], [cleanup_phase_instruction_that( main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.CLEANUP__MAIN))], )
def test_that_symbols_from_arrangement_exist_in_environment(self): symbol_name = 'symbol_name_in_cleanup_phase' symbol_value = 'the symbol value in cleanup phase' symbol_table_of_arrangement = data_symbol_utils.symbol_table_with_single_string_value(symbol_name, symbol_value) expected_symbol_table = data_symbol_utils.symbol_table_with_single_string_value(symbol_name, symbol_value) assertion_for_validation = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table, get_symbol_table_from_path_resolving_environment_that_is_first_arg) assertion_for_main = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table, get_symbol_table_from_instruction_environment_that_is_first_arg) self._check( utils.ParserThatGives( cleanup_phase_instruction_that( validate_pre_sds_initial_action=assertion_for_validation, main_initial_action=assertion_for_main, )), utils.single_line_source(), sut.Arrangement(symbols=symbol_table_of_arrangement), sut.Expectation(), )
def _test_case(self) -> test_case_doc.TestCase: return full_test_case_with_instructions( [configuration_phase_instruction_that( main_initial_action=_RecordCurrDir(self.recorder, phase_step.CONFIGURATION__MAIN).call)], [setup_phase_instruction_that( validate_post_setup_initial_action=_RecordCurrDir(self.recorder, phase_step.SETUP__VALIDATE_POST_SETUP), main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.SETUP__MAIN))], [act_phase_instruction_with_source(LineSequence(1, ('not used',)))], [before_assert_phase_instruction_that( validate_post_setup_initial_action=_RecordCurrDir(self.recorder, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.BEFORE_ASSERT__MAIN))], [assert_phase_instruction_that( validate_post_setup_initial_action=_RecordCurrDir(self.recorder, phase_step.ASSERT__VALIDATE_POST_SETUP), main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.ASSERT__MAIN))], [cleanup_phase_instruction_that( main_initial_action=_RecordCurrDirThenMakeDirAndChangeToIt(self.recorder, phase_step.CLEANUP__MAIN))], )
def cleanup_phase_instruction_that_records_a_value_per_step( recorder_for) -> CleanupPhaseInstruction: return cleanup_phase_instruction_that( validate_pre_sds_initial_action=recorder_for( step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=recorder_for(step.CLEANUP__MAIN), )
def test_instruction_environment_specifies_correct_tmp_dir_space_for_each_instruction( self): # ARRANGE # recorder = {} setup_phase_instr_that_records = setup_phase_instruction_that( validate_post_setup_initial_action= RecordTmpDirForInstructionInPhase(PhaseEnum.SETUP, recorder), main_initial_action=RecordTmpDirForInstructionInPhase( PhaseEnum.SETUP, recorder).call, ) before_assert_phase_instr_that_records = before_assert_phase_instruction_that( validate_post_setup_initial_action= RecordTmpDirForInstructionInPhase(PhaseEnum.BEFORE_ASSERT, recorder), main_initial_action=RecordTmpDirForInstructionInPhase( PhaseEnum.BEFORE_ASSERT, recorder).call) assert_phase_instr_that_records = assert_phase_instruction_that( validate_post_setup_initial_action= RecordTmpDirForInstructionInPhase(PhaseEnum.ASSERT, recorder), main_initial_action=RecordTmpDirForInstructionInPhase( PhaseEnum.ASSERT, recorder).call) cleanup_phase_instr_that_records = cleanup_phase_instruction_that( main_initial_action=RecordTmpDirForInstructionInPhase( PhaseEnum.CLEANUP, recorder).call) test_case = partial_test_case_with_instructions( [ setup_phase_instr_that_records, setup_phase_instr_that_records, ], [act_phase_instruction_with_source(LineSequence(1, ('line', )))], [ before_assert_phase_instr_that_records, before_assert_phase_instr_that_records, ], [ assert_phase_instr_that_records, assert_phase_instr_that_records, ], [ cleanup_phase_instr_that_records, cleanup_phase_instr_that_records, ], ) actor_that_registers_tmp_dirs = ActorThatRunsConstantActions( validate_post_setup_initial_action= RecordTmpDirForInstructionInPhase(PhaseEnum.ACT, recorder), prepare_initial_action=RecordTmpDirForInstructionInPhase( PhaseEnum.ACT, recorder), execute_initial_action=RecordTmpDirForInstructionInPhase( PhaseEnum.ACT, recorder), ) # ACT & ASSERT # test(self, test_case, actor_that_registers_tmp_dirs, functools.partial(tmp_dir_is_correct_for_each_instruction, recorder, 2), is_keep_sandbox=False)
def new_cleanup_instruction(self, value_for_symbol_usages, value_for_validate_pre_sds, first_value_of_pair_for_main) -> CleanupPhaseInstruction: return cleanup_phase_instruction_that( symbol_usages_initial_action=self._do_record_first_invokation(value_for_symbol_usages), validate_pre_sds=self._do_record_and_return_svh(value_for_validate_pre_sds), main=self._do_cleanup_main(first_value_of_pair_for_main))
def new_cleanup_instruction( self, value_for_symbol_usages, value_for_validate_pre_sds, first_value_of_pair_for_main) -> CleanupPhaseInstruction: return cleanup_phase_instruction_that( symbol_usages_initial_action=self._do_record_first_invokation( value_for_symbol_usages), validate_pre_sds=self._do_record_and_return_svh( value_for_validate_pre_sds), main=self._do_cleanup_main(first_value_of_pair_for_main))
def _test_case(self) -> test_case_doc.TestCase: return full_test_case_with_instructions( [ configuration_phase_instruction_that( main_initial_action= _ConfigurationPhaseActionThatSetsHdsCaseDirToParent()), configuration_phase_instruction_that( main_initial_action= _ConfigurationPhaseActionThatSetsHdsActDirToParentParent()) ], [ setup_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars( self.recorder, phase_step.SETUP__VALIDATE_PRE_SDS).call, validate_post_setup_initial_action=_RecordEnvVars( self.recorder, phase_step.SETUP__VALIDATE_POST_SETUP).call, main_initial_action=_RecordEnvVars( self.recorder, phase_step.SETUP__MAIN).setup_main) ], [], [ before_assert_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars( self.recorder, phase_step.BEFORE_ASSERT__VALIDATE_PRE_SDS).call, validate_post_setup_initial_action=_RecordEnvVars( self.recorder, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP).call, main_initial_action=_RecordEnvVars( self.recorder, phase_step.BEFORE_ASSERT__MAIN).non_setup_main) ], [ assert_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars( self.recorder, phase_step.ASSERT__VALIDATE_PRE_SDS).call, validate_post_setup_initial_action=_RecordEnvVars( self.recorder, phase_step.ASSERT__VALIDATE_POST_SETUP).call, main_initial_action=_RecordEnvVars( self.recorder, phase_step.ASSERT__MAIN).non_setup_main) ], [ cleanup_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars( self.recorder, phase_step.CLEANUP__VALIDATE_PRE_SDS).call, main_initial_action=_RecordEnvVars( self.recorder, phase_step.CLEANUP__MAIN).non_setup_main) ], )
def test_that_default_expectation_assumes_no_symbol_usages(self): with self.assertRaises(utils.TestError): unexpected_symbol_usages = [data_symbol_utils.symbol_reference('symbol_name')] self._check( utils.ParserThatGives( cleanup_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), utils.single_line_source(), sut.Arrangement(), sut.Expectation(), )
def test_that_fails_due_to_missing_symbol_reference(self): with self.assertRaises(utils.TestError): symbol_usages_of_instruction = [] symbol_usages_of_expectation = [data_symbol_utils.symbol_reference('symbol_name')] self._check( utils.ParserThatGives( cleanup_phase_instruction_that( symbol_usages=do_return(symbol_usages_of_instruction))), utils.single_line_source(), sut.Arrangement(), sut.Expectation( symbol_usages=sym_asrt.equals_symbol_references(symbol_usages_of_expectation)), )
def test_that_default_expectation_assumes_no_symbol_usages(self): with self.assertRaises(utils.TestError): unexpected_symbol_usages = [ data_references.reference_to__on_direct_and_indirect( 'symbol_name') ] self._check( utils.ParserThatGives( cleanup_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), utils.single_line_source(), sut.Arrangement(), sut.Expectation(), )
def test_that_fails_due_to_missing_symbol_reference(self): with self.assertRaises(utils.TestError): symbol_usages_of_instruction = [] self._check( utils.ParserThatGives( cleanup_phase_instruction_that(symbol_usages=do_return( symbol_usages_of_instruction))), utils.single_line_source(), sut.Arrangement(), sut.Expectation(symbol_usages=asrt.matches_singleton_sequence( matches_data_type_symbol_reference( 'symbol_name', reference_restrictions.is_any_type_w_str_rendering())) ), )
def test_instruction_environment_specifies_correct_log_dir_for_each_phase(self): recorder = {} test_case = partial_test_case_with_instructions( [setup_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.SETUP, recorder))], [act_phase_instruction_with_source(LineSequence(1, ('line',)))], [before_assert_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.BEFORE_ASSERT, recorder))], [assert_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.ASSERT, recorder))], [cleanup_phase_instruction_that(main_initial_action=RecordLogDirForPhase(PhaseEnum.CLEANUP, recorder))], ) test( self, test_case, dummy_actor(), functools.partial(log_dir_is_correct_for_each_phase, recorder), is_keep_sandbox=False)
def test_with_internal_error(self): test_case = test_case_with_two_instructions_in_each_phase() \ .add(phase_identifier.CONFIGURATION, test.ConfigurationPhaseInstructionThatSetsExecutionMode(TestCaseStatus.FAIL)) \ .add(phase_identifier.CLEANUP, test.cleanup_phase_instruction_that( main=do_raise(test.ImplementationErrorTestException()))) self._check( Arrangement( test_case, execute_test_action=execute_action_that_returns_exit_code( 128)), Expectation( asrt_result.matches2( FullExeResultStatus.INTERNAL_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code( 128), ExpectedFailureForInstructionFailure.new_with_exception( phase_step.CLEANUP__MAIN, test_case.the_extra( phase_identifier.CLEANUP)[0].source, test.ImplementationErrorTestException), ), [ phase_step.CONFIGURATION__MAIN, phase_step.CONFIGURATION__MAIN ] + [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [ phase_step.SETUP__MAIN, phase_step.SETUP__MAIN, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ACT__PREPARE, phase_step.ACT__EXECUTE, phase_step.BEFORE_ASSERT__MAIN, phase_step.BEFORE_ASSERT__MAIN, phase_step.ASSERT__MAIN, phase_step.ASSERT__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT), ], ))
def test_set_environment_variable_in_phase_cleanup(self): recorder = _RecorderOfExistenceOfGlobalEnvVar(_unique_variable_name()) test_case = partial_test_case_with_instructions( [], _act_phase_instructions_that_are_not_relevant_to_this_test(), [], [], [cleanup_phase_instruction_that( main_initial_action=Sequence([SetEnvironmentVariableViaInstructionArguments(recorder.variable_name), recorder.for_step(step.CLEANUP__MAIN)]))], ) test__va( self, test_case, Arrangement(actor=dummy_actor()), AssertPhasesWhereTheEnvironmentVariableExistsInTheGlobalEnvironmentIsEmpty(recorder.recorded_steps))
def test_with_implementation_error(self): test_case = test_case_with_two_instructions_in_each_phase() \ .add(phase_identifier.CONFIGURATION, test.ConfigurationPhaseInstructionThatSetsExecutionMode(TestCaseStatus.FAIL)) \ .add(phase_identifier.CLEANUP, test.cleanup_phase_instruction_that( main=do_raise(test.ImplementationErrorTestException()))) self._check( Arrangement(test_case, execute_test_action=execute_action_that_returns_exit_code(128)), Expectation( asrt_result.matches2( FullExeResultStatus.IMPLEMENTATION_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(128), ExpectedFailureForInstructionFailure.new_with_exception( phase_step.CLEANUP__MAIN, test_case.the_extra(phase_identifier.CLEANUP)[0].source, test.ImplementationErrorTestException), ), [phase_step.CONFIGURATION__MAIN, phase_step.CONFIGURATION__MAIN] + [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [phase_step.SETUP__MAIN, phase_step.SETUP__MAIN, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ACT__PREPARE, phase_step.ACT__EXECUTE, phase_step.BEFORE_ASSERT__MAIN, phase_step.BEFORE_ASSERT__MAIN, phase_step.ASSERT__MAIN, phase_step.ASSERT__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT), ], ))
def test_hard_error_in_cleanup_main_step(self): py_pgm_setup = PyProgramSetup('some output to stdout', 'some output to stderr', 72) test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr( act_phase_source=py_pgm_setup.as_line_sequence()) \ .add(PartialPhase.CLEANUP, test.cleanup_phase_instruction_that( main=do_return(sh.new_sh_hard_error('hard error msg from CLEANUP')))) self._check( arr_for_py3_source(test_case), Expectation( asrt_result.matches2( PartialExeResultStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(py_pgm_setup.exit_code), ExpectedFailureForInstructionFailure.new_with_message( phase_step.CLEANUP__MAIN, test_case.the_extra(PartialPhase.CLEANUP)[0].source, 'hard error msg from CLEANUP'), ), atc_stdout_output=asrt.equals(py_pgm_setup.stdout_output), atc_stderr_output=asrt.equals(py_pgm_setup.stderr_output), step_recordings= [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [phase_step.SETUP__MAIN, phase_step.SETUP__MAIN, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ACT__PREPARE, phase_step.ACT__EXECUTE, (phase_step.CLEANUP__MAIN, PreviousPhase.ACT), ], ))
def instruction_set() -> InstructionsSetup: return InstructionsSetup( config_instruction_set=dict( [instruction_item('conf_instruction', instr.configuration_phase_instruction_that())]), setup_instruction_set=dict( [instruction_item('setup_instruction', instr.setup_phase_instruction_that())]), before_assert_instruction_set=dict( [instruction_item('before_assert_instruction', instr.before_assert_phase_instruction_that())]), assert_instruction_set=dict( [instruction_item('assert_instruction', instr.assert_phase_instruction_that())]), cleanup_instruction_set=dict( [instruction_item('cleanup_instruction', instr.cleanup_phase_instruction_that())]), )
def test_implementation_error_in_cleanup_main_step(self): test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.CLEANUP, test.cleanup_phase_instruction_that( main=do_raise(test.ImplementationErrorTestException()))) self._check( Arrangement(test_case, act_executor_execute=execute_action_that_returns_exit_code(5)), Expectation( asrt_result.matches2( PartialExeResultStatus.IMPLEMENTATION_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(5), ExpectedFailureForInstructionFailure.new_with_exception( phase_step.CLEANUP__MAIN, test_case.the_extra(PartialPhase.CLEANUP)[0].source, test.ImplementationErrorTestException), ), [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [phase_step.SETUP__MAIN, phase_step.SETUP__MAIN, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ACT__PREPARE, phase_step.ACT__EXECUTE, phase_step.BEFORE_ASSERT__MAIN, phase_step.BEFORE_ASSERT__MAIN, phase_step.ASSERT__MAIN, phase_step.ASSERT__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT), ], ))
def test_hard_error_in_cleanup_main_step(self): py_pgm_setup = PyProgramSetup('some output to stdout', 'some output to stderr', 72) test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr( act_phase_source=py_pgm_setup.as_line_sequence()) \ .add(PartialPhase.CLEANUP, test.cleanup_phase_instruction_that( main=do_return(sh.new_sh_hard_error__str('hard error msg from CLEANUP')))) self._check( arr_for_py3_source(test_case), Expectation( asrt_result.matches2( ExecutionFailureStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code( py_pgm_setup.exit_code), ExpectedFailureForInstructionFailure.new_with_message( phase_step.CLEANUP__MAIN, test_case.the_extra(PartialPhase.CLEANUP)[0].source, 'hard error msg from CLEANUP'), ), atc_stdout_output=asrt.equals(py_pgm_setup.stdout_output), atc_stderr_output=asrt.equals(py_pgm_setup.stderr_output), step_recordings=[phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [ phase_step.SETUP__MAIN, phase_step.SETUP__MAIN, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_EXE_INPUT, phase_step.ACT__PREPARE, phase_step.ACT__EXECUTE, (phase_step.CLEANUP__MAIN, PreviousPhase.ACT), ], ))
def test_internal_error(self): test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.CLEANUP, test.cleanup_phase_instruction_that( main=do_raise(test.ImplementationErrorTestException()))) self._check( Arrangement(test_case, atc_execute=execute_action_that_returns_exit_code(5)), Expectation( asrt_result.matches2( ExecutionFailureStatus.INTERNAL_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(5), ExpectedFailureForInstructionFailure.new_with_exception( phase_step.CLEANUP__MAIN, test_case.the_extra(PartialPhase.CLEANUP)[0].source, test.ImplementationErrorTestException), ), [phase_step.ACT__PARSE] + SYMBOL_VALIDATION_STEPS__TWICE + PRE_SDS_VALIDATION_STEPS__TWICE + [ phase_step.SETUP__MAIN, phase_step.SETUP__MAIN, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.SETUP__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ASSERT__VALIDATE_POST_SETUP, phase_step.ACT__VALIDATE_EXE_INPUT, phase_step.ACT__PREPARE, phase_step.ACT__EXECUTE, phase_step.BEFORE_ASSERT__MAIN, phase_step.BEFORE_ASSERT__MAIN, phase_step.ASSERT__MAIN, phase_step.ASSERT__MAIN, (phase_step.CLEANUP__MAIN, PreviousPhase.ASSERT), ], ))
def test_set_environment_variable_in_phase_setup(self): recorder = _RecorderOfExistenceOfGlobalEnvVar(_unique_variable_name()) test_case = partial_test_case_with_instructions( [setup_phase_instruction_that( main_initial_action=Sequence([SetEnvironmentVariableViaInstructionArguments(recorder.variable_name), recorder.for_step(step.SETUP__MAIN)]), validate_post_setup_initial_action=recorder.for_step(step.SETUP__VALIDATE_POST_SETUP))], _act_phase_instructions_that_are_not_relevant_to_this_test(), [before_assert_phase_instruction_that( validate_post_setup_initial_action=recorder.for_step(step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=recorder.for_step(step.BEFORE_ASSERT__MAIN))], [assert_phase_instruction_that( validate_post_setup_initial_action=recorder.for_step(step.ASSERT__VALIDATE_POST_SETUP), main_initial_action=recorder.for_step(step.ASSERT__MAIN))], [cleanup_phase_instruction_that( main_initial_action=recorder.for_step(step.CLEANUP__MAIN))], ) test__va( self, test_case, Arrangement( actor=_actor_that_records_existence_of_var_in_global_env(recorder)), AssertPhasesWhereTheEnvironmentVariableExistsInTheGlobalEnvironmentIsEmpty(recorder.recorded_steps))
def _test_case(self) -> test_case_doc.TestCase: return full_test_case_with_instructions( [ configuration_phase_instruction_that( main_initial_action=_ConfigurationPhaseActionThatSetsHomeCaseDirToParent()), configuration_phase_instruction_that( main_initial_action=_ConfigurationPhaseActionThatSetsHomeActDirToParentParent()) ], [setup_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars(self.recorder, phase_step.SETUP__VALIDATE_PRE_SDS), validate_post_setup_initial_action=_RecordEnvVars(self.recorder, phase_step.SETUP__VALIDATE_POST_SETUP), main_initial_action=_RecordEnvVars(self.recorder, phase_step.SETUP__MAIN))], [], [before_assert_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars(self.recorder, phase_step.BEFORE_ASSERT__VALIDATE_PRE_SDS), validate_post_setup_initial_action=_RecordEnvVars(self.recorder, phase_step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=_RecordEnvVars(self.recorder, phase_step.BEFORE_ASSERT__MAIN))], [assert_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars(self.recorder, phase_step.ASSERT__VALIDATE_PRE_SDS), validate_post_setup_initial_action=_RecordEnvVars(self.recorder, phase_step.ASSERT__VALIDATE_POST_SETUP), main_initial_action=_RecordEnvVars(self.recorder, phase_step.ASSERT__MAIN))], [cleanup_phase_instruction_that( validate_pre_sds_initial_action=_RecordEnvVars(self.recorder, phase_step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=_RecordEnvVars(self.recorder, phase_step.CLEANUP__MAIN))], )
def test_that_symbols_from_arrangement_exist_in_environment(self): symbol = StringConstantSymbolContext( 'symbol_name_in_cleanup_phase', 'the symbol value in cleanup phase') symbol_table_of_arrangement = symbol.symbol_table expected_symbol_table = symbol.symbol_table assertion_for_validation = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table, get_symbol_table_from_path_resolving_environment_that_is_first_arg) assertion_for_main = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table, get_symbol_table_from_instruction_environment_that_is_first_arg) self._check( utils.ParserThatGives( cleanup_phase_instruction_that( validate_pre_sds_initial_action=assertion_for_validation, main_initial_action=assertion_for_main, )), utils.single_line_source(), sut.Arrangement(symbols=symbol_table_of_arrangement), sut.Expectation(), )
def test_one_symbol_is_defined_in_the_cleanup_phase(self): symbol = NameAndValue('symbol name', 'symbol value (not used in test)') all_defined_symbols = {symbol.name} symbol_definition = StringConstantSymbolContext( symbol.name, symbol.value).definition symbol_usages_of_instruction_that_defines_symbol = [symbol_definition] expected_phase_2_step_2_names_set = { PhaseEnum.SETUP: { step.SETUP__VALIDATE_PRE_SDS.step: all_defined_symbols, step.SETUP__MAIN.step: set(), step.SETUP__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.ACT: { step.ACT__VALIDATE_PRE_SDS.step: all_defined_symbols, step.ACT__VALIDATE_POST_SETUP.step: all_defined_symbols, step.ACT__EXECUTE.step: set(), step.ACT__PREPARE.step: set(), }, PhaseEnum.BEFORE_ASSERT: { step.BEFORE_ASSERT__VALIDATE_PRE_SDS.step: all_defined_symbols, step.BEFORE_ASSERT__MAIN.step: set(), step.BEFORE_ASSERT__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.ASSERT: { step.ASSERT__VALIDATE_PRE_SDS.step: all_defined_symbols, step.ASSERT__MAIN.step: set(), step.ASSERT__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.CLEANUP: { step.CLEANUP__VALIDATE_PRE_SDS.step: all_defined_symbols, step.CLEANUP__MAIN.step: set(), }, } actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict() def recorder_for(phase_step: SimplePhaseStep): return psr.StepRecordingAction( phase_step, actual_phase_2_step_2_names_set, get_symbols_name_set_from_instruction_environment) test_case = partial_test_case_with_instructions( [ psr.setup_phase_instruction_that_records_a_value_per_step( recorder_for) ], psr.act_phase_instructions_that_does_nothing(), [ psr. before_assert_phase_instruction_that_records_a_value_per_step( recorder_for) ], [ psr.assert_phase_instruction_that_records_a_value_per_step( recorder_for) ], [ cleanup_phase_instruction_that( symbol_usages=do_return( symbol_usages_of_instruction_that_defines_symbol), validate_pre_sds_initial_action=recorder_for( step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=sequence_of_actions([ recorder_for(step.CLEANUP__MAIN), _ActionThatSetsSymbolInSymbolTable(symbol_definition), ]), ) ], ) test__va( self, test_case, Arrangement( psr.actor_that_records_a_value_per_step( recorder_for, recorder_for_parse_step=psr.no_recording)), asrt.anything_goes()) _check_result(self, expected_phase_2_step_2_names_set, actual_phase_2_step_2_names_set)
def cleanup_instr_setup(self) -> SingleInstructionSetup: return instr_setup(instr.cleanup_phase_instruction_that( validate_pre_sds=self.do_return_validation_error) )
def instruction_that_returns(self, symbol_usages: list) -> TestCaseInstruction: return test.cleanup_phase_instruction_that(symbol_usages=do_return(symbol_usages))
def cleanup_instr_setup(self) -> SingleInstructionSetup: return instr_setup( instr.cleanup_phase_instruction_that( validate_pre_sds=self.do_return_validation_error))
def cleanup_phase_instruction_that_records_property_of_env_for_each_step( property_recorder: PropertyRecorderBuilder) -> CleanupPhaseInstruction: return cleanup_phase_instruction_that( validate_pre_sds_initial_action=property_recorder.of_first_arg( step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=property_recorder.of_first_arg(step.CLEANUP__MAIN))
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.cleanup_phase_instruction_that(validate_pre_sds=do_raise(exception))
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.cleanup_phase_instruction_that(validate_pre_sds=do_raise(exception))
def mk_instruction_with_main_action(self, main_action: Callable) -> Instruction: return cleanup_phase_instruction_that(main_initial_action=main_action)
def _cleanup_phase(self) -> list: return self._phase_elements( lambda main: cleanup_phase_instruction_that(main=main), PhaseEnum.CLEANUP)
def test_one_symbol_is_defined_in_the_cleanup_phase(self): symbol = NameAndValue('symbol name', 'symbol value (not used in test)') all_defined_symbols = {symbol.name} symbol_definition = data_symbol_utils.string_symbol_definition(symbol.name, symbol.value) symbol_usages_of_instruction_that_defines_symbol = [symbol_definition] expected_phase_2_step_2_names_set = { PhaseEnum.SETUP: { step.SETUP__VALIDATE_PRE_SDS.step: all_defined_symbols, step.SETUP__MAIN.step: set(), step.SETUP__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.ACT: { step.ACT__VALIDATE_PRE_SDS.step: all_defined_symbols, step.ACT__VALIDATE_POST_SETUP.step: all_defined_symbols, step.ACT__EXECUTE.step: set(), step.ACT__PREPARE.step: set(), }, PhaseEnum.BEFORE_ASSERT: { step.BEFORE_ASSERT__VALIDATE_PRE_SDS.step: all_defined_symbols, step.BEFORE_ASSERT__MAIN.step: set(), step.BEFORE_ASSERT__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.ASSERT: { step.ASSERT__VALIDATE_PRE_SDS.step: all_defined_symbols, step.ASSERT__MAIN.step: set(), step.ASSERT__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.CLEANUP: { step.CLEANUP__VALIDATE_PRE_SDS.step: all_defined_symbols, step.CLEANUP__MAIN.step: set(), }, } actual_phase_2_step_2_names_set = psr.new_phase_enum_2_empty_dict() def recorder_for(phase_step: SimplePhaseStep): return psr.StepRecordingAction(phase_step, actual_phase_2_step_2_names_set, get_symbols_name_set_from_instruction_environment) test_case = partial_test_case_with_instructions( [ psr.setup_phase_instruction_that_records_a_value_per_step(recorder_for) ], psr.act_phase_instructions_that_does_nothing(), [ psr.before_assert_phase_instruction_that_records_a_value_per_step(recorder_for) ], [ psr.assert_phase_instruction_that_records_a_value_per_step(recorder_for) ], [ cleanup_phase_instruction_that( symbol_usages=do_return(symbol_usages_of_instruction_that_defines_symbol), validate_pre_sds_initial_action=recorder_for(step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=Sequence([ recorder_for(step.CLEANUP__MAIN), _ActionThatSetsSymbolInSymbolTable(symbol_definition), ]), ) ], ) test__va( self, test_case, Arrangement(psr.actor_that_records_a_value_per_step(recorder_for, recorder_for_parse_step=psr.no_recording)), asrt.anything_goes()) _check_result(self, expected_phase_2_step_2_names_set, actual_phase_2_step_2_names_set)
def _cleanup_phase(self) -> list: return self._phase_elements(lambda main: cleanup_phase_instruction_that(main=main), PhaseEnum.CLEANUP)
def cleanup_instr_setup(self) -> SingleInstructionSetup: return instr_setup( instr.cleanup_phase_instruction_that( main_initial_action=append_section_name_action( self.recording_output, phase_identifier.CLEANUP)))
def cleanup_instr_setup(self) -> SingleInstructionSetup: return instr_setup(instr.cleanup_phase_instruction_that( main_initial_action=append_section_name_action(self.recording_output, phase_identifier.CLEANUP)) )
DEF_INSTRUCTION_NAME: define_symbol__before_assert.setup(DEF_INSTRUCTION_NAME), REF_INSTRUCTION_NAME: _ref_instruction_setup( REF_INSTRUCTION_NAME, lambda usages: instrs.before_assert_phase_instruction_that(symbol_usages=do_return(usages))), }, assert_instruction_set={ DEF_INSTRUCTION_NAME: define_symbol__assert.setup(DEF_INSTRUCTION_NAME), REF_INSTRUCTION_NAME: _ref_instruction_setup( REF_INSTRUCTION_NAME, lambda usages: instrs.assert_phase_instruction_that(symbol_usages=do_return(usages))), }, cleanup_instruction_set={ DEF_INSTRUCTION_NAME: define_symbol__cleanup.setup(DEF_INSTRUCTION_NAME), REF_INSTRUCTION_NAME: _ref_instruction_setup( REF_INSTRUCTION_NAME, lambda usages: instrs.cleanup_phase_instruction_that(symbol_usages=do_return(usages))), }, ) def main_program_config(actor: Optional[Actor] = None) -> MainProgramConfig: if actor is None: actor = _ActorThatParsesReferences(REF_INSTRUCTION_NAME) return main_program_execution.main_program_config( test_case_definition_for(INSTRUCTION_SETUP), act_phase_setup=ActPhaseSetup( actor ) )
def cleanup_phase_instruction_that_records_property_of_env_for_each_step( property_recorder: PropertyRecorderBuilder) -> CleanupPhaseInstruction: return cleanup_phase_instruction_that( validate_pre_sds_initial_action=property_recorder.of_first_arg(step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=property_recorder.of_first_arg(step.CLEANUP__MAIN))
def instruction_that_returns(self, return_value: svh.SuccessOrValidationErrorOrHardError) -> TestCaseInstruction: return test.cleanup_phase_instruction_that( validate_pre_sds=do_return(return_value))
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.cleanup_phase_instruction_that(symbol_usages=do_raise(exception))
def cleanup_phase_instruction_that_records_a_value_per_step(recorder_for) -> CleanupPhaseInstruction: return cleanup_phase_instruction_that( validate_pre_sds_initial_action=recorder_for(step.CLEANUP__VALIDATE_PRE_SDS), main_initial_action=recorder_for(step.CLEANUP__MAIN), )
def instruction_that_returns(self, return_value: svh.SuccessOrValidationErrorOrHardError) -> TestCaseInstruction: return test.cleanup_phase_instruction_that( validate_pre_sds=do_return(return_value))
sut.Arrangement( default_environ_getter=default_environ_getter, process_execution_settings=ProcessExecutionSettings. from_non_immutable(environ=default_environs), ), sut.Expectation(instruction_settings=asrt_instr_settings.matches( environ=asrt.equals(default_environs), return_value_from_default_getter=asrt.equals( default_from_default_getter)), proc_exe_settings=asrt_pes.matches( environ=asrt.equals(default_environs))), ) PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION = utils.ParserThatGives( cleanup_phase_instruction_that()) class TestSymbols(TestCaseBase): def test_that_symbols_from_arrangement_exist_in_environment(self): symbol = StringConstantSymbolContext( 'symbol_name_in_cleanup_phase', 'the symbol value in cleanup phase') symbol_table_of_arrangement = symbol.symbol_table expected_symbol_table = symbol.symbol_table assertion_for_validation = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table, get_symbol_table_from_path_resolving_environment_that_is_first_arg) assertion_for_main = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table,
populated_dir_contents = DirContents([empty_file('sds-file.txt')]) self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, utils.single_line_source(), sut.Arrangement( sds_contents_before_main=sds_populator.contents_in( sds_populator.RelSdsOptionType.REL_TMP, populated_dir_contents)), sut.Expectation( main_side_effects_on_sds=tmp_user_dir_contains_exactly( populated_dir_contents)), ) PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION = utils.ParserThatGives( cleanup_phase_instruction_that()) class TestSymbols(TestCaseBase): def test_that_symbols_from_arrangement_exist_in_environment(self): symbol_name = 'symbol_name_in_cleanup_phase' symbol_value = 'the symbol value in cleanup phase' symbol_table_of_arrangement = data_symbol_utils.symbol_table_with_single_string_value(symbol_name, symbol_value) expected_symbol_table = data_symbol_utils.symbol_table_with_single_string_value(symbol_name, symbol_value) assertion_for_validation = do_fail_if_symbol_table_does_not_equal( self, expected_symbol_table, get_symbol_table_from_path_resolving_environment_that_is_first_arg)
def instruction_that_returns(self, symbol_usages: list) -> TestCaseInstruction: return test.cleanup_phase_instruction_that(symbol_usages=do_return(symbol_usages))
def cleanup_instr_setup(self) -> SingleInstructionSetup: return instr_setup(instr.cleanup_phase_instruction_that( main_initial_action=do_raise(ImplementationError()) ))
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.cleanup_phase_instruction_that(symbol_usages=do_raise(exception))
def cleanup_instr_setup(self) -> SingleInstructionSetup: return instr_setup( instr.cleanup_phase_instruction_that( main_initial_action=do_raise(ImplementationError())))