def runTest(self): # ARRANGE # source_file = fs.File.empty('source-file.src') python_interpreter_symbol = PathSymbolContext.of_sdv( 'PYTHON_INTERPRETER_SYMBOL', path_sdvs.constant( path_ddvs.absolute_path(pathlib.Path(sys.executable)))) interpreter_with_symbol_reference = command_sdvs.for_executable_file( python_interpreter_symbol.reference_sdv__path_or_string( relativity_configurations.INTERPRETER_FILE.relativity)) arrangement = arrangement_w_tcds( symbol_table=python_interpreter_symbol.symbol_table, hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([source_file]))) expectation = Expectation( symbol_usages=asrt.matches_singleton_sequence( python_interpreter_symbol.reference_assertion__path_or_string), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_pr.sub_process_result( exitcode=asrt.equals(0), stdout=asrt.equals(''), stderr=asrt.equals(''), )), ) # ACT & ASSERT # check_execution(self, sut.actor(interpreter_with_symbol_reference), [instr([])], arrangement, expectation)
def test_possibility_to_have_sds_path_references_in_argument(self): file_name_of_referenced_file = 'file-name.txt' symbol = ConstantSuffixPathDdvSymbolContext( 'symbol_name', RelOptionType.REL_TMP, file_name_of_referenced_file) executable = 'the-executable' command_line = '{executable} {symbol}'.format( executable=executable, symbol=symbol.name__sym_ref_syntax, ) arrangement = arrangement_w_tcds( hds_contents=relativity_configurations.ATC_FILE. populator_for_relativity_option_root__hds( fs.DirContents([ fs.python_executable_file( executable, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES ) ])), symbol_table=symbol.symbol_table) expectation = Expectation( execute=eh_assertions.is_exit_code(0), symbol_usages=asrt.matches_singleton_sequence( symbol.reference_assertion__w_str_rendering), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=pr.stdout( str_asrt.contains(file_name_of_referenced_file))), ) check_execution(self, sut.actor(), [instr([command_line])], arrangement, expectation)
def test_stdin_contains_model_contents_WHEN_program_do_not_define_stdin( self): # ARRANGE # test_setup = SingleStdinOfProgramTestSetup(self, exit_code=0) for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): with self.subTest(pgm_and_args_case.name): # ACT & ASSERT # CHECKER.check__abs_stx( self, pgm_and_args_case.pgm_and_args, Arrangement( symbols=pgm_and_args_case.symbol_table, process_execution=test_setup. proc_exe_env__w_stdin_check, atc_exe_input=AtcExeInputArr( stdin_contents=test_setup.STRING_SOURCE_CONTENTS, ), tcds=TcdsArrangementPreAct( tcds_contents=pgm_and_args_case.tcds, ), ), Expectation( symbol_usages=pgm_and_args_case.usages_assertion, post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(exit_code=asrt.equals( test_setup.exit_code), )), ))
def check_actor_execution(put: unittest.TestCase, arrangement: Arrangement, expectation: Expectation): instruction = sut.Parser().parse(ARBITRARY_FS_LOCATION_INFO, arrangement.source) configuration_builder = _configuration_builder_with_exception_throwing_act_phase_setup() assert isinstance(instruction, ConfigurationPhaseInstruction) instruction.main(configuration_builder) act_phase_instructions = [instr(arrangement.act_phase_source_lines)] integration_check.check_execution( put, configuration_builder.actor.value, act_phase_instructions, integration_check.arrangement_w_tcds( hds_contents=arrangement.hds_contents, process_execution=ProcessExecutionArrangement( os_services=arrangement.os_services, )), integration_check.Expectation( symbol_usages=expectation.symbol_usages, post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=expectation.sub_process_result_from_execute ), after_execution=expectation.after_execution ) ) expectation.source_after_parse.apply_with_message(put, arrangement.source, 'source after parse')
def test_stdin_is_concatenation_of_model_and_program_stdin_WHEN_program_defines_single_stdin( self): # ARRANGE # model_contents = '\n'.join(('the', 'contents', 'of', 'the', 'model')) test_setup = SingleStdinOfProgramTestSetup( self, exit_code=0, additional_stdin=model_contents) for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): with self.subTest(pgm_and_args_case.name): # ACT & ASSERT # CHECKER.check__abs_stx( self, test_setup.program_w_stdin_syntax( pgm_and_args_case.pgm_and_args), Arrangement( symbols=pgm_and_args_case.symbol_table, process_execution=test_setup. proc_exe_env__w_stdin_check, atc_exe_input=AtcExeInputArr( stdin_contents=model_contents, ), tcds=TcdsArrangementPreAct( tcds_contents=pgm_and_args_case.tcds, ), ), Expectation( symbol_usages=pgm_and_args_case.usages_assertion, post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(exit_code=asrt.equals( test_setup.exit_code), )), ))
def test_symbol_reference_on_command_line_SHOULD_be_reported_and_used_in_execution( self): symbol = StringConstantSymbolContext('symbol_name', 'symbol value') string_to_print_template = 'constant and {symbol}' expected_output_template = string_to_print_template + '\n' shell_source_line = shell_commands.command_that_prints_to_stdout( string_to_print_template.format( symbol=symbol.name__sym_ref_syntax)) act_phase_instructions = [ instr([shell_command_source_line_for(shell_source_line)]) ] check_execution( self, sut.actor(), act_phase_instructions, arrangement_w_tcds(symbol_table=symbol.symbol_table), Expectation(symbol_usages=asrt.matches_singleton_sequence( symbol.reference_assertion__w_str_rendering), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=pr.stdout( asrt.equals( expected_output_template.format( symbol=symbol.str_value))))), )
def runTest(self): # ARRANGE # stdin_from_act_exe_input = 'the stdin from the Act Execution Input (via [setup])' stdin_defined_by_the_program = 'the stdin defined by the program' test_setup = StdinCheckViaCopyToOutputFileTestSetup( ProcOutputFile.STDOUT, stdin_defined_for_program=[ ss_sdvs.const_str(stdin_defined_by_the_program) ]) full_stdin = stdin_defined_by_the_program + stdin_from_act_exe_input # ACT & ASSERT # CHECKER.check__abs_stx( self, test_setup.program_that_copies_stdin_syntax(), Arrangement( symbols=SymbolContext.symbol_table_of_contexts( test_setup.symbols), atc_exe_input=AtcExeInputArr( stdin_contents=stdin_from_act_exe_input, ), tcds=TcdsArrangementPreAct(), ), Expectation( symbol_usages=SymbolContext.usages_assertion_of_contexts( test_setup.symbols), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(exit_code=asrt.equals(0), stdout=asrt.equals(full_stdin))), ), )
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): sub_dir_of_home = 'sub-dir' dir_symbol = ConstantSuffixPathDdvSymbolContext('dir_symbol_name', RelOptionType.REL_HDS_ACT, sub_dir_of_home, PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN) source_file_name_symbol = StringConstantSymbolContext('source_file_name_symbol_name', 'the-source-file.py') argument = 'argument_string' expected_output = lines_content([argument]) command_line = '{dir}/{file_name} {argument} '.format( dir=dir_symbol.name__sym_ref_syntax, file_name=source_file_name_symbol.name__sym_ref_syntax, argument=argument, ) executable_file = fs.File( source_file_name_symbol.str_value, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) arrangement = arrangement_w_tcds( hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([ fs.Dir(sub_dir_of_home, [executable_file]) ])), symbol_table=SymbolContext.symbol_table_of_contexts([ dir_symbol, source_file_name_symbol, ]) ) expectation = Expectation( symbol_usages=asrt.matches_sequence([ dir_symbol.reference_assertion__path_or_string, source_file_name_symbol.reference_assertion__path_component, ]), execute=eh_assertions.is_exit_code(0), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line')) ), ) self._check(command_line, arrangement, expectation)
def runTest(self): stderr_output = 'output on stderr' with self.config.program_that_prints_to_stderr(stderr_output) as setup: self._check( setup.act_phase_instructions, arrangement_w_tcds( symbol_table=setup.symbols, hds_contents=_hds_pop_of(setup), act_exe_input=AtcExeInputArr(environ=setup.environ), ), Expectation( symbol_usages=setup.symbol_usages, post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(stderr=asrt.equals(stderr_output + '\n')))), )
def runTest(self): symbol = ConstantSuffixPathDdvSymbolContext('symbol_name', RelOptionType.REL_ACT, 'the-path-suffix') program_that_prints_value_of_symbol = 'print("{symbol}")' single_source_line = program_that_prints_value_of_symbol.format( symbol=symbol.name__sym_ref_syntax, ) self._check( single_source_line, arrangement_w_tcds(symbol_table=symbol.symbol_table), Expectation( symbol_usages=asrt.matches_singleton_sequence( symbol.reference_assertion__w_str_rendering), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_pr.stdout( str_asrt.contains(symbol.path_suffix))), ))
def runTest(self): symbol = StringConstantSymbolContext('symbol_name', 'the symbol value') program_that_prints_value_of_symbol = 'print("{symbol}")' single_source_line = program_that_prints_value_of_symbol.format( symbol=symbol.name__sym_ref_syntax, ) expected_output = symbol.str_value + '\n' self._check( single_source_line, arrangement_w_tcds(symbol_table=symbol.symbol_table), Expectation( symbol_usages=asrt.matches_sequence([ symbol.reference_assertion__w_str_rendering, ]), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_pr.stdout( asrt.Equals(expected_output, 'program output'))), ))
def runTest(self): expected_output = pr.sub_process_result(exitcode=asrt.equals(0), stdout=asrt.equals(''), stderr=asrt.equals('')) cases = [ ( 'no act phase contents', [] ), ( 'act phase contents of just comments', [instr([LINE_COMMENT_MARKER + ' a comment'])] ), ( 'act phase contents of just comments and empty lines', [instr([LINE_COMMENT_MARKER + ' a comment', '', LINE_COMMENT_MARKER + ' a second comment', ])] ), ( 'act phase contents with non-comment and non-empty line', [instr(['not a comment and not empty', ])] ), ] actor = sut.actor() for case_name, act_phase_instructions in cases: with self.subTest(case_name=case_name): arrangement = arrangement_w_tcds() expectation = Expectation( post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=expected_output ) ) check_execution(self, actor, act_phase_instructions, arrangement, expectation)
def test_stdin_is_concatenation_of_model_and_program_stdin_WHEN_program_defines_multiple_stdin( self): # ARRANGE # model_contents = '\n'.join(('the', 'contents', 'of', 'the', 'model')) test_setup = MultipleStdinOfProgramTestSetup( self, exit_code=0, additional_stdin=model_contents) # ACT & ASSERT # CHECKER.check__abs_stx( self, test_setup.program_w_stdin_syntax, Arrangement( symbols=test_setup.program_symbol.symbol_table, process_execution=test_setup.proc_exe_env__w_stdin_check, atc_exe_input=AtcExeInputArr(stdin_contents=model_contents, ), tcds=TcdsArrangementPreAct(), ), Expectation( symbol_usages=test_setup.program_symbol.usages_assertion, post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(exit_code=asrt.equals( test_setup.exit_code), )), ))
def runTest(self): # ARRANGE # result = SubProcessResult( exitcode=5, stdout='output on stdout from existing py program file', stderr='output on stderr from existing py program file', ) py_file = fs.File( 'the-program.py', py_program.program_that_prints_and_exits_with_exit_code(result), ) source_w_relative_name_of_existing_file = args.interpret_py_source_file( py_file.name) # ACT & ASSERT # integration_check.check_execution( self, sut.actor(), [ instr( source_w_relative_name_of_existing_file.as_arguments.lines) ], arrangement_w_tcds( hds_contents=relativity_configurations.PROGRAM_FILE. populator_for_relativity_option_root__hds( DirContents([py_file]))), Expectation(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), stderr=asrt.equals(result.stderr), ))), )
def runTest(self): var_name = 'This_Is_A_Test_Var_23026509234' var_value = str(random.getrandbits(32)) with self.config.program_that_prints_value_of_environment_variable_to_stdout( var_name) as setup: environ = (dict(os.environ) if setup.environ is None else setup.environ) environ[var_name] = var_value self._check( setup.act_phase_instructions, arrangement_w_tcds( symbol_table=setup.symbols, hds_contents=_hds_pop_of(setup), process_execution=ProcessExecutionArrangement( process_execution_settings=proc_exe_env_for_test()), act_exe_input=AtcExeInputArr(environ=environ, ), ), Expectation( symbol_usages=setup.symbol_usages, post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_proc_result. matches_proc_result(stdout=asrt.equals(var_value + '\n')))), )
def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program(self): symbol = StringConstantSymbolContext('symbol_name', 'symbol value with space') expected_output = lines_content([symbol.str_value]) source_file = 'the-source-file.py' command_line = '{source_file} {symbol}'.format( source_file=source_file, symbol=symbol.name__sym_ref_syntax, ) arrangement = integration_check.arrangement_w_tcds( hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([ fs.File( source_file, PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES) ])), symbol_table=symbol.symbol_table ) expectation = integration_check.Expectation( symbol_usages=asrt.matches_sequence( [symbol.reference_assertion__w_str_rendering] ), execute=eh_assertions.is_exit_code(0), post_sds=PostSdsExpectation.constant( sub_process_result_from_execute=asrt_pr.stdout(asrt.Equals(expected_output, 'CLI arguments, one per line')) ), ) integration_check.check_execution(self, ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE, [instr([command_line])], arrangement, expectation)