def _check_failing_validation_of_referenced_program__for_relativity(self, missing_file_relativity: RelOptionType): relativity_conf = relativity_options.conf_rel_any(missing_file_relativity) program_symbol_with_ref_to_non_exiting_exe_file = ProgramSymbolContext.of_sdv( 'PGM_WITH_REF_TO_EXE_FILE', program_sdvs.ref_to_exe_file( constant(simple_of_rel_option(relativity_conf.relativity_option, 'non-existing-exe-file'))) ) program_symbol_with_ref_to_non_exiting_file_as_argument = ProgramSymbolContext.of_sdv( 'PGM_WITH_ARG_WITH_REF_TO_FILE', program_sdvs.interpret_py_source_file_that_must_exist( constant(simple_of_rel_option(relativity_conf.relativity_option, 'non-existing-python-file.py'))) ) expectation = MultiSourceExpectation.of_const( symbol_references=asrt.anything_goes(), primitive=asrt.anything_goes(), execution=ExecutionExpectation( validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[relativity_conf.directory_structure_partition], ) ) symbols = SymbolContext.symbol_table_of_contexts([ program_symbol_with_ref_to_non_exiting_exe_file, program_symbol_with_ref_to_non_exiting_file_as_argument, ]) arrangement = arrangement_w_tcds( symbols=symbols, ) cases = [ NameAndValue( 'executable does not exist', RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_exe_file.name), ), NameAndValue( 'file referenced from argument does not exist', RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_file_as_argument.name), ), ] for case in cases: with self.subTest(case=case.name): # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, case.value, arrangement, expectation, )
def _check(put: unittest.TestCase, integer_matcher: IntegerMatcherAbsStx, integer_matcher_symbols: List[SymbolContext]): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL') all_symbols = [program_symbol] + integer_matcher_symbols command_execution_counter = recording.Counter(initial_value=0) # ACT & ASSERT # CHECKER.check__abs_stx( put, InstructionArguments( program_symbol.abstract_syntax, integer_matcher, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services=os_services_w_cmd_exe_counting__w_wrapped( command_execution_counter, CommandExecutorThatJustReturnsConstant(1) ), ) ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols) ) ), ) put.assertEqual(1, command_execution_counter.value, 'number of times the program has been executed')
def environment_exe_case( environment: Dict[str, str], program_symbol_name: str, ) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]: py_file = File( 'environment-vars-check.py', py_programs. pgm_that_exists_with_zero_exit_code_iff_environment_vars_not_included( environment)) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( program_symbol_name, program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) return NExArr( 'Environment: {}'.format(repr(environment)), PrimAndExeExpectation.of_exe( main_result=asrt_run.is_result_for_py_interpreter( py_run_programs.EXIT_CODE_FOR_SUCCESS)), arrangement_w_tcds( tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root(DirContents([py_file])), symbols=program_symbol.symbol_table, process_execution=ProcessExecutionArrangement( process_execution_settings=ProcessExecutionSettings. with_environ(environment))))
def run_test(self): def resolve_validator_that_fails_pre_sds( symbols: SymbolTable) -> DdvValidator: return ConstantDdvValidator.of_pre_sds( asrt_text_doc.new_single_string_text_for_test('err msg')) referenced_system_program_sdv_w_invalid_arguments = program_sdvs.system_program( string_sdvs.str_constant('valid-system-program'), ArgumentsSdv(list_sdvs.from_str_constant('the arg'), [resolve_validator_that_fails_pre_sds])) valid_program_symbol = ProgramSymbolContext.of_sdv( 'VALID_PROGRAM', referenced_system_program_sdv_w_invalid_arguments) argument_syntax = ArgumentOfRichStringAbsStx.of_str('valid-arg') reference_and_additional_invalid_argument = self.source_to_parse( valid_program_symbol.name, [argument_syntax], ) # ACT & ASSERT # self.integration_checker( ).check__abs_stx__layouts__source_variants__wo_input( self.put, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, reference_and_additional_invalid_argument, arrangement_w_tcds(symbols=valid_program_symbol.symbol_table, ), MultiSourceExpectation.of_const( symbol_references=valid_program_symbol.references_assertion, primitive=asrt.anything_goes(), execution=ExecutionExpectation( validation=validation.ValidationAssertions. pre_sds_fails__w_any_msg(), )), )
def run_test(self): relativity_conf = relativity_options.conf_rel_any( self._missing_file_relativity) referenced_program_arguments = [ 'valid arg 1 of referenced', 'valid arg 2 of referenced' ] referenced_system_program_sdv = program_sdvs.system_program( string_sdvs.str_constant('valid-system-program'), ArgumentsSdv.new_without_validation( list_sdvs.from_str_constants(referenced_program_arguments))) valid_program_symbol = ProgramSymbolContext.of_sdv( 'VALID_PROGRAM', referenced_system_program_sdv) invalid_argument_syntax = ArgumentOfExistingPathAbsStx( relativity_conf.path_abs_stx_of_name('non-existing-file')) reference_and_additional_invalid_argument = self.source_to_parse( valid_program_symbol.name, [invalid_argument_syntax], ) # ACT & ASSERT # self.integration_checker( ).check__abs_stx__layouts__source_variants__wo_input( self.put, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, reference_and_additional_invalid_argument, arrangement_w_tcds(symbols=valid_program_symbol.symbol_table, ), MultiSourceExpectation.of_const( symbol_references=valid_program_symbol.references_assertion, primitive=asrt.anything_goes(), execution=ExecutionExpectation( validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[ relativity_conf.directory_structure_partition], )), )
def runTest(self): output_to_stderr = 'on stderr' py_file = File( 'exit-with-value-on-command-line.py', py_pgm_that_exits_with_1st_value_on_command_line(output_to_stderr)) py_file_rel_opt_conf = relativity_options.conf_rel_any( RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_that_executes_py_pgm_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_FILE', program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) symbols = program_that_executes_py_pgm_symbol.symbol_table instruction_arguments = [ pgm_args.symbol_ref_command_line( program_that_executes_py_pgm_symbol.name), 0, ] self.conf.run_test( self, single_line_source(args.sequence(instruction_arguments).as_str), self.conf.arrangement(tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([py_file])), symbols=symbols), self.conf.expect_success(symbol_usages=asrt.matches_sequence( [program_that_executes_py_pgm_symbol.reference_assertion])), )
def runTest(self): # ARRANGE # valid_program_symbol = ProgramSymbolContext.of_arbitrary_value( 'VALID_PROGRAM') for invalid_matcher_case in im_validation_case.failing_validation_cases( ): invalid_matcher_symbol = invalid_matcher_case.value.symbol_context all_symbols = [valid_program_symbol, invalid_matcher_symbol] with self.subTest(invalid_matcher_case.name): # ACT & ASSERT # invalid_matcher_symbol = invalid_matcher_case.value.symbol_context CHECKER.check__abs_stx( self, InstructionArguments( valid_program_symbol.abstract_syntax, invalid_matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts( all_symbols), ), Expectation2( ParseExpectation( symbol_usages=SymbolContext. usages_assertion_of_contexts(all_symbols)), ExecutionExpectation. validation_corresponding_to__post_sds_as_hard_error( invalid_matcher_case.value.actual, ), ))
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) ) ), ), )
class TestProgramViaSymbolReference(unittest.TestCase): output_to_stderr = 'on stderr' py_file = File( 'exit-with-value-on-command-line.py', py_pgm_that_exits_with_1st_value_on_command_line(output_to_stderr)) py_file_rel_opt_conf = relativity_options.conf_rel_any( RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_that_executes_py_pgm_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_FILE', program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) symbols = program_that_executes_py_pgm_symbol.symbol_table def test_check_zero_exit_code(self): EXECUTION_CHECKER.check__w_source_variants( self, args.sequence([ pgm_args.symbol_ref_command_line( self.program_that_executes_py_pgm_symbol.name), 0 ]).as_str, Arrangement.phase_agnostic( tcds=TcdsArrangement(tcds_contents=self.py_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([self.py_file])), ), symbols=self.symbols), MultiSourceExpectation.phase_agnostic( main_result=result_assertions.equals(0, None), symbol_usages=asrt.matches_sequence([ self.program_that_executes_py_pgm_symbol. reference_assertion ]))) def test_check_non_zero_exit_code(self): exit_code = 87 EXECUTION_CHECKER.check__w_source_variants( self, args.sequence([ pgm_args.symbol_ref_command_line( self.program_that_executes_py_pgm_symbol.name), exit_code ]).as_str, Arrangement.phase_agnostic( tcds=TcdsArrangement(tcds_contents=self.py_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([self.py_file])), ), symbols=self.symbols), MultiSourceExpectation.phase_agnostic( main_result=result_assertions.equals(exit_code, self.output_to_stderr), symbol_usages=asrt.matches_sequence([ self.program_that_executes_py_pgm_symbol. reference_assertion ])))
def _check( self, command_driver: CommandDriverSdvCase, arguments_of_referenced_command: List[str], accumulated_arguments_of_referenced_program: List[str], additional_argument: List[str], ): # ARRANGE # all_arguments = (arguments_of_referenced_command + accumulated_arguments_of_referenced_program + additional_argument) def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=command_driver.expected_command_driver(env), arguments=asrt.equals(all_arguments)), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ) referenced_program_symbol = ProgramSymbolContext.of_sdv( 'REFERENCED_PROGRAM', command_program_sdv.ProgramSdvForCommand( CommandSdv( command_driver.command_driver, ArgumentsSdv.new_without_validation( list_sdvs.from_str_constants( arguments_of_referenced_command))), AccumulatedComponents.of_arguments( ArgumentsSdv.new_without_validation( list_sdvs.from_str_constants( accumulated_arguments_of_referenced_program))))) source_to_parse = self.source_to_parse( referenced_program_symbol.name, [ ArgumentOfRichStringAbsStx.of_str(arg) for arg in additional_argument ], ) # ACT & ASSERT # self.integration_checker().check__abs_stx__wo_input( self.put, source_to_parse, command_driver.mk_arrangement( referenced_program_symbol.symbol_table), Expectation( parse=ParseExpectation( symbol_references=referenced_program_symbol. references_assertion, ), primitive=expected_program, ), )
def __init__( self, output_file: ProcOutputFile, stdin_defined_for_program: Sequence[StringSourceSdv] = (), ): self.output_file = output_file self._copy_program_symbol = ProgramSymbolContext.of_sdv( 'COPY_STDIN', program_sdvs.for_py_source_on_command_line( py_programs.copy_stdin_to(output_file), stdin=stdin_defined_for_program))
def _check( self, output: StdOutputFilesContents, exit_code_cases: List[int], ignore_exit_code: bool, execution_expectation: ExecutionExpectation, ): # ARRANGE # py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) for exit_code in exit_code_cases: with self.subTest(non_zero_exit_code=exit_code): py_file = File( 'exit-with-hard-coded-exit-code.py', py_programs.py_pgm_with_stdout_stderr_exit_code( stdout_output=output.out, stderr_output=output.err, exit_code=exit_code, ), ) py_file_conf = py_file_rel_opt_conf.named_file_conf( py_file.name) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL_NAME', program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check( self, args.syntax_for_run( program_args.symbol_ref_command_elements( program_symbol.name), ignore_exit_code=ignore_exit_code, ).as_remaining_source, model_constructor.arbitrary(self), arrangement_w_tcds( symbols=program_symbol.symbol_table, tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root( DirContents([py_file])), ), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(1), symbol_references=program_symbol. references_assertion), execution_expectation, ), )
def __init__(self, put: unittest.TestCase, exit_code: int = 0, additional_stdin: str = ''): super().__init__( put, exit_code, self.CONCATENATED_STRING_SOURCES_CONTENTS + additional_stdin) self.program_w_stdin_symbol = ProgramSymbolContext.of_sdv( 'REFERENCED_PROGRAM', self._program_sdv_w_stdin__wo_sym_refs( self.STR_SRC_CONTENTS__OF_REFERENCED_PROGRAM))
def runTest(self): # ARRANGE # py_file = File('stdin-to-upper.py', _PGM_THAT_OUTPUTS_STDIN_IN_UPPER_CASE) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_FILE', program_sdvs.interpret_py_source_file_that_must_exist(py_file_conf.path_sdv) ) input_model_lines = [ 'the\n', 'input\n', 'model', ] expected_output_model_lines = list(map(str.upper, input_model_lines)) for with_ignored_exit_code in [False, True]: with self.subTest(with_ignored_exit_code=with_ignored_exit_code): # ACT && ASSERT # integration_check.CHECKER__PARSE_FULL.check__w_source_variants_for_full_line_parser( self, args.syntax_for_run( program_args.symbol_ref_command_elements(program_symbol.name), ignore_exit_code=with_ignored_exit_code, ), model_constructor.of_lines(self, input_model_lines), arrangement_w_tcds( tcds_contents=py_file_rel_opt_conf.populator_for_relativity_option_root( DirContents([py_file]) ), symbols=program_symbol.symbol_table, ), MultiSourceExpectation( symbol_references=program_symbol.references_assertion, execution=ExecutionExpectation( main_result=asrt_string_source.pre_post_freeze__matches_lines( asrt.equals(expected_output_model_lines), may_depend_on_external_resources=asrt.equals(True), frozen_may_depend_on_external_resources=asrt.anything_goes(), ) ), primitive=prim_asrt__constant( asrt_string_transformer.is_identity_transformer(False) ), ), )
def program_reference__w_argument_list() -> PgmAndArgsCase: system_program = 'the-system-program' system_program_sdv = program_sdvs.system_program(string_sdvs.str_constant(system_program)) system_program_symbol = ProgramSymbolContext.of_sdv('SYSTEM_PROGRAM_SYMBOL', system_program_sdv) return PgmAndArgsCase.wo_tcds( 'reference to program w argument list', pgm_and_args=ProgramOfSymbolReferenceAbsStx(system_program_symbol.name), symbols=[system_program_symbol], expected_command_driver=prim_asrt__constant( asrt_command.matches_system_program_command_driver( asrt.equals(system_program) )), )
def __init__( self, symbol_name: str, string_transformer_case: str_trans_validation_cases.ValidationCase, ): self._string_transformer_case = string_transformer_case additional_components = AccumulatedComponents.of_transformation( StringTransformerSdvReference( string_transformer_case.symbol_context.name)) program_w_transformer = program_sdvs.system_program( string_sdvs.str_constant('system-program')).new_accumulated( additional_components) self._program_symbol_context = ProgramSymbolContext.of_sdv( symbol_name, program_w_transformer)
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value( 'PROGRAM_SYMBOL') executor_that_do_not_run_any_program = CommandExecutorThatJustReturnsConstant( 0) for may_depend_on_external_resources in [False, True]: for with_ignored_exit_code in [False, True]: with self.subTest( with_ignored_exit_code=with_ignored_exit_code, may_depend_on_external_resources= may_depend_on_external_resources): # ACT && ASSERT # pass integration_check.CHECKER__PARSE_SIMPLE.check( self, args.syntax_for_run( program_args.symbol_ref_command_elements( program_symbol.name), ignore_exit_code=with_ignored_exit_code, ).as_remaining_source, model_constructor.empty(self, may_depend_on_external_resources= may_depend_on_external_resources), arrangement_w_tcds( symbols=program_symbol.symbol_table, process_execution=ProcessExecutionArrangement( os_services=os_services_access.new_for_cmd_exe( executor_that_do_not_run_any_program)), ), Expectation( ParseExpectation(symbol_references=program_symbol. references_assertion, ), ExecutionExpectation( main_result=asrt_string_source. pre_post_freeze__matches_lines( asrt.anything_goes(), may_depend_on_external_resources=asrt.equals( True), frozen_may_depend_on_external_resources=asrt. anything_goes(), )), prim_asrt__constant( asrt_string_transformer.is_identity_transformer( False)), ), )
def _instructions_for_executing_py_source( self, py_src: List[str]) -> ContextManager[TestCaseSourceSetup]: py_file = fs.File('the-program.py', lines_content(py_src)) symbol = 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_ACT, py_file.name, ))) program_line = args.symbol_ref_command_line(symbol.name).as_str yield TestCaseSourceSetup( act_phase_instructions=[instr([program_line])], home_act_dir_contents=DirContents([py_file]), symbols=symbol.symbol_table, symbol_usages=symbol.usages_assertion)
def runTest(self): # ARRANGE # symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL', program_sdvs.system_program( string_sdvs.str_constant('non-existing-system-program'))) program_line = args.symbol_ref_command_line(symbol.name).as_str # ACT & ASSERT # integration_check.check_execution( self, sut.actor(), [instr([program_line])], arrangement_w_tcds(symbol_table=symbol.symbol_table), Expectation.hard_error_from_execute( symbol_usages=symbol.usages_assertion), )
def exit_code_exe_cases( program_symbol_name: str, exit_code_symbol_name: str, ) -> Sequence[NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]]: py_file = File( 'exit-with-value-on-command-line.py', py_programs.py_pgm_that_exits_with_1st_value_on_command_line('')) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( program_symbol_name, program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) def case( exit_code_from_program: int ) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]: exit_code_symbol = StringIntConstantSymbolContext( exit_code_symbol_name, exit_code_from_program) return NExArr( 'Exit code {}'.format(exit_code_from_program), PrimAndExeExpectation.of_exe( main_result=asrt_run.is_result_for_py_interpreter( exit_code_from_program)), arrangement_w_tcds( tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root(DirContents([py_file])), symbols=SymbolContext.symbol_table_of_contexts([ program_symbol, exit_code_symbol, ]), )) exit_code_from_program_cases = [0, 1, 3, 69, 72] return [ case(exit_code_from_program) for exit_code_from_program in exit_code_from_program_cases ]
def runTest(self): python_source = 'exit(72)' name_of_defined_symbol = 'the_symbol' referred_symbol = ProgramSymbolContext.of_sdv( 'PRE_EXISTING_PROGRAM_SYMBOL', program_sdvs.for_py_source_on_command_line(python_source)) symbols = referred_symbol.symbol_table program_abs_stx = ProgramOfSymbolReferenceAbsStx(referred_symbol.name) define_symbol_syntax = DefineSymbolWMandatoryValue( name_of_defined_symbol, ValueType.PROGRAM, program_abs_stx, ) expected_symbol_container = matches_container( asrt.equals(ValueType.PROGRAM), sdv=type_sdv_assertions.matches_sdv_of_program_constant( references=asrt.matches_sequence( [referred_symbol.reference_assertion]), primitive_value=matches_py_source_on_cmd_line_program( python_source), symbols=symbols)) expectation = MultiSourceExpectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition( name=asrt.equals(name_of_defined_symbol), container=expected_symbol_container) ]), symbols_after_main=assert_symbol_table_is_singleton( expected_name=name_of_defined_symbol, value_assertion=expected_symbol_container, )) INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants( self, define_symbol_syntax, Arrangement.phase_agnostic(), expectation, )
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_sdv( 'A_PROGRAM', program_sdvs.arbitrary__without_symbol_references()) pgm_and_args_cases = [ NameAndValue('shell command', pgm_args.shell_command('shell-command arg')), NameAndValue( 'system command', pgm_args.system_program_argument_elements( 'system command arg')), NameAndValue('python', pgm_args.interpret_py_source_elements('exit(0)')), NameAndValue( 'symbol reference', pgm_args.symbol_ref_command_elements(program_symbol.name, [])), ] for pgm_and_args_case in pgm_and_args_cases: for validation_case in failing_validation_cases(): arguments = pgm_and_args_case.value.followed_by_lines( [validation_case.value.transformer_arguments_elements]) symbols = SymbolContext.symbol_table_of_contexts([ program_symbol, validation_case.value.symbol_context, ]) with self.subTest(pgm_and_args_case=pgm_and_args_case.name, validation_case=validation_case.name): # ACT & ASSERT # CHECKER_W_TRANSFORMATION.check( self, arguments.as_remaining_source, ProcOutputFile.STDOUT, arrangement_w_tcds(symbols=symbols), Expectation( ParseExpectation( symbol_references=asrt.anything_goes(), ), ExecutionExpectation( validation=validation_case.value.expectation, )))
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value( 'PROGRAM_SYMBOL') const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant( 'CONST_TRUE_INT_MATCHER', result=True, ) string_transformer_that_reports_failure_if_applied = StringTransformerSymbolContext.of_primitive( 'STRING_TRANSFORMER_THAT_MUST_NOT_BE_USED', StringTransformerThatFailsTestIfApplied(self)) all_symbols = [ program_symbol, string_transformer_that_reports_failure_if_applied, const_true_int_matcher_symbol, ] # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( FullProgramAbsStx( program_symbol.abstract_syntax, transformation= string_transformer_that_reports_failure_if_applied. abstract_syntax), const_true_int_matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services_access.new_for_cmd_exe( CommandExecutorThatJustReturnsConstant(1), ), ), ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( all_symbols), ), ExecutionExpectation(main_result=asrt_pfh.is_pass()), ))
def runTest(self): # ARRANGE # program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL') const_true_int_matcher_symbol = IntegerMatcherSymbolContext.of_primitive_constant( 'CONST_TRUE_INT_MATCHER', result=True, ) all_symbols = [program_symbol, const_true_int_matcher_symbol, ] hard_error_message = 'the err msg' # ACT & ASSERT # CHECKER.check__abs_stx( self, InstructionArguments( program_symbol.abstract_syntax, const_true_int_matcher_symbol.abstract_syntax, ), ArrangementPostAct2( symbols=SymbolContext.symbol_table_of_contexts(all_symbols), process_execution=ProcessExecutionArrangement( os_services_access.new_for_cmd_exe( CommandExecutorThatRaisesHardError( asrt_text_doc.new_single_string_text_for_test(hard_error_message) ), ), ), ), Expectation2( ParseExpectation( symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols), ), ExecutionExpectation( main_result=asrt_pfh.is_hard_error( asrt_text_doc.is_string_for_test_that_equals(hard_error_message) ) ), ) )
def runTest(self): for case in VALIDATION_CASES: with self.subTest(case.name): program_sdv = program_sdvs.ref_to_exe_file( path_sdvs.of_rel_option_with_const_file_name( case.path_relativity, 'non-existing')) program_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_SYMBOL', program_sdv) integration_check.check_execution( self, sut.actor(), [ instr([ args.symbol_ref_command_line( program_symbol.name).as_str ]) ], arrangement_w_tcds( symbol_table=program_symbol.symbol_table, ), Expectation(symbol_usages=program_symbol.usages_assertion, validation=case.expectation), )
def runTest(self): # ARRANGE # exit_code_from_program = 0 py_file = fs.File( 'the-program', lines_content(py_program.exit_with_code(exit_code_from_program)), ) program_symbol = 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, ))) program_line = args.symbol_ref_command_line(program_symbol.name).as_str with tmp_dir_in_path_with_files(DirContents([py_file])) as environ: for source_case in valid_source_variants(program_line): with self.subTest(source_case.name): # ACT & ASSERT # integration_check.check_execution( self, sut.actor(), [instr([program_line])], arrangement_w_tcds( symbol_table=program_symbol.symbol_table, act_exe_input=AtcExeInputArr(environ=environ), hds_contents=hds_populators.contents_in( RelHdsOptionType.REL_HDS_CASE, DirContents([py_file])), ), Expectation( symbol_usages=program_symbol.usages_assertion, execute=asrt_eh.is_exit_code( exit_code_from_program)), )
def argument_list_exe_case( command_line_arguments: List[str], expected_program_arguments: List[str], program_symbol_name: str, list_arg_symbol_name: str, ) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]: py_file = File( 'arguments-check.py', py_run_programs. pgm_that_exists_with_zero_exit_code_iff_arguments_are_expected( expected_program_arguments)) py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP) py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name) program_symbol = ProgramSymbolContext.of_sdv( program_symbol_name, program_sdvs.interpret_py_source_file_that_must_exist( py_file_conf.path_sdv)) arg_list_symbol = ListSymbolContext.of_constants(list_arg_symbol_name, command_line_arguments) return NExArr( 'Command line arguments: {}'.format(repr(command_line_arguments), ), PrimAndExeExpectation.of_exe( main_result=asrt_run.is_result_for_py_interpreter( py_run_programs.EXIT_CODE_FOR_SUCCESS)), arrangement_w_tcds( tcds_contents=py_file_rel_opt_conf. populator_for_relativity_option_root(DirContents([py_file])), symbols=SymbolContext.symbol_table_of_contexts([ program_symbol, arg_list_symbol, ]), ))
def test_stdin_in_referenced_program_and_as_source_argument(self): # ARRANGE # str_src_contents__of_argument = 'the_str_src_contents__of_argument' str_src_contents__of_referenced_pgm = 'the_str_src_contents__of_program' stdin_argument_syntax = str_src_abs_stx.StringSourceOfStringAbsStx.of_str( str_src_contents__of_argument) stdin_sdv__of_referenced = str_src_sdvs.ConstantStringStringSourceSdv( string_sdvs.str_constant(str_src_contents__of_referenced_pgm)) referenced_program__system_program = 'the-system-program' referenced_program__sdv = program_sdvs.system_program( string_sdvs.str_constant(referenced_program__system_program), stdin=[stdin_sdv__of_referenced], ) referenced_program = ProgramSymbolContext.of_sdv( 'REFERENCED_PROGRAM', referenced_program__sdv) symbols__symbol_table = [referenced_program] symbols__expected_references = [referenced_program] arguments_cases = [ NameAndValue( 'no arguments', [], ), NameAndValue( 'single argument', ['arg1'], ) ] for arguments_case in arguments_cases: with self.subTest(arguments=arguments_case.name): program_w_stdin = FullProgramAbsStx( ProgramOfSymbolReferenceAbsStx(referenced_program.name, [ ArgumentOfRichStringAbsStx.of_str(arg) for arg in arguments_case.value ]), stdin=stdin_argument_syntax, ) expected_primitive = asrt_pgm_val.matches_program( asrt_command.matches_command( driver=asrt_command. matches_system_program_command_driver( asrt.equals(referenced_program__system_program)), arguments=asrt.equals(arguments_case.value), ), stdin=asrt.matches_sequence([ asrt_str_src.matches__str( asrt.equals(str_src_contents__of_referenced_pgm)), asrt_str_src.matches__str( asrt.equals(str_src_contents__of_argument)), ]), transformer=asrt_pgm_val.is_no_transformation(), ) # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, program_w_stdin, arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts( symbols__symbol_table), ), MultiSourceExpectation.of_const( symbol_references=SymbolContext. references_assertion_of_contexts( symbols__expected_references), primitive=expected_primitive, ))
def test_stdin_in_referenced_program_and_as_source_argument(self): # ARRANGE # stdin_contents = 'str_src_contents' valid_stdin_sdv = sdvs.ConstantStringStringSourceSdv( string_sdvs.str_constant(stdin_contents)) valid_stdin_syntax = str_src_abs_stx.StringSourceOfStringAbsStx.of_str( stdin_contents) referenced_program__system_program = 'the-system-program' for validation_case in validation_cases.failing_validation_cases(): invalid_stdin_location_cases = [ ValidationCaseWAccumulation( 'in referenced symbol', sdv_of_referenced_program=validation_case.value. symbol_context.sdv, syntax_accumulated=valid_stdin_syntax, symbols=[], ), ValidationCaseWAccumulation( 'as source argument', sdv_of_referenced_program=valid_stdin_sdv, syntax_accumulated=validation_case.value.syntax, symbols=[validation_case.value.symbol_context], ), ] for invalid_stdin_location_case in invalid_stdin_location_cases: referenced_program__sdv = program_sdvs.system_program( string_sdvs.str_constant( referenced_program__system_program), stdin=[ invalid_stdin_location_case.sdv_of_referenced_program ]) referenced_program = ProgramSymbolContext.of_sdv( 'REFERENCED_PROGRAM', referenced_program__sdv) program_w_stdin = FullProgramAbsStx( ProgramOfSymbolReferenceAbsStx(referenced_program.name, ), stdin=invalid_stdin_location_case.syntax_of_accumulated, ) symbols__all = [ validation_case.value.symbol_context, referenced_program ] symbols__expected_references = [ referenced_program ] + invalid_stdin_location_case.symbols # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, program_w_stdin, arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts( symbols__all), ), MultiSourceExpectation.of_const( symbol_references=SymbolContext. references_assertion_of_contexts( symbols__expected_references), execution=ExecutionExpectation( validation=validation_case.value.assertion, ), primitive=asrt.anything_goes(), ), sub_test_identifiers={ 'validation': validation_case.name, 'invalid_stdin_location': invalid_stdin_location_case.name, })