def test_successful_flow(self): self._check( PARSER_THAT_GIVES_MATCHER_THAT_MATCHES, utils.single_line_source(), empty_model(), sut.ArrangementPostAct(), is_pass())
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_successful_step_sequence(self): validate_pre_sds = 'validate_pre_sds' validate_post_sds = 'validate_post_sds' main = 'main' expected_recordings = [ validate_pre_sds, validate_post_sds, main, ] recorder = [] def recording_of(s: str): def ret_val(*args, **kwargs): recorder.append(s) return ret_val instruction_that_records_steps = instruction_embryo_that( validate_pre_sds_initial_action=recording_of(validate_pre_sds), validate_post_sds_initial_action=recording_of(validate_post_sds), main_initial_action=recording_of(main)) self._check( ParserThatGives(instruction_that_records_steps), single_line_source(), ArrangementWithSds(), sut.Expectation()) self.assertEqual(expected_recordings, recorder, 'step execution sequence')
def test_successful_flow(self): self._check( utils.ParserThatGives(SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.Arrangement(), sut.Expectation(), )
def test_successful_step_sequence(self): validate_pre_sds = 'validate_pre_sds' validate_post_sds = 'validate_post_sds' main = 'main' expected_recordings = [ validate_pre_sds, validate_post_sds, main, ] recorder = [] def recording_of(s: str) -> Callable[[InstructionEnvironmentForPostSdsStep, InstructionSettings, OsServices], None]: def ret_val(*args): recorder.append(s) return ret_val instruction_that_records_steps = instruction_embryo_that__phase_agnostic( validate_pre_sds_initial_action=recording_of(validate_pre_sds), validate_post_sds_initial_action=recording_of(validate_post_sds), main_initial_action=recording_of(main)) self._check( ParserThatGives(instruction_that_records_steps), single_line_source(), Arrangement.phase_agnostic(), Expectation.phase_agnostic()) self.assertEqual(expected_recordings, recorder, 'step execution sequence')
def test_fail_due_to_fail_of_side_effects_on_configuration(self): with self.assertRaises(test_misc.TestError): self._check( ParserThatGives(_SUCCESSFUL_INSTRUCTION), single_line_source(), Arrangement(), Expectation(configuration=test_misc.raises_test_error()))
def _check_raises_test_error__single_and_multi(self, parser: Parser[MatcherSdv[int]], expectation: Expectation, ): for check_application_result_with_tcds in [False, True]: checker = sut.IntegrationChecker(parser, CONFIGURATION, check_application_result_with_tcds) for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='single execution'): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), ARBITRARY_MODEL, checker, arrangement.value, expectation, ) with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='multiple execution'): with self.assertRaises(utils.TestError): self._check___multi( utils.single_line_arguments(), ARBITRARY_MODEL, checker, arrangement.value, expectation, )
def test_symbols_after_main(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(symbols_after_main=asrt.is_instance(SymbolTable)), )
def test_successful_flow(self): self._check( utils.single_line_source(), arbitrary_model(), ConstantParser(arbitrary_transformer()), sut.Arrangement(), is_pass())
def test_that_cwd_for_main_and_post_validation_is_test_root(self): self._check( ConstantParser(string_matcher_that_raises_test_error_if_cwd_is_is_not_test_root()), utils.single_line_source(), empty_model(), sut.ArrangementPostAct(), is_pass())
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_home(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(side_effects_on_home=asrt.IsInstance(pathlib.Path)), )
def test_environment_variables__is_an_empty_dict(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(main_side_effect_on_environment_variables=asrt.equals({})), )
def test_side_effects_on_files(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(main_side_effects_on_sds=asrt.IsInstance(SandboxDirectoryStructure)), )
def test_source(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(source=asrt.IsInstance(ParseSource)), )
def test_source(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), Arrangement.phase_agnostic(), Expectation.phase_agnostic(source=asrt.IsInstance(ParseSource)), )
def test_fail_due_to_unexpected_result__from_main(self): with self.assertRaises(utils.TestError): self._check( ParserThatGives(instruction_embryo_that(main=do_return('actual'))), single_line_source(), ArrangementWithSds(), sut.Expectation(main_result=asrt.equals('different-from-actual')), )
def test_fail_due_to_side_effects_check(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.Expectation(main_side_effects_on_home_and_sds=asrt.IsInstance(bool)), )
def test_fail_due_to_assertion_on_instruction_environment(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(assertion_on_instruction_environment=asrt.fail('unconditional failure')), )
def test_fail_due_to_unexpected_result__from_main(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.Expectation(main_result=sh_assertions.is_hard_error()), )
def test_fail_if_instruction_is_not_setup_phase_aware(self): with self.assertRaises(utils.TestError): self._check( ParserThatGives(instruction_embryo_that__phase_agnostic()), single_line_source(), Arrangement.setup_phase_aware(), Expectation.setup_phase_aware(), )
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.Arrangement(), sut.Expectation(main_result=sh_assertions.is_hard_error()), )
def test_that_cwd_for_main_and_post_validation_is_test_root(self): self._check( utils.ParserThatGives( InstructionThatRaisesTestErrorIfCwdIsIsNotTestRoot()), utils.single_line_source(), sut.Arrangement(), sut.Expectation(), )
def test_fail_due_to_unexpected_result_from__validate_post_sds(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(validation_post_sds=asrt.is_not_none), )
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(test_misc.TestError): self._check( ParserThatGives(_SUCCESSFUL_INSTRUCTION), single_line_source(), Arrangement(), Expectation(main_result=test_misc.raises_test_error()))
def test_assertion_on_instruction_environment(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation( assertion_on_instruction_environment=asrt.is_instance(InstructionEnvironmentForPostSdsStep)), )
def test_fail_due_to_unexpected_result_from_validate_pre_sds(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.Arrangement(), sut.Expectation(validate_pre_sds_result=svh_assertions.is_hard_error()), )
def test_fail_due_to_unexpected_result_from_pre_validation(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.ArrangementPostAct(), Expectation(validation_pre_sds=svh_assertions.is_hard_error()), )
def test_fail_due_to_side_effects_check(self): with self.assertRaises(utils.TestError): self._check(utils.ParserThatGives(SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.Arrangement(), sut.Expectation(main_side_effects_on_home_and_sds=sds_2_home_and_sds_assertion( act_dir_contains_exactly( DirContents([empty_file('non-existing-file.txt')])))), )
def test_fail_due_to_fail_of_side_effects_on_instruction_settings(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.Arrangement(), sut.Expectation(instruction_settings=asrt.not_( asrt.is_instance(InstructionSettings))), )
def test_fail_due_to_fail_of_side_effects_on_tcds(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.Expectation( main_side_effects_on_tcds=asrt.IsInstance(bool)), )
def test_fail_due_to_side_effects_on_home(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), ArrangementWithSds(), sut.Expectation(side_effects_on_home=f_asrt.dir_contains_at_least( DirContents([empty_file('file-name.txt')]))), )
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.ArrangementPostAct(), Expectation(main_result=pfh_assertions. is_fail__with_arbitrary_message()), )
def test_fail_due_to_fail_of_side_effects_on_sds(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.ArrangementPostAct(), Expectation(main_side_effects_on_sds=act_dir_contains_exactly( DirContents([File.empty('non-existing-file.txt')]))), )
def test_fail_due_to_fail_of_side_effects_on_files(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.Expectation(main_side_effects_on_sds=act_dir_contains_exactly( DirContents([empty_file('non-existing-file.txt')]))), )
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.ArrangementPostAct(), Expectation( main_result=pfh_assertions.is_fail()), )
def test_fail_due_to_unexpected_result_from_post_validation(self): with self.assertRaises(utils.TestError): self._check(ConstantParser(_MATCHER_THAT_MATCHES), utils.single_line_source(), empty_model(), sut.ArrangementPostAct(), Expectation( validation_post_sds=asrt_validation.is_arbitrary_validation_failure()), )
def test_missing_hard_error_is_detected(self): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), arbitrary_model(), ConstantParser(arbitrary_transformer()), sut.Arrangement(), sut.Expectation( is_hard_error=is_hard_error(), ))
def test_fail_due_to_unexpected_result_from_post_validation(self): with self.assertRaises(utils.TestError): self._check(utils.single_line_source(), arbitrary_model(), ConstantParser(arbitrary_transformer()), sut.Arrangement(), Expectation( validation=asrt_validation.post_sds_validation_fails(), ) )
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(utils.TestError): self._check( ConstantParser(_MATCHER_THAT_MATCHES), utils.single_line_source(), empty_model(), sut.ArrangementPostAct(), Expectation( main_result=matcher_assertions.is_arbitrary_matching_failure()), )
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), arbitrary_model(), ConstantParser(string_transformer_from_result(model_with_num_lines(1))), sut.Arrangement(), Expectation( main_result=assert_num_lines_in_result_equals(2)), )
def test_missing_hard_error_is_detected(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_MATCHER_THAT_MATCHES, utils.single_line_source(), empty_model(), sut.ArrangementPostAct(), sut.Expectation( is_hard_error=is_hard_error(), ))
def test_fail_due_to_fail_of_side_effects_on_instruction_settings(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.Expectation( instruction_settings=asrt.not_(asrt.is_instance(InstructionSettings)), ), )
def test_fail_due_to_fail_of_side_effects_on_sds(self): with self.assertRaises(utils.TestError): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.Expectation( main_side_effects_on_sds=act_dir_contains_exactly( DirContents([File.empty('non-existing-file.txt')])) ), )
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_populate_sds(self): populated_dir_contents = DirContents([File.empty('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)), )
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_populate_environ(self): default_from_default_getter = {'default': 'value of default'} default_environs = {'in_environs': 'value of var in environs'} def default_environ_getter() -> Dict[str, str]: return default_from_default_getter self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, utils.single_line_source(), 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))), )
def test_fail_due_to_unsatisfied_assertion_on_output_from_application(self): matcher_result_value = True for check_application_result_with_tcds in [False, True]: parser = _constant_line_matcher_type_parser_of_matcher_sdv( sdv_ddv.sdv_from_primitive_value(constant.MatcherWithConstantResult(matcher_result_value)) ) checker = sut.IntegrationChecker( parser, _CustomMatcherPropertiesConfiguration(asrt_matching_result.matches_value(not matcher_result_value)), check_application_result_with_tcds, ) expectation = is_expectation_of_execution_result_of(matcher_result_value) for arrangement in _EMPTY_ARRANGEMENT_W_WO_TCDS: with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='single execution'): with self.assertRaises(utils.TestError): self._check( utils.single_line_source(), ARBITRARY_MODEL, checker, arrangement.value, expectation, ) with self.subTest(arrangement.name, check_application_result_with_tcds=check_application_result_with_tcds, execution_variant='multiple execution'): with self.assertRaises(utils.TestError): self._check___multi( utils.single_line_arguments(), ARBITRARY_MODEL, checker, arrangement.value, expectation, )
def test_successful_flow(self): self._check(ParserThatGives(_SUCCESSFUL_INSTRUCTION), single_line_source(), Arrangement(), Expectation())
def test_fail_due_to_unexpected_result_from_main(self): with self.assertRaises(test_misc.TestError): self._check(ParserThatGives(_SUCCESSFUL_INSTRUCTION), single_line_source(), Arrangement(), Expectation(main_result=test_misc.raises_test_error()))
def test_successful_flow(self): self._check( PARSER_THAT_GIVES_SUCCESSFUL_INSTRUCTION, single_line_source(), sut.arrangement(), sut.is_success())
def test_that_cwd_for_main__and__validate_post_setup_is_act_dir(self): self._check( utils.ParserThatGives(InstructionThatRaisesTestErrorIfCwdIsIsNotTestRoot()), single_line_source(), sut.arrangement(), sut.is_success())
def test_successful_flow(self): self._check(utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.ArrangementPostAct(), is_pass())
def test_fail_due_to_unexpected_source_after_parse(self): with self.assertRaises(utils.TestError): self._check( utils.ParserThatGives(_SUCCESSFUL_INSTRUCTION), utils.single_line_source(), sut.ArrangementPostAct(), Expectation(source=asrt_source.is_at_beginning_of_line(10), ))