def runTest(self): output_from_program = 'first second' transformer_of_program = transformers_setup.DELETE_INITIAL_WORD_TRANSFORMER transformer_of_instruction = transformers_setup.DUPLICATE_WORDS_TRANSFORMER program_that_outputs_something = pgm_args.program( pgm_args.interpret_py_source_line( self.configuration.py_source_for_print(output_from_program)), transformation=transformer_of_program.name) result_when_positive = pfh_expectation_type_config( ExpectationType.POSITIVE) self._check_positive_and_negated( result_when_positive, program_that_outputs_something, matcher_arguments.equals_matcher( ab.quoted_string('second second')), lambda main_result: Expectation( main_result=main_result, symbol_usages=asrt.matches_sequence([ is_reference_to_string_transformer__usage( transformer_of_program.name), is_reference_to_string_transformer__usage( transformer_of_instruction.name), ])), arrangement=ArrangementPostAct( symbols=transformers_setup.SYMBOL_TABLE), transformation=transformer_of_instruction.name)
def _check_with_exit_code(self, exit_code: int): # ARRANGE # result = SubProcessResult( exitcode=exit_code, stdout='output on stdout', stderr='output on stderr', ) command_py_program = py_program.program_that_prints_and_exits_with_exit_code(result) py_file = fs.File( 'the-program.py', command_py_program, ) program_wo_transformation = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL', program_sdvs.interpret_py_source_file_that_must_exist( path_sdvs.of_rel_option_with_const_file_name( RelOptionType.REL_HDS_CASE, py_file.name, ) ) ) source = args.program( args.symbol_ref_command_line(program_wo_transformation.name), transformation=TO_UPPER_CASE_TRANSFORMER.name__sym_ref_syntax) symbols = [ program_wo_transformation, TO_UPPER_CASE_TRANSFORMER, ] # ACT & ASSERT # integration_check.check_execution( self, sut.actor(), [instr(source.as_arguments.lines)], arrangement_w_tcds( symbol_table=SymbolContext.symbol_table_of_contexts(symbols), hds_contents=hds_populators.contents_in( RelHdsOptionType.REL_HDS_CASE, DirContents([py_file]), ) ), Expectation( symbol_usages=SymbolContext.references_assertion_of_contexts(symbols), execute=asrt_eh.is_exit_code(result.exitcode), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result.matches_proc_result( exit_code=asrt.equals(result.exitcode), stdout=asrt.equals(result.stdout.upper()), stderr=asrt.equals(result.stderr), ) ) ), )
def runTest(self): # ARRANGE # command_py_program = py_program.exit_with_code(0) py_file = fs.File( 'the-program.py', lines_content(command_py_program), ) program_wo_transformation = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL', program_sdvs.interpret_py_source_file_that_must_exist( path_sdvs.of_rel_option_with_const_file_name( RelOptionType.REL_HDS_CASE, py_file.name, ) ) ) error_message = 'error message from transformer' transformer = StringTransformerPrimitiveSymbolContext( 'HARD_ERROR_TRANSFORMER', string_transformers.model_access_raises_hard_error(error_message), ) source = args.program( args.symbol_ref_command_line(program_wo_transformation.name), transformation=transformer.name__sym_ref_syntax) symbols = [ program_wo_transformation, transformer, ] # ACT & ASSERT # integration_check.check_execution( self, sut.actor(), [instr(source.as_arguments.lines)], arrangement_w_tcds( symbol_table=SymbolContext.symbol_table_of_contexts(symbols), hds_contents=hds_populators.contents_in( RelHdsOptionType.REL_HDS_CASE, DirContents([py_file]), ) ), Expectation( symbol_usages=SymbolContext.references_assertion_of_contexts(symbols), execute=asrt_eh.matches_hard_error( asrt_failure_details.is_failure_message_matching__td( asrt_text_doc.is_string_for_test_that_equals(error_message) ) ), ), )
def runTest(self): program_that_outputs_nothing = pgm_args.program( pgm_args.interpret_py_source_line( self.configuration.py_source_for_print(''))) result_when_positive = pfh_expectation_type_config( ExpectationType.POSITIVE) self._check_positive_and_negated( result_when_positive, program_that_outputs_nothing, matcher_arguments.emptiness_matcher(), lambda main_result: Expectation(main_result=main_result))
def runTest(self): # ARRANGE # program = pgm_args.program( pgm_args.interpret_py_source_line('exit(0)') ) no_matcher = [] arguments = po_ab.from_program(program, no_matcher) source = arguments.as_remaining_source with self.assertRaises(SingleInstructionInvalidArgumentException): # ACT # self.configuration.parser().parse(ARBITRARY_FS_LOCATION_INFO, source)
def runTest(self): # ARRANGE # program_with_ref_to_file_in_hds_ds = pgm_args.program( pgm_args.interpret_py_source_file(path_arguments.RelOptPathArgument('non-existing-file', RelOptionType.REL_HDS_CASE)) ) arguments = po_ab.from_program(program_with_ref_to_file_in_hds_ds, matcher_arguments.emptiness_matcher()) # ACT & ASSERT # self._check(arguments, ArrangementPostAct(), Expectation(validation_pre_sds=asrt_svh.is_validation_error()))
def runTest(self): # ARRANGE # symbol_in_program_source = NameAndValue('SYMBOL_IN_PROGRAM_SOURCE', data_restrictions_assertions.is__w_str_rendering()) symbol_in_matcher = NameAndValue('SYMBOL_IN_MATCHER', ss_references.IS_STRING_SOURCE_OR_STRING_REFERENCE_RESTRICTION) symbol_in_transformer_of_program = NameAndValue('SYMBOL_IN_TRANSFORMER_OF_PROGRAM', is_reference_restrictions__value_type( [ValueType.STRING_TRANSFORMER])) symbol_in_transformer_of_instruction = NameAndValue('SYMBOL_IN_TRANSFORMER_OF_INSTRUCTION', is_reference_restrictions__value_type( [ValueType.STRING_TRANSFORMER])) program_with_ref_to_symbols = pgm_args.program( pgm_args.interpret_py_source_line( self.configuration.py_source_for_print( symbol_reference_syntax_for_name(symbol_in_program_source.name))), transformation=symbol_in_transformer_of_program.name ) matcher_with_ref_to_symbol = matcher_arguments.equals_matcher(SymbolReferenceArgument(symbol_in_matcher.name)) arguments = po_ab.from_program(program_with_ref_to_symbols, matcher_with_ref_to_symbol, transformation=symbol_in_transformer_of_instruction.name) symbol_usages_assertion = asrt.matches_sequence([ matches_reference(symbol_in_program_source), matches_reference(symbol_in_transformer_of_program), matches_reference(symbol_in_transformer_of_instruction), matches_reference(symbol_in_matcher), ]) source = arguments.as_remaining_source # ACT # actual = self.configuration.parser().parse(ARBITRARY_FS_LOCATION_INFO, source) actual_symbol_usages = actual.symbol_usages() # ASSERT # symbol_usages_assertion.apply_without_message(self, actual_symbol_usages)
def runTest(self): # ARRANGE # program_with_ref_to_file_in_hds_ds = pgm_args.program( pgm_args.interpret_py_source_file(path_arguments.RelOptPathArgument('non-existing-file', RelOptionType.REL_ACT)) ) arguments = po_ab.from_program(program_with_ref_to_file_in_hds_ds, matcher_arguments.emptiness_matcher()) # ACT & ASSERT # self._check(arguments, ArrangementPostAct(), Expectation( main_result=asrt_pfh.is_hard_error__with_arbitrary_message()) )
def runTest(self): program_that_outputs_something = pgm_args.program( pgm_args.interpret_py_source_line( self.configuration.py_source_for_print('some output')), transformation=transformers_setup.DELETE_EVERYTHING_TRANSFORMER. name) result_when_positive = pfh_expectation_type_config( ExpectationType.POSITIVE) self._check_positive_and_negated( result_when_positive, program_that_outputs_something, matcher_arguments.emptiness_matcher(), lambda main_result: Expectation( main_result=main_result, symbol_usages=asrt.matches_sequence([ is_reference_to_string_transformer__usage( transformers_setup.DELETE_EVERYTHING_TRANSFORMER.name), ])), ArrangementPostAct(symbols=transformers_setup.SYMBOL_TABLE))
def source_for_interpreting(relativity: RelOptionType, file_name: str) -> ParseSource: return pgm_args.program( pgm_args.interpret_py_source_file( path_arguments.RelOptPathArgument(file_name, relativity))).as_remaining_source