def test_superfluous_arguments(self): # ARRANGE # arbitrary_transformer_symbol = StringTransformerSymbolContext.of_arbitrary_value( 'TRANSFORMER_SYMBOL') src_file_relativity_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE) file_contents_builder = string_source_abs_stx.TransformableAbsStxBuilder( string_source_abs_stx.StringSourceOfFileAbsStx( src_file_relativity_conf.path_abs_stx_of_name('src-file.txt'))) file_contents_cases = [ NameAndValue('contents of existing file / without transformation', file_contents_builder.without_transformation()), NameAndValue( 'contents of existing file / with transformation', file_contents_builder.with_transformation( arbitrary_transformer_symbol.abstract_syntax)), ] for file_contents_case in file_contents_cases: valid_instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file.txt'), file_contents_case.value, ) invalid_instruction_syntax = custom_abs_stx.SequenceAbsStx([ valid_instruction_syntax, custom_abs_stx.CustomAbstractSyntax.singleton( 'superfluous_argument') ]) with self.subTest(file_contents_variant=file_contents_case.name): # ACT & ASSERT # check_invalid_syntax__abs_stx(self, invalid_instruction_syntax)
def _check_cases_for_dst_file_setup__expect_pre_sds_validation_failure( self, dst_file_name: str, additional_symbols: Iterable[Entry] = (), ): dst_file = path_abs_stx.DefaultRelPathAbsStx(dst_file_name) cases_data = self._file_contents_cases() for file_contents_case in cases_data.file_contents_cases: instruction_syntax = instr_abs_stx.InstructionAbsStx( dst_file, file_contents_case.value, ) symbols = cases_data.symbols.copy() symbols.add_all(additional_symbols) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest( file_contents_variant=file_contents_case.name, phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx( self, instruction_syntax, Arrangement.phase_agnostic(symbols=symbols, ), Expectation.phase_agnostic_2( validation=ValidationAssertions. pre_sds_fails__w_any_msg(), symbol_usages=asrt.anything_goes(), ))
def test_WHEN_program_is_non_non_existing_system_command_THEN_result_SHOULD_be_error_message(self): failing_program_builder = program_abs_stx.TransformableProgramAbsStxBuilder( program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str(NON_EXISTING_SYSTEM_PROGRAM) ) transformer = TO_UPPER_TRANSFORMER_SYMBOL symbols = transformer.symbol_table cases = failing_program_builder.with_and_without_transformer_cases(transformer.abstract_syntax) for transformation_case in cases: instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file'), string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, transformation_case.value, ignore_exit_code=False) ) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest(phase_is_after_act=phase_is_after_act, transformation=transformation_case.name): checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( symbols=symbols, tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.anything_goes(), main_result=IS_FAILURE, ) )
def test_fail_when_contents_is_missing(self): # ARRANGE # missing_contents = fs_abs_stx.FileContentsExplicitAbsStx( fs_abs_stx.ModificationType.CREATE, string_source_abs_stx.CustomStringSourceAbsStx.missing_value()) instruction_syntax = instr_abs_stx.InstructionAbsStx( path_abs_stx.DefaultRelPathAbsStx('file-name'), missing_contents, ) # ACT & ASSERT # check_invalid_syntax__abs_stx(self, instruction_syntax)
def test_fail_when_superfluous_arguments(self): # ARRANGE # valid_instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('file-name'), string_source_abs_stx.StringSourceOfStringAbsStx.of_str('string'), ) invalid_instruction_syntax = custom_abs_stx.SequenceAbsStx([ valid_instruction_syntax, custom_abs_stx.CustomAbstractSyntax.singleton( 'superfluous_argument') ]) # ACT & ASSERT # check_invalid_syntax__abs_stx(self, invalid_instruction_syntax)
def test_string_transformer_should_be_parsed_as_simple_expression(self): # ARRANGE # transformation_w_infix_op = str_trans_abs_stx.StringTransformerCompositionAbsStx( [ StringTransformerSymbolReferenceAbsStx('str_trans_1'), StringTransformerSymbolReferenceAbsStx('str_trans_2'), ], within_parens=False, allow_elements_on_separate_lines=False, ) src_rel_opt_conf = conf_rel_sds(RelSdsOptionType.REL_ACT) file_contents_arg = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name('src-file')), transformation_w_infix_op) instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file'), file_contents_arg, ) # ACT & ASSERT # check_invalid_syntax__abs_stx(self, instruction_syntax)
def runTest(self): # ARRANGE # cases = [ NArrEx( 'pre SDS validation failure SHOULD cause validation error', RelOptionType.REL_HDS_CASE, MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ), ), NArrEx( 'post SDS validation failure SHOULD cause main error', RelOptionType.REL_ACT, MultiSourceExpectation.phase_agnostic( validation=ValidationAssertions.post_sds_fails__w_any_msg() ), ), ] for case in cases: program_with_ref_to_non_existing_file = program_abs_stx.ProgramOfExecutableFileCommandLineAbsStx( path_abs_stx.RelOptPathAbsStx(case.arrangement, 'non-existing-file') ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( path_abs_stx.DefaultRelPathAbsStx('dst-file'), string_source_abs_stx.StringSourceOfProgramAbsStx(ProcOutputFile.STDOUT, program_with_ref_to_non_existing_file, ignore_exit_code=False) ) # ACT & ASSERT # for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) with self.subTest(phase_is_after_act=phase_is_after_act, step=case.name): checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(), case.expectation, )
def syntax_for_matcher(self, matcher: StringMatcherAbsStx) -> AbstractSyntax: return abstract_syntax.InstructionArgumentsAbsStx( path_abs_stx.DefaultRelPathAbsStx(self.FILE_NAME_REL_CWD), matcher, )