def parse_from_token_parser(self, parser: TokenParser) -> ProgramSdv: instruction_argument = parser.consume_current_line_as_string_of_remaining_part_of_current_line( ) return ProgramSdvForCommand( test_command_sdvs.for_interpret_py_file_that_must_exist( path_sdvs.of_rel_option_with_const_file_name( RelOptionType.REL_ACT, instruction_argument)), AccumulatedComponents.empty())
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): # ARRANGE # model_location = RelOptionType.REL_TMP model_name = 'the-model-dir' model_path = path_sdvs.of_rel_option_with_const_file_name( model_location, model_name) model_checker_symbol_name = 'symbol_that_checks_model' contents_cases = test_data.strip_file_type_info_s([ test_data.expected_is_direct_contents_of_actual( case.name, case.value) for case in test_data.cases() ])
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 # checked_dir_location = RelOptionType.REL_TMP checked_dir_name = 'the-model-dir' checked_dir_path = path_sdvs.of_rel_option_with_const_file_name( checked_dir_location, checked_dir_name) model_checker_symbol_name = 'symbol_that_checks_model' arguments = args.recursive( RelOptPathArgument(checked_dir_name, checked_dir_location), SymbolReferenceArgument(model_checker_symbol_name), ) contents_cases = test_data.strip_file_type_info_s([ test_data.identical_expected_and_actual(case.name, case.value) for case in test_data.cases() ])
def check_single( put: unittest.TestCase, make_model: Callable[[DescribedPath], FilesMatcherModel], model_dir_contents: List[FileSystemElement], expected_model_contents: List[pathlib.Path], ): relativities = [ RelOptionType.REL_TMP, RelOptionType.REL_ACT, RelOptionType.REL_HDS_CASE, RelOptionType.REL_CWD, ] model_name = 'the-model-dir' for model_location in relativities: model_path_sdv = path_sdvs.of_rel_option_with_const_file_name( model_location, model_name) with put.subTest(relativity=model_location): tcds_contents = TcdsArrangement( pre_population_action= MK_DIR_AND_CHANGE_TO_IT_INSIDE_OF_SDS_BUT_OUTSIDE_OF_ANY_OF_THE_RELATIVITY_OPTION_DIRS, tcds_contents=tcds_populators.TcdsPopulatorForRelOptionType( model_location, DirContents([Dir(model_name, model_dir_contents)]), ), ) with tcds_with_act_as_curr_dir_3(tcds_contents) as tcds: model_path = model_path_sdv.resolve( SYMBOLS).value_of_any_dependency__d(tcds) # ACT # actual = make_model(model_path) # ASSERT # expectation = FilesMatcherModelContentsAssertion( model_path.primitive, expected_model_contents) expectation.apply_without_message(put, actual)
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 list_element_for_path(relativity: RelOptionType, name: str) -> ElementSdv: return list_sdvs.string_element( string_sdvs.from_path_sdv( path_sdvs.of_rel_option_with_const_file_name(relativity, name)))
def model_file_path(self) -> PathSdv: return path_sdvs.of_rel_option_with_const_file_name( self.model_file.location, self.model_file.name)
def path(self) -> PathSdv: return path_sdvs.of_rel_option_with_const_file_name( self.location, self.name, )