def test_stdin_is_contents_of_string_source_WHEN_program_defines_single_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 # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layouts__source_variants( self, equivalent_source_variants__for_expr_parse__s__nsc, abstract_syntaxes.RunProgramAbsStx( test_setup.program_w_stdin_syntax(pgm_and_args_case.pgm_and_args), abstract_syntaxes.PathArgumentPositionLast() ), integration_check.ARBITRARY_MODEL, 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( symbol_references=pgm_and_args_case.references_assertion, execution=ExecutionExpectation( main_result=asrt_matching_result.matches_value(True) ), ), )
def _check_case(self, invalid_file_spec: FileSpecAbsStx, contents_case: ContentsCase, validation_case: NameAndValue[ValidationCaseWSymbolContextAndAssertion], ): symbol_context = validation_case.value.symbol_context integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, LiteralFilesSourceAbsStx(contents_case.other_valid_file_spec.value + [invalid_file_spec]), models.empty(), arrangement_wo_tcds( symbols=symbol_context.symbol_table ), MultiSourceExpectation( symbol_references=symbol_context.references_assertion, execution=ExecutionExpectation( validation=validation_case.value.assertion ) ), sub_test_identifiers={ 'validation': validation_case.name, 'other-valid-file-spec': contents_case.other_valid_file_spec.name, 'modification-type': contents_case.modification_type, } )
def runTest(self): for line_filter_case in LINE_FILTER_CASES: for preserve_new_lines in [False, True]: for regex_case in failing_regex_validation_cases(): all_symbols = line_filter_case.value.symbols + regex_case.symbols source = ReplaceRegexAbsStx.of_str( regex_case.regex_string, 'arbitrary_replacement', preserve_new_lines=preserve_new_lines, lines_filter=line_filter_case.value.syntax, ) # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layout__std_source_variants( self, source, model_constructor.arbitrary(self), arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts( all_symbols)), MultiSourceExpectation( symbol_references=line_filter_case.value. references_assertion__followed_by( regex_case.reference_assertions), execution=ExecutionExpectation( validation=regex_case.expectation), primitive=prim_asrt__constant( is_identity_transformer(False)), ), sub_test_identifiers={ 'regex_case': regex_case.case_name, 'preserve_new_lines': preserve_new_lines, 'lines_filtering': line_filter_case.name, })
def runTest(self): # ARRANGE # program_ref_case = pgm_and_args_cases.program_reference__w_argument_list() def expected_program(env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=program_ref_case.expected_command_driver(env), arguments=asrt.is_empty_sequence, ), stdin=asrt_pgm_val.is_no_stdin(), 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, OptionallyOnNewLine(WithinParensAbsStx(program_ref_case.pgm_and_args, end_paren_on_separate_line=False)), arrangement_wo_tcds( symbols=SymbolContext.symbol_table_of_contexts(program_ref_case.symbols), ), MultiSourceExpectation( symbol_references=SymbolContext.references_assertion_of_contexts(program_ref_case.symbols), primitive=expected_program, ) )
def test_string_symbol_reference(self): for other_valid_file_spec_case in OTHER_VALID_FILE_SPECS: for file_name_case in INVALID_FILE_NAMES: file_name_symbol = StringSymbolContext.of_constant( 'FILE_NAME_SYMBOL', file_name_case.value, default_restrictions=asrt_rest.is__string__w_all_indirect_refs_are_strings(), ) file_name_abs_stx = file_name_symbol.abstract_syntax for file_spec_case in file_type_and_contents_variants(file_name_abs_stx): integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, LiteralFilesSourceAbsStx(other_valid_file_spec_case.value + [file_spec_case.value]), models.empty(), arrangement_wo_tcds( symbols=file_name_symbol.symbol_table ), MultiSourceExpectation( symbol_references=file_name_symbol.references_assertion, execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ) ), sub_test_identifiers={ 'file-name': file_name_case.name, 'type-and-contents': file_spec_case.name, 'other-valid-file-spec': other_valid_file_spec_case.name, } )
def runTest(self): # ARRANGE # leaf_file_name = 'created-leaf' for create_path_case in create_path_cases(leaf_file_name): for rel_file_name_case in rel_file_name_cases__create( leaf_file_name, create_path_case.expected_created_file): syntax = LiteralFilesSourceAbsStx([ abs_stx.FileSpecAbsStx.of_file_type( create_path_case.file_type, file_name_arg( str(rel_file_name_case.file_spec_file_name)), create_path_case.contents__syntax, ) ]) # ACT & ASSERT # integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, syntax, rel_file_name_case.arrangement, arrangement_w_tcds(), MultiSourceExpectation(execution=ExecutionExpectation( main_result=asrt_fs.dir_contains_exactly_2( rel_file_name_case.expected_root_dir_contents))), sub_test_identifiers={ 'create_case': create_path_case.name, 'rel_file_name_case': rel_file_name_case.name, })
def test_transformer_component(self): checker = integration_check.checker__w_arbitrary_file_relativities() for validation_case in failing_validation_cases(): transformer_symbol = validation_case.value.symbol_context program_syntax = program_abs_stx.FullProgramAbsStx( program_abs_stx.ProgramOfSystemCommandLineAbsStx.of_str( 'a-system-command'), transformation=transformer_symbol.abstract_syntax, ) string_source_syntax = string_source_abs_stx.StringSourceOfProgramAbsStx( ProcOutputFile.STDOUT, program_syntax, ignore_exit_code=False, ) with self.subTest(validation_case.name): checker.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, OptionallyOnNewLine(string_source_syntax), arrangement_wo_tcds( symbols=transformer_symbol.symbol_table), MultiSourceExpectation( symbol_references=transformer_symbol. references_assertion, execution=ExecutionExpectation( validation=validation_case.value.expectation)))
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 # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layouts__source_variants( self, equivalent_source_variants__for_expr_parse__s__nsc, RunProgramAbsStx( test_setup.program_w_stdin_syntax( pgm_and_args_case.pgm_and_args), ), model_constructor.of_str(self, model_contents), 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( symbol_references=pgm_and_args_case. references_assertion, execution=EXECUTION_OUTPUT_IS_EMPTY, primitive=PRIMITIVE_IS_NOT_IDENTITY_TRANSFORMATION, ), )
def runTest(self): # ARRANGE # for validation_case in validation_cases.failing_validation_cases(): for preserve_new_lines in [False, True]: syntax = ReplaceRegexAbsStx.of_str( 'valid_regex', 'valid_replacement', preserve_new_lines=preserve_new_lines, lines_filter=validation_case.value.matcher_abs_stx, ) line_matcher_symbol_context = validation_case.value.symbol_context # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layout__std_source_variants( self, syntax, model_constructor.arbitrary(self), arrangement_wo_tcds( symbols=line_matcher_symbol_context.symbol_table), MultiSourceExpectation( symbol_references=line_matcher_symbol_context. references_assertion, execution=ExecutionExpectation( validation=validation_case.value.expectation, )), sub_test_identifiers={ 'preserve_new_lines': preserve_new_lines, 'validation': validation_case.name, })
def runTest(self): # ARRANGE # contents_cases: Sequence[NameAndValue[fs.FileSystemElements]] = [ NameAndValue( 'empty', (), ), NameAndValue( 'non-empty', [fs.File.empty('empty-file.txt')], ), ] for contents_case in contents_cases: symbol = FilesSourceSymbolContext.of_primitive( 'SYMBOL_NAME', FilesSourceThatWritesFileSystemElements(contents_case.value), ) # ACT & ASSERT # integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, symbol.abstract_syntax, models.empty(), arrangement_w_tcds( symbols=symbol.symbol_table, ), MultiSourceExpectation( symbol_references=symbol.references_assertion, execution=ExecutionExpectation( main_result=asrt_fs.dir_contains_exactly_2(contents_case.value) ) ), sub_test_identifiers={ 'contents': contents_case.name, } )
def test_with_reference_to_existing_file(self): referenced_file = 'referenced-file.txt' relativity_cases = [ relativity_options.conf_rel_hds(RelHdsOptionType.REL_HDS_CASE), relativity_options.conf_rel_non_hds(RelNonHdsOptionType.REL_ACT), ] for file_existence_case in FILE_EXISTENCE_CASES: for relativity_conf in relativity_cases: source_syntax = RawSystemCommandLineAbsStx.of_str( 'program_name', [ ArgumentOfExistingPathAbsStx( relativity_conf.path_abs_stx_of_name( referenced_file)) ]) with self.subTest( relativity=relativity_conf.option_string, file_do_existence_case=file_existence_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, source_syntax, arrangement_w_tcds( tcds_contents=relativity_conf. populator_for_relativity_option_root( DirContents( file_existence_case.files_for_name( referenced_file)))), MultiSourceExpectation(execution=ExecutionExpectation( validation=file_existence_case.expectation_for( relativity_conf.directory_structure_partition)) ), )
def test_transformation_only_as_source_argument(self): # ARRANGE # transformer = StringTransformerPrimitiveSymbolContext( 'STRING_TRANSFORMER', string_transformers.to_uppercase()) for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): program_w_transformer = FullProgramAbsStx( pgm_and_args_case.pgm_and_args, transformation=transformer.abstract_syntax) symbols = list(pgm_and_args_case.symbols) + [transformer] with self.subTest(command=pgm_and_args_case.name): # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( self, equivalent_source_variants__for_expr_parse__s__nsc, program_w_transformer, pgm_and_args_case.mk_arrangement( SymbolContext.symbol_table_of_contexts(symbols)), MultiSourceExpectation( symbol_references=SymbolContext. references_assertion_of_contexts(symbols), primitive=lambda env: (asrt_pgm_val.matches_program( asrt_command. matches_command(driver=pgm_and_args_case. expected_command_driver(env), arguments=asrt.is_empty_sequence), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt.matches_singleton_sequence( asrt.is_(transformer.primitive)), ))))
def test_dir(self): # ARRANGE # to_append_file = fs.File('file-to-append', 'contents of file to append') pre_existing_file = fs.File('pre-existing', 'contents of pre existing file') append_single_file__contents_syntax = abs_stx.DirContentsExplicitAbsStx( ModificationType.APPEND, abs_stx.LiteralFilesSourceAbsStx([ abs_stx.regular_file_spec( file_name_arg(to_append_file.name), abs_stx.FileContentsExplicitAbsStx( ModificationType.CREATE, str_src_abs_stx.StringSourceOfStringAbsStx.of_str( to_append_file.contents, QuoteType.HARD))) ])) target_dir_name = 'destination-dir' contents_cases: Sequence[AppendDirContentsCase] = [ AppendDirContentsCase( 'empty', [], [to_append_file], ), AppendDirContentsCase( 'non-empty', [pre_existing_file], [pre_existing_file, to_append_file], ), ] for target_location_case in target_locations(): syntax = abs_stx.LiteralFilesSourceAbsStx([ abs_stx.dir_spec( file_name_arg( target_location_case.target_rel_path(target_dir_name)), append_single_file__contents_syntax, ) ]) for contents_case in contents_cases: # ACT & ASSERT # integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, syntax, [ target_location_case.file_for_leaf( contents_case.original(target_dir_name)) ], arrangement_w_tcds(), MultiSourceExpectation(execution=ExecutionExpectation( main_result=asrt_fs.dir_contains_exactly_2([ target_location_case.file_for_leaf( fs.Dir( target_dir_name, contents_case. expected_contents_after_modification)) ]))), sub_test_identifiers={ 'contents': contents_case.name, 'target_location': target_location_case.name })
def runTest(self): # ARRANGE # arguments = ['arg'] str_src_contents = 'the_str_src_contents' stdin_syntax = str_src_abs_stx.StringSourceWithinParensAbsStx( str_src_abs_stx.StringSourceOfStringAbsStx.of_str( str_src_contents)) transformer_symbol = StringTransformerPrimitiveSymbolContext( 'TRANSFORMER', string_transformers.to_uppercase()) for pgm_and_args_case in pgm_and_args_cases.cases__w_argument_list__including_program_reference( ): program_w_stdin = FullProgramAbsStx( PgmAndArgsWArgumentsAbsStx( pgm_and_args_case.pgm_and_args, [ ArgumentOfRichStringAbsStx.of_str(arg) for arg in arguments ], ), stdin=stdin_syntax, transformation=transformer_symbol.abstract_syntax, ) symbols = list(pgm_and_args_case.symbols) + [transformer_symbol] def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver(env), arguments=asrt.equals(arguments), ), stdin=asrt.matches_singleton_sequence( asrt_str_src.matches__str( asrt.equals(str_src_contents), )), transformer=asrt.matches_singleton_sequence( asrt.is_(transformer_symbol.primitive)), ) # 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), tcds_contents=pgm_and_args_case.tcds, ), MultiSourceExpectation( symbol_references=SymbolContext. references_assertion_of_contexts(symbols), primitive=expected_program, ), sub_test_identifiers={'command': pgm_and_args_case.name})
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 test_regular(self): # ARRANGE # to_append__text = '<appended text>' non_empty_original__text = '<original text>' append_contents_syntax = abs_stx.FileContentsExplicitAbsStx( ModificationType.APPEND, str_src_abs_stx.StringSourceOfStringAbsStx.of_str_hard( to_append__text)) name_of_modified_file = 'destination.txt' contents_cases: Sequence[AppendRegularContentsCase] = [ AppendRegularContentsCase( 'empty', '', to_append__text, ), AppendRegularContentsCase( 'non-empty', non_empty_original__text, non_empty_original__text + to_append__text, ), ] for target_location_case in target_locations(): syntax = abs_stx.LiteralFilesSourceAbsStx([ abs_stx.regular_file_spec( file_name_arg( target_location_case.target_rel_path( name_of_modified_file)), append_contents_syntax, ) ]) for contents_case in contents_cases: # ACT & ASSERT # integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, syntax, [ target_location_case.file_for_leaf( contents_case.original(name_of_modified_file)) ], arrangement_w_tcds(), MultiSourceExpectation(execution=ExecutionExpectation( main_result=asrt_fs.dir_contains_exactly_2([ target_location_case.file_for_leaf( fs.File( name_of_modified_file, contents_case. expected_contents_after_modification)) ]))), sub_test_identifiers={ 'contents': contents_case.name, 'target_location': target_location_case.name })
def test_shell_program(self): argument_string_template = 'first {string_symbol} between {list_symbol} after' string_argument_symbol = StringConstantSymbolContext( 'STRING_ARGUMENT_SYMBOL', 'string argument', ) list_argument_symbol = ListConstantSymbolContext( 'LIST_ARGUMENT_SYMBOL', ['list_arg_value_1', 'list arg value 2']) symbols = [string_argument_symbol, list_argument_symbol] command_line_syntax_str = argument_string_template.format( string_symbol=string_argument_symbol.name__sym_ref_syntax, list_symbol=list_argument_symbol.name__sym_ref_syntax, ) command_line_str = argument_string_template.format( string_symbol=string_argument_symbol.str_value, list_symbol=' '.join(list_argument_symbol.constant_list), ) syntax = ProgramOfShellCommandLineAbsStx( StringLiteralAbsStx(command_line_syntax_str)) def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( command=asrt_command.equals_shell_command( command_line=command_line_str, arguments=[], ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ) expectation = MultiSourceExpectation( symbol_references=asrt.matches_sequence([ string_argument_symbol.reference_assertion__w_str_rendering, list_argument_symbol.reference_assertion__w_str_rendering, ]), primitive=expected_program, ) # 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, syntax, arrangement_wo_tcds( symbols=SymbolContext.symbol_table_of_contexts(symbols), ), expectation, )
def test_without_reference_to_existing_file(self): # ARRANGE # abstract_syntax = RawSystemCommandLineAbsStx.of_str( 'program_name', [ArgumentOfRichStringAbsStx.of_str('argument-that-is-not-a-file')]) # 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, abstract_syntax, arrangement_wo_tcds(), MultiSourceExpectation(execution=ExecutionExpectation( validation=validation.ValidationAssertions.all_passes())), )
def check__w_source_variants_for_full_line_parser_2( self, put: unittest.TestCase, arguments: Arguments, input_: INPUT, arrangement: Arrangement, expectation: Expectation[PRIMITIVE, OUTPUT], ): self.check__w_source_variants_for_full_line_parser( put, arguments, input_, arrangement, MultiSourceExpectation( expectation.parse.symbol_references, expectation.execution, expectation.primitive, ))
def _check_of_invalid_src_file( self, src_file_relativity: RelOptionType, validation: ValidationAssertions, ): # ARRANGE # checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_file_relativity)) expectation_ = MultiSourceExpectation( symbol_references=asrt.anything_goes(), execution=ExecutionExpectation( validation=validation ) ) src_file_rel_conf = conf_rel_any(src_file_relativity) transformer = StringTransformerSymbolContext.of_primitive( 'TRANSFORMER_SYMBOL', string_transformers.to_uppercase(), ) symbols = transformer.symbol_table 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): with self.subTest(src_file_variant=actual_src_file_variant.name, contents=contents_arguments.name, relativity_of_src_path=src_file_rel_conf.option_argument): # ACT & ASSERT # checker.check__abs_stx__layouts__std_source_variants__wo_input( self, OptionallyOnNewLine(contents_arguments.value), arrangement_w_tcds( tcds_contents=src_file_rel_conf.populator_for_relativity_option_root( actual_src_file_variant.value), symbols=symbols, ), expectation_, )
def _check_lines_for_constant_regex__equivalent_for_preserve_new_lines( self, lines_for: Callable[[str], List[str]], source_cases: List[TransformationCase], ): for line_filter_case in LINE_FILTER_CASES: for preserve_new_lines in [False, True]: for source_case in source_cases: source = ReplaceRegexAbsStx.of_str( source_case.regex, source_case.replacement, preserve_new_lines=preserve_new_lines, lines_filter=line_filter_case.value.syntax, ) # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layout__std_source_variants( self, source, model_constructor.of_lines( self, lines_for(source_case.regex)), arrangement_w_tcds( symbols=line_filter_case.value.symbol_table, ), MultiSourceExpectation( symbol_references=line_filter_case.value. references_assertion, execution=ExecutionExpectation( main_result=asrt_string_source. pre_post_freeze__matches_lines__identical( asrt.equals( lines_for(source_case.replacement)), may_depend_on_external_resources=asrt. equals(line_filter_case.value. may_depend_on_external_resources), )), adv=freeze_check. first_invoked_method_of_source_model__is_freeze, ), sub_test_identifiers={ 'preserve_new_lines': preserve_new_lines, 'source': repr(source.as_str__default()), 'line_filter_case': line_filter_case.name, })
def test_stdin_only_as_source_argument(self): # ARRANGE # str_src_contents = 'the_str_src_contents' stdin_syntax = str_src_abs_stx.StringSourceOfStringAbsStx.of_str( str_src_contents) for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): program_w_stdin = FullProgramAbsStx( pgm_and_args_case.pgm_and_args, stdin=stdin_syntax, ) symbols = list(pgm_and_args_case.symbols) def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver(env), arguments=asrt.is_empty_sequence), stdin=asrt.matches_singleton_sequence( asrt_str_src.matches__str( asrt.equals(str_src_contents), )), transformer=asrt_pgm_val.is_no_transformation(), ) with self.subTest(command=pgm_and_args_case.name): # 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), tcds_contents=pgm_and_args_case.tcds, ), MultiSourceExpectation( symbol_references=SymbolContext. references_assertion_of_contexts(symbols), primitive=expected_program, ))
def test_string_literal(self): for other_valid_file_spec_case in OTHER_VALID_FILE_SPECS: for file_name_case in INVALID_FILE_NAMES: file_name_abs_stx = StringLiteralAbsStx(file_name_case.value, QuoteType.HARD) for file_spec_case in file_type_and_contents_variants(file_name_abs_stx): integration_check.CHECKER.check__abs_stx__layout__std_source_variants( self, LiteralFilesSourceAbsStx(other_valid_file_spec_case.value + [file_spec_case.value]), models.empty(), arrangement_wo_tcds(), MultiSourceExpectation( execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ) ), sub_test_identifiers={ 'file-name': file_name_case.name, 'type-and-contents': file_spec_case.name, 'other-valid-file-spec': other_valid_file_spec_case.name, } )
def _check_parsing_of_program(put: unittest.TestCase, program_case: ProgramNameCase, argument_case: ArgumentsCase, symbols: SymbolTable): # ARRANGE # with put.subTest(program=program_case.name, arguments=argument_case.name): expected_references_assertion = asrt.matches_sequence( program_case.expected_symbol_references + argument_case.expected_symbol_references) def expected_program( env: AssertionResolvingEnvironment) -> Assertion[Program]: return asrt_pgm_val.matches_program( command=asrt_command.equals_system_program_command( program=program_case.expected_resolved_value, arguments=argument_case.expected_resolved_values( env.tcds)), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ) expectation = MultiSourceExpectation( symbol_references=expected_references_assertion, primitive=expected_program, ) source_abs_stx = program_case.source_element.new_w_additional_arguments( argument_case.source_elements) # ACT & ASSERT # CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input( put, equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc, source_abs_stx, arrangement_w_tcds( symbols=symbols, tcds_contents=argument_case.tcds_contents, ), expectation, )
def test_stdin_is_concatenation_of_string_sources_WHEN_program_defines_multiple_stdin(self): # ARRANGE # test_setup = MultipleStdinOfProgramTestSetup(self, exit_code=0) # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layouts__source_variants( self, equivalent_source_variants__for_expr_parse__s__nsc, abstract_syntaxes.RunProgramAbsStx( test_setup.program_w_stdin_syntax, abstract_syntaxes.PathArgumentPositionLast() ), integration_check.ARBITRARY_MODEL, arrangement_w_tcds( symbols=test_setup.program_symbol.symbol_table, process_execution=test_setup.proc_exe_env__w_stdin_check, ), MultiSourceExpectation( symbol_references=test_setup.program_symbol.references_assertion, execution=ExecutionExpectation( main_result=asrt_matching_result.matches_value(True) ), ), )
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 # integration_check.CHECKER__PARSE_FULL.check__abs_stx__layouts__source_variants( self, equivalent_source_variants__for_expr_parse__s__nsc, abstract_syntaxes.RunProgramAbsStx( test_setup.program_w_stdin_syntax, ), model_constructor.of_str(self, model_contents), arrangement_w_tcds( symbols=test_setup.program_symbol.symbol_table, process_execution=test_setup.proc_exe_env__w_stdin_check, ), MultiSourceExpectation( symbol_references=test_setup.program_symbol. references_assertion, execution=ExecutionExpectation( main_result=asrt_matching_result.matches_value(True)), ), )
def expectation_of_successful_execution__multi( output_lines: List[str], may_depend_on_external_resources: bool, symbol_references: Assertion[Sequence[SymbolReference]], is_identity_transformer: bool = False, adv: Callable[ [AssertionResolvingEnvironment], Assertion[ApplicationEnvironmentDependentValue[StringTransformer]] ] = adv_asrt__any, ) -> StMultiSourceExpectation: return MultiSourceExpectation( symbol_references=symbol_references, execution=ExecutionExpectation( main_result=asrt_string_source.pre_post_freeze__matches_lines( asrt.equals(output_lines), may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources), frozen_may_depend_on_external_resources=asrt.equals(may_depend_on_external_resources), ), ), primitive=prim_asrt__constant( asrt_string_transformer.is_identity_transformer(is_identity_transformer) ), adv=adv, )
def test_transformer_SHOULD_be_validated(self): src_file_rel_conf = conf_rel_any(RelOptionType.REL_HDS_CASE) src_file = fs.File.empty('src-file.txt') checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_file_rel_conf.relativity)) file_string_source_syntax = string_source_abs_stx.StringSourceOfFileAbsStx( src_file_rel_conf.path_abs_stx_of_name(self.src_file_name) ) str_trans_syntax = StringTransformerSymbolReferenceAbsStx( 'INVALID_STRING_TRANSFORMER' ) transformed_string_source_syntax = string_source_abs_stx.TransformedStringSourceAbsStx( file_string_source_syntax, str_trans_syntax, ) for validation_case in str_trans_validation_cases.failing_validation_cases(str_trans_syntax.symbol_name): with self.subTest(validation_case.name): v_case = validation_case.value checker.check__abs_stx__layouts__std_source_variants__wo_input( self, OptionallyOnNewLine(transformed_string_source_syntax), arrangement_w_tcds( tcds_contents=src_file_rel_conf.populator_for_relativity_option_root( fs.DirContents([src_file]) ), symbols=v_case.symbol_context.symbol_table, ), MultiSourceExpectation( symbol_references=v_case.symbol_context.references_assertion, execution=ExecutionExpectation( validation=v_case.expectation ) ), )
def runTest(self): # ARRANGE # for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(): with self.subTest(command=pgm_and_args_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, pgm_and_args_case.pgm_and_args, pgm_and_args_case.mk_arrangement(SymbolContext.symbol_table_of_contexts(pgm_and_args_case.symbols)), MultiSourceExpectation( symbol_references=SymbolContext.references_assertion_of_contexts(pgm_and_args_case.symbols), primitive=lambda env: ( asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver(env), arguments=asrt.is_empty_sequence ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ) ) ) )
def test_list_of_arguments_and_symbol_references(self): arg_wo_space = 'arg_wo_space' arg_w_space = 'an arg w space' string_symbol_1 = StringConstantSymbolContext( 'STRING_SYMBOL_1', 'value of string symbol 1', default_restrictions=asrt_data_rest.is__w_str_rendering(), ) string_symbol_2 = StringConstantSymbolContext( 'STRING_SYMBOL_2', 'value of string symbol 2', default_restrictions=asrt_data_rest.is__w_str_rendering(), ) arguments_cases = [ ArgumentsCase( 'one / wo symbol references', arguments=[ ArgumentOfRichStringAbsStx.of_str(arg_w_space, QuoteType.SOFT) ], expected_arguments=[arg_w_space], symbols=(), ), ArgumentsCase( 'two / wo symbol references', arguments=[ ArgumentOfRichStringAbsStx.of_str(arg_wo_space), ArgumentOfRichStringAbsStx.of_str(arg_w_space, QuoteType.HARD) ], expected_arguments=[arg_wo_space, arg_w_space], symbols=(), ), ArgumentsCase( 'three / w symbol references', arguments=[ ArgumentOfSymbolReferenceAbsStx(string_symbol_1.name), ArgumentOfRichStringAbsStx.of_str(arg_w_space, QuoteType.HARD), ArgumentOfSymbolReferenceAbsStx(string_symbol_2.name) ], expected_arguments=[ string_symbol_1.str_value, arg_w_space, string_symbol_2.str_value ], symbols=[string_symbol_1, string_symbol_2], ), ] # ARRANGE # for pgm_and_args_case in pgm_and_args_cases.cases__w_argument_list__excluding_program_reference( ): for arguments_case in arguments_cases: pgm_w_args = PgmAndArgsWArgumentsAbsStx( pgm_and_args_case.pgm_and_args, arguments_case.arguments) expected_arguments = asrt.equals( arguments_case.expected_arguments) symbols = list(pgm_and_args_case.symbols) + list( arguments_case.symbols) expectation = MultiSourceExpectation( symbol_references=SymbolContext. references_assertion_of_contexts(symbols), primitive=lambda env: (asrt_pgm_val.matches_program( asrt_command.matches_command( driver=pgm_and_args_case.expected_command_driver( env), arguments=expected_arguments, ), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt_pgm_val.is_no_transformation(), ))) with self.subTest(command=pgm_and_args_case.name, arguments=arguments_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, pgm_w_args, pgm_and_args_case.mk_arrangement( SymbolContext.symbol_table_of_contexts(symbols)), expectation, )