def test_before_assert(self): # ARRANGE # cases = { STEP__VALIDATE_POST_SETUP: { EXECUTION__VALIDATION_ERROR: before_assert_phase_instruction_that(validate_post_setup=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: before_assert_phase_instruction_that(validate_post_setup=SVH_HARD_ERROR), EXECUTION__IMPLEMENTATION_ERROR: before_assert_phase_instruction_that( validate_post_setup_initial_action=DO_RAISES_EXCEPTION), }, STEP__MAIN: { EXECUTION__HARD_ERROR: before_assert_phase_instruction_that(main=SH_HARD_ERROR), EXECUTION__IMPLEMENTATION_ERROR: before_assert_phase_instruction_that(main_initial_action=DO_RAISES_EXCEPTION), }, } # ACT & ASSERT # self._check_and_assert_sds_is_preserved_and_is_printed(phase_identifier.BEFORE_ASSERT, cases)
def test_before_assert(self): # ARRANGE # cases = { STEP__VALIDATE_POST_SETUP: { EXECUTION__VALIDATION_ERROR: before_assert_phase_instruction_that( validate_post_setup=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: before_assert_phase_instruction_that( validate_post_setup=SVH_HARD_ERROR), EXECUTION__INTERNAL_ERROR: before_assert_phase_instruction_that( validate_post_setup_initial_action=DO_RAISES_EXCEPTION), }, STEP__MAIN: { EXECUTION__HARD_ERROR: before_assert_phase_instruction_that(main=SH_HARD_ERROR), EXECUTION__INTERNAL_ERROR: before_assert_phase_instruction_that( main_initial_action=DO_RAISES_EXCEPTION), }, } # ACT & ASSERT # self._check_and_assert_sds_is_preserved_and_is_printed( phase_identifier.BEFORE_ASSERT, cases)
def test_before_assert(self): # ARRANGE # cases = { EXECUTION__VALIDATION_ERROR: before_assert_phase_instruction_that(validate_pre_sds=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: before_assert_phase_instruction_that(validate_pre_sds=SVH_HARD_ERROR), EXECUTION__IMPLEMENTATION_ERROR: before_assert_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.BEFORE_ASSERT, 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' symbol_value = 'the symbol value' 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( before_assert_phase_instruction_that( validate_pre_sds_initial_action=assertion_for_validation, validate_post_setup_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_that_symbols_from_arrangement_exist_in_environment(self): symbol = StringConstantSymbolContext('symbol_name', 'the symbol value') 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( before_assert_phase_instruction_that( validate_pre_sds_initial_action=assertion_for_validation, validate_post_setup_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_before_assert(self): # ARRANGE # cases = { EXECUTION__VALIDATION_ERROR: before_assert_phase_instruction_that( validate_pre_sds=SVH_VALIDATION_ERROR), EXECUTION__HARD_ERROR: before_assert_phase_instruction_that( validate_pre_sds=SVH_HARD_ERROR), EXECUTION__INTERNAL_ERROR: before_assert_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.BEFORE_ASSERT, 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).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 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 before_assert_phase_instruction_that_records_a_value_per_step( recorder_for) -> BeforeAssertPhaseInstruction: return before_assert_phase_instruction_that( validate_pre_sds_initial_action=recorder_for( step.BEFORE_ASSERT__VALIDATE_PRE_SDS), validate_post_setup_initial_action=recorder_for( step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=recorder_for(step.BEFORE_ASSERT__MAIN), )
def before_assert_phase_instruction_that_records_property_of_env_for_each_step( property_recorder: PropertyRecorderBuilder ) -> BeforeAssertPhaseInstruction: return before_assert_phase_instruction_that( validate_pre_sds_initial_action=property_recorder.of_first_arg( step.BEFORE_ASSERT__VALIDATE_PRE_SDS), validate_post_setup_initial_action=property_recorder.of_first_arg( step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=property_recorder.of_first_arg( step.BEFORE_ASSERT__MAIN))
def new_before_assert_instruction(self, value_for_symbol_usages, value_for_validate_pre_sds, value_for_validate_post_sds, value_for_main) -> BeforeAssertPhaseInstruction: return before_assert_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), validate_post_setup=self._do_record_and_return_svh(value_for_validate_post_sds), main=self._do_record_and_return_sh(value_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( before_assert_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), single_line_source(), sut.arrangement(), sut.Expectation(), )
def new_before_assert_instruction( self, value_for_symbol_usages, value_for_validate_pre_sds, value_for_validate_post_sds, value_for_main) -> BeforeAssertPhaseInstruction: return before_assert_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), validate_post_setup=self._do_record_and_return_svh( value_for_validate_post_sds), main=self._do_record_and_return_sh(value_for_main))
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( before_assert_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), 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( before_assert_phase_instruction_that( symbol_usages=do_return(symbol_usages_of_instruction))), single_line_source(), sut.arrangement(), sut.Expectation( symbol_usages=sym_asrt.equals_symbol_references(symbol_usages_of_expectation)), )
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_that_fails_due_to_missing_symbol_reference(self): with self.assertRaises(utils.TestError): symbol_usages_of_instruction = [] self._check( utils.ParserThatGives( before_assert_phase_instruction_that( symbol_usages=do_return(symbol_usages_of_instruction))), 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 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_set_environment_variable_in_phase_before_assert(self): recorder = _RecorderOfExistenceOfGlobalEnvVar(_unique_variable_name()) test_case = partial_test_case_with_instructions( [], _act_phase_instructions_that_are_not_relevant_to_this_test(), [before_assert_phase_instruction_that( main_initial_action=Sequence([SetEnvironmentVariableViaInstructionArguments(recorder.variable_name), 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=dummy_actor()), AssertPhasesWhereTheEnvironmentVariableExistsInTheGlobalEnvironmentIsEmpty(recorder.recorded_steps))
def test_hard_error_in_before_assert_main_step(self): test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.BEFORE_ASSERT, test.before_assert_phase_instruction_that( main=do_return(sh.new_sh_hard_error('hard error msg')))) self._check( Arrangement(test_case, act_executor_execute=execute_action_that_returns_exit_code(0)), Expectation( asrt_result.matches2( PartialExeResultStatus.HARD_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(0), ExpectedFailureForInstructionFailure.new_with_message( phase_step.BEFORE_ASSERT__MAIN, test_case.the_extra(PartialPhase.BEFORE_ASSERT)[0].source, 'hard error msg'), ), [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.CLEANUP__MAIN, PreviousPhase.BEFORE_ASSERT), (phase_step.CLEANUP__MAIN, PreviousPhase.BEFORE_ASSERT), ], ))
def test_internal_error(self): test_case = TestCaseGeneratorWithExtraInstrsBetweenRecordingInstr() \ .add(PartialPhase.BEFORE_ASSERT, test.before_assert_phase_instruction_that( main=do_raise(test.ImplementationErrorTestException()))) self._check( Arrangement(test_case, atc_execute=execute_action_that_returns_exit_code(12)), Expectation( asrt_result.matches2( ExecutionFailureStatus.INTERNAL_ERROR, asrt_result.has_sds(), asrt_result.has_action_to_check_outcome_with_exit_code(12), ExpectedFailureForInstructionFailure.new_with_exception( phase_step.BEFORE_ASSERT__MAIN, test_case.the_extra( PartialPhase.BEFORE_ASSERT)[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.CLEANUP__MAIN, PreviousPhase.BEFORE_ASSERT), (phase_step.CLEANUP__MAIN, PreviousPhase.BEFORE_ASSERT), ], ))
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))], )
return instruction_setup.single_instruction_setup_for_parser(instruction_name, _ReferenceParser(mk_instruction)) INSTRUCTION_SETUP = InstructionsSetup( setup_instruction_set={ DEF_INSTRUCTION_NAME: define_symbol__setup.setup(DEF_INSTRUCTION_NAME), REF_INSTRUCTION_NAME: _ref_instruction_setup( REF_INSTRUCTION_NAME, lambda usages: instrs.setup_phase_instruction_that(symbol_usages=do_return(usages))), }, before_assert_instruction_set={ 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 instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.before_assert_phase_instruction_that(validate_pre_sds=do_raise(exception))
def instruction_that_returns(self, return_value: svh.SuccessOrValidationErrorOrHardError) -> TestCaseInstruction: return test.before_assert_phase_instruction_that( validate_pre_sds=do_return(return_value))
def before_assert_phase_instruction_that_records_property_of_env_for_each_step( property_recorder: PropertyRecorderBuilder) -> BeforeAssertPhaseInstruction: return before_assert_phase_instruction_that( validate_pre_sds_initial_action=property_recorder.of_first_arg(step.BEFORE_ASSERT__VALIDATE_PRE_SDS), validate_post_setup_initial_action=property_recorder.of_first_arg(step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=property_recorder.of_first_arg(step.BEFORE_ASSERT__MAIN))
def _before_assert_phase(self) -> list: return self._phase_elements( lambda main: before_assert_phase_instruction_that(main=main), PhaseEnum.BEFORE_ASSERT)
def _before_assert_phase(self) -> list: return self._phase_elements(lambda main: before_assert_phase_instruction_that(main=main), PhaseEnum.BEFORE_ASSERT)
def before_assert_phase_instruction_that_records_a_value_per_step(recorder_for) -> BeforeAssertPhaseInstruction: return before_assert_phase_instruction_that( validate_pre_sds_initial_action=recorder_for(step.BEFORE_ASSERT__VALIDATE_PRE_SDS), validate_post_setup_initial_action=recorder_for(step.BEFORE_ASSERT__VALIDATE_POST_SETUP), main_initial_action=recorder_for(step.BEFORE_ASSERT__MAIN), )
def instruction_that_returns(self, return_value: svh.SuccessOrValidationErrorOrHardError) -> TestCaseInstruction: return test.before_assert_phase_instruction_that( validate_pre_sds=do_return(return_value))
def before_assert_instr_setup(self) -> SingleInstructionSetup: return instr_setup(instr.before_assert_phase_instruction_that( main_initial_action=do_raise(ImplementationError()) ))
def before_assert_instr_setup(self) -> SingleInstructionSetup: return instr_setup(instr.before_assert_phase_instruction_that( validate_pre_sds=self.do_return_validation_error) )
}, setup_instruction_set={ DEF_INSTRUCTION_NAME: define_symbol__setup.setup(DEF_INSTRUCTION_NAME), REF_INSTRUCTION_NAME: _ref_instruction_setup( REF_INSTRUCTION_NAME, lambda usages: instrs. setup_phase_instruction_that(symbol_usages=do_return(usages))), }, before_assert_instruction_set={ 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.
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.before_assert_phase_instruction_that(symbol_usages=do_raise(exception))
def before_assert_instr_setup(self) -> SingleInstructionSetup: return instr_setup( instr.before_assert_phase_instruction_that( main_initial_action=append_section_name_action( self.recording_output, phase_identifier.BEFORE_ASSERT)))
def instruction_that_returns(self, symbol_usages: list) -> TestCaseInstruction: return test.before_assert_phase_instruction_that(symbol_usages=do_return(symbol_usages))
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( before_assert_phase_instruction_that()) class TestSymbols(TestCaseBase): 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( before_assert_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), single_line_source(), sut.arrangement(), sut.Expectation(), )
def test_one_symbol_is_defined_in_the_before_assert_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: all_defined_symbols, step.ASSERT__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.CLEANUP: psr.same_value_for_all_steps(step.ALL_CLEANUP_WITH_ENV_ARG, all_defined_symbols), } 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(), [ before_assert_phase_instruction_that( symbol_usages=do_return(symbol_usages_of_instruction_that_defines_symbol), validate_pre_sds_initial_action=recorder_for(step.BEFORE_ASSERT__VALIDATE_PRE_SDS), main_initial_action=Sequence([ recorder_for(step.BEFORE_ASSERT__MAIN), _ActionThatSetsSymbolInSymbolTable(symbol_definition), ]), validate_post_setup_initial_action=recorder_for(step.BEFORE_ASSERT__VALIDATE_POST_SETUP), ) ], [ psr.assert_phase_instruction_that_records_a_value_per_step(recorder_for) ], [ psr.cleanup_phase_instruction_that_records_a_value_per_step(recorder_for) ], ) 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 instruction_that_returns(self, symbol_usages: list) -> TestCaseInstruction: return test.before_assert_phase_instruction_that(symbol_usages=do_return(symbol_usages))
def test_one_symbol_is_defined_in_the_before_assert_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: all_defined_symbols, step.ASSERT__VALIDATE_POST_SETUP.step: all_defined_symbols, }, PhaseEnum.CLEANUP: psr.same_value_for_all_steps(step.ALL_CLEANUP_WITH_ENV_ARG, all_defined_symbols), } 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(), [ before_assert_phase_instruction_that( symbol_usages=do_return( symbol_usages_of_instruction_that_defines_symbol), validate_pre_sds_initial_action=recorder_for( step.BEFORE_ASSERT__VALIDATE_PRE_SDS), main_initial_action=sequence_of_actions([ recorder_for(step.BEFORE_ASSERT__MAIN), _ActionThatSetsSymbolInSymbolTable(symbol_definition), ]), validate_post_setup_initial_action=recorder_for( step.BEFORE_ASSERT__VALIDATE_POST_SETUP), ) ], [ psr.assert_phase_instruction_that_records_a_value_per_step( recorder_for) ], [ psr.cleanup_phase_instruction_that_records_a_value_per_step( recorder_for) ], ) 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 mk_instruction_with_main_action(self, main_action: Callable) -> Instruction: return before_assert_phase_instruction_that(main_initial_action=main_action)
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.before_assert_phase_instruction_that(symbol_usages=do_raise(exception))
def before_assert_instr_setup(self) -> SingleInstructionSetup: return instr_setup( instr.before_assert_phase_instruction_that( validate_pre_sds=self.do_return_validation_error))
def instruction_that_raises(self, exception: Exception) -> TestCaseInstruction: return test.before_assert_phase_instruction_that(validate_pre_sds=do_raise(exception))
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( before_assert_phase_instruction_that()) class TestSymbols(TestCaseBase): 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( before_assert_phase_instruction_that( symbol_usages=do_return(unexpected_symbol_usages))), single_line_source(), sut.arrangement(), sut.Expectation(), )
def before_assert_instr_setup(self) -> SingleInstructionSetup: return instr_setup(instr.before_assert_phase_instruction_that( main_initial_action=append_section_name_action(self.recording_output, phase_identifier.BEFORE_ASSERT)) )
def before_assert_instr_setup(self) -> SingleInstructionSetup: return instr_setup( instr.before_assert_phase_instruction_that( main_initial_action=do_raise(ImplementationError())))