def test_stdin_is_concatenation_of_string_sources_WHEN_program_defines_multiple_stdin( self): # ARRANGE # test_setup = MultipleStdinOfProgramTestSetup(self, exit_code=0) # ACT & ASSERT # for output_file in ProcOutputFile: for ignore_exit_code in [False, True]: with self.subTest(output_file=output_file, ignore_exit_code=ignore_exit_code): CHECKER.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, StringSourceOfProgramAbsStx( output_file, test_setup.program_w_stdin_syntax, ignore_exit_code, ), arrangement_w_tcds( symbols=test_setup.program_symbol.symbol_table, process_execution=test_setup. proc_exe_env__w_stdin_check, ), MultiSourceExpectation.of_prim__const( symbol_references=test_setup.program_symbol. references_assertion, primitive=IS_EMPTY_STRING_SOURCE, ), )
def test_without_transformer(self): # ARRANGE # src_file = fs.File('source-file.txt', 'contents of source file') src_rel_opt_conf = conf_rel_any(RelOptionType.REL_TMP) checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_rel_opt_conf.relativity)) file_contents_abs_stx = string_source_abs_stx.StringSourceOfFileAbsStx( src_rel_opt_conf.path_abs_stx_of_name(src_file.name) ) # ACT & ASSERT # checker.check__abs_stx__layouts__std_source_variants__wo_input( self, OptionallyOnNewLine(file_contents_abs_stx), arrangement_w_tcds( tcds_contents=src_rel_opt_conf.populator_for_relativity_option_root( DirContents([src_file])) ), MultiSourceExpectation.of_prim__const( asrt_string_source.pre_post_freeze__matches_str__const( src_file.contents, may_depend_on_external_resources=True, ), symbol_references=asrt.is_empty_sequence, ) )
def test_stdin_is_contents_of_string_source_WHEN_program_defines_single_stdin( self): # ARRANGE # test_setup = SingleStdinOfProgramTestSetup(self, exit_code=0) for output_file in ProcOutputFile: for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): for ignore_exit_code in [False, True]: with self.subTest(output_file=output_file, program=pgm_and_args_case.name, ignore_exit_code=ignore_exit_code): # ACT & ASSERT # CHECKER.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, StringSourceOfProgramAbsStx( output_file, test_setup.program_w_stdin_syntax( pgm_and_args_case.pgm_and_args), ignore_exit_code, ), arrangement_w_tcds( symbols=pgm_and_args_case.symbol_table, process_execution=test_setup. proc_exe_env__w_stdin_check, tcds_contents=pgm_and_args_case.tcds, ), MultiSourceExpectation.of_prim__const( symbol_references=pgm_and_args_case. references_assertion, primitive=IS_EMPTY_STRING_SOURCE, ), )
def runTest(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_contents = src_file.contents.upper() path_relativity_variants = PathRelativityVariants({src_file_rel_conf.relativity}, True) checker = integration_check.checker(RelOptionsConfiguration(path_relativity_variants, src_file_rel_conf.relativity)) src_file_symbol = ConstantSuffixPathDdvSymbolContext( 'SRC_FILE_SYMBOL', src_file_rel_conf.relativity, src_file.name, path_relativity_variants, ) string_source_syntax = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfFileAbsStx(src_file_symbol.abstract_syntax), to_upper_transformer.abstract_syntax, ) symbol_table = SymbolContext.symbol_table_of_contexts([ src_file_symbol, to_upper_transformer, ]) # ACT & ASSERT # checker.check__abs_stx__layouts__std_source_variants__wo_input( self, OptionallyOnNewLine(string_source_syntax), arrangement_w_tcds( symbols=symbol_table, hds_contents=src_file_rel_conf.populator_for_relativity_option_root__hds( DirContents([src_file])) ), MultiSourceExpectation.of_prim__const( asrt_string_source.pre_post_freeze__matches_str__const( expected_contents, may_depend_on_external_resources=True, ), symbol_references=asrt.matches_sequence([ src_file_symbol.reference_assertion__path_or_string, to_upper_transformer.reference_assertion, ]), ), )
def test_here_doc(self): # ARRANGE # string_value = rich_str_abs_stx.HereDocAbsStx( 'single line in here doc\n') string_source_syntax = string_source_abs_stx.StringSourceOfStringAbsStx( string_value) CHECKER.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_full_line_expr_parse__s__nsc, OptionallyOnNewLine( WithinParensAbsStx(string_source_syntax, end_paren_on_separate_line=True)), arrangement_w_tcds(), MultiSourceExpectation.of_prim__const( asrt_string_source.pre_post_freeze__matches_str__const( string_value.value, may_depend_on_external_resources=False, )))
def test__with_transformer(self): # ARRANGE # src_file = fs.File('source-file.txt', 'contents of source file') expected_contents = src_file.contents.upper() to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) src_rel_opt_conf = conf_rel_any(RelOptionType.REL_TMP) 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, ) symbols = to_upper_transformer.symbol_table checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_rel_opt_conf.relativity)) # ACT & ASSERT # checker.check__abs_stx__layouts__std_source_variants__wo_input( self, OptionallyOnNewLine(transformed_file_contents_abs_stx), arrangement_w_tcds( tcds_contents=src_rel_opt_conf.populator_for_relativity_option_root( DirContents([src_file])), symbols=symbols, ), MultiSourceExpectation.of_prim__const( asrt_string_source.pre_post_freeze__matches_str__const( expected_contents, may_depend_on_external_resources=True, ), symbol_references=to_upper_transformer.references_assertion, ) )
transformer_symbol = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER', string_transformers.add(str_added_by_transformer), ) ss_syntax = string_source_abs_stx.TransformedStringSourceAbsStx( string_source_abs_stx.StringSourceOfStringAbsStx(case.syntax), transformer_symbol.abstract_syntax, ) CHECKER.check__abs_stx__layouts__source_variants__wo_input( put, equivalent_source_variants__for_expr_parse__s__nsc, OptionallyOnNewLine(ss_syntax), arrangement_w_tcds(symbols=transformer_symbol.symbol_table, ), MultiSourceExpectation.of_prim__const( symbol_references=transformer_symbol.references_assertion, primitive=asrt_string_source.pre_post_freeze__matches_str__const( case.expected + str_added_by_transformer, may_depend_on_external_resources=False, )), sub_test_identifiers={'name': case.name}) def cases_w_constant_contents() -> Sequence[Case]: here_doc_contents = 'single line in here doc\n' return [ Case( 'plain string', PlainStringAbsStx(StringLiteralAbsStx('the_string_value')), 'the_string_value', ),
def _test(self, text_printed_by_program: str, expected_file_contents: str, make_arguments: Callable[[TransformableProgramAbsStxBuilder], ProgramAbsStx], additional_symbols: Dict[str, SymbolContainer], additional_symbol_references: List[Assertion[SymbolReference]], ): for proc_output_file in ProcOutputFile: python_source = py_programs.single_line_pgm_that_prints_to(proc_output_file, text_printed_by_program) program_that_executes_py_source_symbol = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_SOURCE', program_sdvs.for_py_source_on_command_line(python_source) ) program_cases = [ ProgramCase( 'python interpreter', program_abs_stx.ProgramOfPythonInterpreterAbsStx.of_execute_python_src_string(python_source), [] ), ProgramCase( 'symbol reference program', ProgramOfSymbolReferenceAbsStx(program_that_executes_py_source_symbol.name), [program_that_executes_py_source_symbol.reference_assertion], ), ] symbols_dict = { program_that_executes_py_source_symbol.name: program_that_executes_py_source_symbol.symbol_table_container, } symbols_dict.update(additional_symbols) symbols = SymbolTable(symbols_dict) checker = integration_check.checker__w_arbitrary_file_relativities() for program_case in program_cases: program_syntax_builder = TransformableProgramAbsStxBuilder(program_case.source) program_syntax = make_arguments(program_syntax_builder) expected_symbol_references = program_case.expected_references + additional_symbol_references syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( proc_output_file, program_syntax, ignore_exit_code=False, ) with self.subTest(program=program_case.name, output_channel=proc_output_file): checker.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_full_line_expr_parse__s__nsc, OptionallyOnNewLine(syntax), arrangement_w_tcds( symbols=symbols, ), MultiSourceExpectation.of_prim__const( symbol_references=asrt.matches_sequence(expected_symbol_references), primitive=asrt_string_source.pre_post_freeze__matches_str__const_2( expected_file_contents, may_depend_on_external_resources=True, frozen_may_depend_on_external_resources=asrt.anything_goes(), ), ) )