def runTest(self): # ARRANGE # rel_conf = rel_opts.conf_rel_non_hds(RelNonHdsOptionType.REL_TMP) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for case in successful_cases(): dst_path = rel_conf.path_abs_stx_of_name(case.dst_file_name) instruction_syntax = InstructionAbsStx( dst_path, case.contents_syntax, ) with self.subTest(case.name, phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx( self, instruction_syntax, embryo_arr_exp.Arrangement.phase_agnostic( symbols=SymbolContext.symbol_table_of_contexts(case.symbols), tcds=TcdsArrangement( non_hds_contents=rel_conf.populator_for_relativity_option_root__non_hds__s( case.pre_existing_files ) ), ), embryo_arr_exp.Expectation.phase_agnostic( symbol_usages=SymbolContext.usages_assertion_of_contexts(case.symbols), main_result=IS_SUCCESS, main_side_effects_on_sds=rel_conf.assert_root_dir_contains_exactly__p( case.expected_files) ), )
def test_single_file_in_root_dir(self): # ARRANGE # expected_file = File.empty('file-name.txt') for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES: with self.subTest( relativity_option_string=rel_opt_conf.option_argument, phase_is_after_act=phase_is_after_act): instruction_syntax = abs_stx.without_contents( rel_opt_conf.path_abs_stx_of_name(expected_file.name)) # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, side_effects_on_hds=f_asrt.dir_is_empty(), symbol_usages=asrt.is_empty_sequence, main_side_effects_on_sds= non_hds_dir_contains_exactly( rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
def runTest(self): # ARRANGE # dst_path = DefaultRelPathAbsStx('existing-file') for phase_is_after_act in [False, True]: for modification_type in ModificationType: checker = integration_check.checker(phase_is_after_act) for validation_case in validation_cases.failing_validation_cases(): instruction_syntax = InstructionAbsStx( dst_path, fs_abs_stx.FileContentsExplicitAbsStx(modification_type, validation_case.value.syntax), ) # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, embryo_arr_exp.Arrangement.phase_agnostic( symbols=validation_case.value.symbol_context.symbol_table, ), embryo_arr_exp.MultiSourceExpectation.phase_agnostic( validation=validation_case.value.assertion, symbol_usages=validation_case.value.symbol_context.usages_assertion, ), sub_test_identifiers={ 'modification_type': modification_type, 'phase_is_after_act': phase_is_after_act, 'validation': validation_case.name }, )
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_contents_from_here_doc(self): # ARRANGE # string_value = rich_str_abs_stx.HereDocAbsStx( 'single line in here doc\n') expected_file = fs.File('a-file-name.txt', string_value.value) rel_opt_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY dst_path = rel_opt_conf.path_abs_stx_of_name(expected_file.name) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_path, string_source_abs_stx.StringSourceOfStringAbsStx(string_value), ) 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): # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, side_effects_on_hds=f_asrt.dir_is_empty(), symbol_usages=asrt.is_empty_sequence, main_side_effects_on_sds=non_hds_dir_contains_exactly( rel_opt_conf.root_dir__non_hds, fs.DirContents([expected_file])), ))
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__with_transformer(self): # ARRANGE # src_file = fs.File('source-file.txt', 'contents of source file') expected_file = fs.File('a-file-name.txt', src_file.contents.upper()) to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) src_rel_opt_conf = ALLOWED_SRC_FILE_RELATIVITIES__BEFORE_ACT[0] dst_rel_opt_conf = conf_rel_non_hds(RelNonHdsOptionType.REL_ACT) expected_non_hds_contents = self._expected_non_hds_contents( dst_rel_opt_conf, expected_file, src_rel_opt_conf, src_file, ) transformed_file_contents_abs_stx = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name(src_file.name)), to_upper_transformer.abstract_syntax, ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_rel_opt_conf.path_abs_stx_of_name(expected_file.file_name), transformed_file_contents_abs_stx, ) symbols = to_upper_transformer.symbol_table 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): # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, tcds_contents=src_rel_opt_conf. populator_for_relativity_option_root( DirContents([src_file])), ), symbols=symbols, ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, main_side_effects_on_sds=expected_non_hds_contents, symbol_usages=to_upper_transformer.usages_assertion, ))
def runTest(self): # ARRANGE # text_printed_by_program = StringSymbolContext.of_constant('STRING_TO_PRINT_SYMBOL', 'hello world') dst_file_symbol = ConstantSuffixPathDdvSymbolContext( 'DST_FILE_SYMBOL', RelOptionType.REL_ACT, 'dst-file-name.txt', sut.REL_OPT_ARG_CONF.options.accepted_relativity_variants, ) to_upper_transformer = TO_UPPER_TRANSFORMER_SYMBOL transformed_program_output_contents_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, program_abs_stx.FullProgramAbsStx( program_abs_stx.ProgramOfPythonInterpreterAbsStx.of_execute_python_src_string( py_programs.single_line_pgm_that_prints_to( ProcOutputFile.STDOUT, text_printed_by_program.name__sym_ref_syntax ) ), transformation=to_upper_transformer.abstract_syntax, ) ) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_file_symbol.abstract_syntax, transformed_program_output_contents_syntax ) symbols = SymbolContext.symbol_table_of_contexts([ dst_file_symbol, text_printed_by_program, to_upper_transformer, ]) # ACT & ASSERT # checker = integration_check.checker(False) checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( symbols=symbols, tcds=TcdsArrangement(), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, symbol_usages=asrt.matches_sequence([ dst_file_symbol.reference_assertion__path_or_string, text_printed_by_program.reference_assertion__w_str_rendering, to_upper_transformer.reference_assertion, ]), ) )
def _check_of_invalid_src_file( self, is_after_act_2_every_src_file_rel_conf: Callable[ [bool], Sequence[RelativityOptionConfiguration]], step_of_expected_failure: Step): # ARRANGE # transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) symbols = transformer.symbol_table dst_file_rel_conf = conf_rel_any(RelOptionType.REL_TMP) expectation_ = self._expect_failure_in(step_of_expected_failure) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for src_file_rel_conf in is_after_act_2_every_src_file_rel_conf( phase_is_after_act): contents_builder = string_source_abs_stx.TransformableAbsStxBuilder( string_source_abs_stx.StringSourceOfFileAbsStx( src_file_rel_conf.path_abs_stx_of_name( self.src_file_name))) for actual_src_file_variant in self.src_file_variants: for contents_arguments in contents_builder.with_and_without_transformer_cases( transformer.abstract_syntax): instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_file_rel_conf.path_abs_stx_of_name( 'dst-file.txt'), contents_arguments.value, ) # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, tcds_contents=src_file_rel_conf. populator_for_relativity_option_root( actual_src_file_variant.value), ), symbols=symbols, ), expectation_, sub_test_identifiers={ 'phase_is_after_act': phase_is_after_act, 'contents': contents_arguments.name, 'relativity_of_src_path': src_file_rel_conf.name, })
def _check_cases_for_dst_file_setup__w_relativity_options( self, dst_file_name: str, dst_root_contents_before_execution: DirContents, ): cases_data = self._file_contents_cases() dst_file_relativity_cases = [ conf_rel_non_hds(RelNonHdsOptionType.REL_CWD), conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), ] for rel_opt_conf in dst_file_relativity_cases: non_hds_contents = rel_opt_conf.populator_for_relativity_option_root__non_hds( dst_root_contents_before_execution) dst_file = rel_opt_conf.path_abs_stx_of_name(dst_file_name) for file_contents_case in cases_data.file_contents_cases: instruction_syntax = instr_abs_stx.InstructionAbsStx( dst_file, file_contents_case.value, ) 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, dst_file_variant=rel_opt_conf.name, phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx( self, instruction_syntax, Arrangement.phase_agnostic( tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, tcds_contents=cases_data. pre_existing_files, non_hds_contents=non_hds_contents, ), symbols=cases_data.symbols, ), Expectation.phase_agnostic_2( main_result=IS_FAILURE, symbol_usages=asrt.anything_goes(), ))
def test_all_relativities__without_transformer(self): # ARRANGE # src_file = fs.File('source-file.txt', 'contents of source file') expected_file = fs.File('a-file-name.txt', src_file.contents) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) for dst_rel_opt_conf in ALLOWED_DST_FILE_RELATIVITIES: for src_rel_opt_conf in accepted_src_file_relativities( phase_is_after_act): file_contents_abs_stx = string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name(src_file.name)) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_rel_opt_conf.path_abs_stx_of_name( expected_file.file_name), file_contents_abs_stx, ) expected_non_hds_contents = self._expected_non_hds_contents( dst_rel_opt_conf, expected_file, src_rel_opt_conf, src_file) with self.subTest(phase_is_after_act=phase_is_after_act, relativity_dst=dst_rel_opt_conf. option_argument.as_str, relativity_src=src_rel_opt_conf. option_argument.as_str): # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic(tcds=TcdsArrangement( pre_population_action= SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, tcds_contents=src_rel_opt_conf. populator_for_relativity_option_root( DirContents([src_file]))), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, symbol_usages=asrt.is_empty_sequence, main_side_effects_on_sds= expected_non_hds_contents, ))
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 test_symbol_usages(self): # ARRANGE # to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) src_file = fs.File('src-file.txt', 'contents of source file') src_file_rel_conf = conf_rel_hds(RelHdsOptionType.REL_HDS_CASE) expected_dst_file = fs.File('dst-file-name.txt', src_file.contents.upper()) dst_file_symbol = ConstantSuffixPathDdvSymbolContext( 'DST_FILE_SYMBOL', RelOptionType.REL_TMP, expected_dst_file.name, sut.REL_OPT_ARG_CONF.options.accepted_relativity_variants, ) for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) src_file_rel_opt_conf = src_rel_opt_arg_conf_for_phase( phase_is_after_act) src_file_symbol = ConstantSuffixPathDdvSymbolContext( 'SRC_FILE_SYMBOL', src_file_rel_conf.relativity_option, src_file.name, src_file_rel_opt_conf.options.accepted_relativity_variants, ) transformed_file_contents = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx( src_file_symbol.abstract_syntax), StringTransformerSymbolReferenceAbsStx( to_upper_transformer.name)) instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_file_symbol.abstract_syntax, transformed_file_contents, ) symbols = SymbolContext.symbol_table_of_contexts([ dst_file_symbol, src_file_symbol, to_upper_transformer, ]) with self.subTest(phase_is_after_act=phase_is_after_act): # ACT & ASSERT # checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( symbols=symbols, tcds=TcdsArrangement( hds_contents=src_file_rel_conf. populator_for_relativity_option_root__hds( DirContents([src_file]))), ), MultiSourceExpectation.phase_agnostic( main_result=IS_SUCCESS, symbol_usages=asrt.matches_sequence([ dst_file_symbol. reference_assertion__path_or_string, src_file_symbol. reference_assertion__path_or_string, is_reference_to_string_transformer__usage( to_upper_transformer.name), ]), ), )
def _check_exit_codes(self, exit_code_cases: List[int], ignore_exit_code: bool, main_result: Assertion[Optional[TextRenderer]], expected_output_dir_contents: Optional[Callable[[str, str], DirContents]], ): # ARRANGE # destination_file_name = 'dst-file.txt' program_output = { ProcOutputFile.STDOUT: 'output on stdout', ProcOutputFile.STDERR: 'output on stderr', } transformer = TO_UPPER_TRANSFORMER_SYMBOL sym_ref_program = ProgramOfSymbolReferenceAbsStx('PROGRAM_SYMBOL_NAME') program_builder = program_abs_stx.TransformableProgramAbsStxBuilder( ProgramOfSymbolReferenceAbsStx(sym_ref_program.symbol_name) ) program_cases = [ ProgramAndSymbolsCase( 'without transformation', program_builder.without_transformation(), [], adapt_expected_program_output=lambda s: s ), ProgramAndSymbolsCase( 'with transformation', program_builder.with_transformation(transformer.abstract_syntax), [transformer], adapt_expected_program_output=str.upper ), ] program_builder.with_and_without_transformer_cases(transformer.abstract_syntax) py_file_rel_conf = rel_opt.conf_rel_any(RelOptionType.REL_HDS_CASE) dst_file_rel_conf = ARBITRARY_ALLOWED_DST_FILE_RELATIVITY for output_file in ProcOutputFile: for exit_code in exit_code_cases: py_file = File('exit-with-hard-coded-exit-code.py', py_programs.py_pgm_with_stdout_stderr_exit_code( exit_code=exit_code, stdout_output=program_output[ProcOutputFile.STDOUT], stderr_output=program_output[ProcOutputFile.STDERR], ), ) py_file_conf = py_file_rel_conf.named_file_conf(py_file.name) dst_file_conf = dst_file_rel_conf.named_file_conf(destination_file_name) program_symbol = ProgramSymbolContext.of_sdv( sym_ref_program.symbol_name, program_sdvs.interpret_py_source_file_that_must_exist(py_file_conf.path_sdv) ) for program_case in program_cases: instruction_syntax = instr_abs_stx.create_w_explicit_contents( dst_file_conf.abstract_syntax, string_source_abs_stx.StringSourceOfProgramAbsStx( output_file, program_case.syntax, ignore_exit_code=ignore_exit_code) ) expected_program_output = program_case.adapt_expected_program_output(program_output[output_file]) main_side_effects_on_sds = ( dst_file_rel_conf.assert_root_dir_contains_exactly( expected_output_dir_contents(dst_file_conf.name, expected_program_output) ) if expected_output_dir_contents is not None else asrt.anything_goes() ) symbol_contexts = [program_symbol] + program_case.additional_symbols # ACT && ASSERT # for phase_is_after_act in [False, True]: checker = integration_check.checker(phase_is_after_act) checker.check__abs_stx__std_layouts_and_source_variants( self, instruction_syntax, Arrangement.phase_agnostic( symbols=SymbolContext.symbol_table_of_contexts(symbol_contexts), tcds=TcdsArrangement( tcds_contents=py_file_rel_conf.populator_for_relativity_option_root( DirContents([py_file]) ) ), ), MultiSourceExpectation.phase_agnostic( symbol_usages=SymbolContext.usages_assertion_of_contexts(symbol_contexts), main_result=main_result, main_side_effects_on_sds=main_side_effects_on_sds, ), sub_test_identifiers={ 'exit_code': exit_code, 'output_file': output_file, 'program': program_case.name, 'phase_is_after_act': phase_is_after_act, }, )