def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): # ARRANGE # named_transformer = StringTransformerSymbolContext.of_primitive( 'the_transformer', every_line_empty()) original_file_contents = 'some\ntext' symbols = SymbolTable( {named_transformer.name: named_transformer.symbol_table_container}) expected_symbol_reference_to_transformer = is_reference_to_string_transformer( named_transformer.name) expected_symbol_usages = asrt.matches_sequence( [expected_symbol_reference_to_transformer]) self._check_with_source_variants( test_configuration.arguments_for( args( '{transform_option} {the_transformer} {maybe_not} {empty}', the_transformer=named_transformer.name, maybe_not=maybe_not. nothing__if_positive__not_option__if_negative)), model_constructor.of_str(self, original_file_contents), arrangement_w_tcds(post_population_action= MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, symbols=symbols), Expectation( ParseExpectation(symbol_references=expected_symbol_usages), ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative, ), ))
def test_transformation_SHOULD_apply_only_to_matcher_argument(self): to_upper_transformer = StringTransformerSymbolContext.of_primitive( 'the_to_upper_transformer', string_transformers.to_uppercase()) model = contents_transformation.TransformedContentsSetup( original='text', transformed='TEXT', ) integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, args2.conjunction([ args2.Parentheses( args2.Transformed( to_upper_transformer.name, args2.Equals.eq_string(model.transformed)), ), args2.Equals.eq_string(model.original), ]).as_arguments, model_constructor.of_str(self, model.original), arrangement_w_tcds(symbols=to_upper_transformer.symbol_table), Expectation( ParseExpectation( symbol_references=asrt.matches_singleton_sequence( is_reference_to_string_transformer( to_upper_transformer.name))), ExecutionExpectation( main_result=asrt_matching_result.matches_value(True))))
def runTest(self): # ARRANGE # named_transformer = StringTransformerSymbolContext.of_primitive( _TRANSFORMER_SYMBOL_NAME, string_transformers.to_uppercase() ) contents_generator = contents_transformation.TransformedContentsSetup( original='some\ntext', transformed='SOME\nTEXT', ) symbols = self.rel_opt.symbols.in_arrangement() symbols.put(named_transformer.name, named_transformer.symbol_table_container) expected_symbol_reference_to_transformer = is_reference_to_string_transformer(named_transformer.name) expected_symbol_references = asrt.matches_sequence( [expected_symbol_reference_to_transformer] + self.rel_opt.symbols.usage_expectation_assertions() ) self._check_with_source_variants( test_configuration.arguments_for( args( '{transform_option} {transformer} {maybe_not} {equals} ' '{file_option} {relativity_option} expected.txt', transformer=named_transformer.name, maybe_not=self.not_opt.nothing__if_positive__not_option__if_negative, relativity_option=self.rel_opt.option_argument)), model_constructor.of_str(self, contents_generator.original), arrangement_w_tcds( tcds_contents=self.rel_opt.populator_for_relativity_option_root(DirContents([ File('expected.txt', contents_generator.transformed) ])), post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, symbols=symbols, ), Expectation( ParseExpectation( symbol_references=expected_symbol_references, ), ExecutionExpectation( main_result=self.not_opt.pass__if_positive__fail__if_negative, ), ), )
def test_it_SHOULD_be_possible_to_create_multiple_intermediate_files(self): # ARRANGE # original_file_contents = 'original_file_contents' expected_transformer_contents = original_file_contents.upper() transform_to_uppercase = test_transformers_setup.TO_UPPER_CASE_TRANSFORMER symbol_table_with_lines_transformer = transform_to_uppercase.symbol_table expected_symbol_references = asrt.matches_sequence([ is_reference_to_string_transformer(transform_to_uppercase.name) ]) for_all__equals__arguments = args.complete_arguments_constructor( FileQuantificationAssertionVariant( Quantifier.ALL, file_contents_arg2(sm_arg.Transformed(transform_to_uppercase.name, sm_arg.Equals.eq_string(expected_transformer_contents))) , )) relativity_root_conf = AN_ACCEPTED_SDS_REL_OPT_CONFIG etc = expectation_type_config__non_is_success(ExpectationType.POSITIVE) arguments = for_all__equals__arguments.apply(etc) # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check( self, remaining_source(arguments), model.model_with_rel_root_as_source_path(relativity_root_conf), arrangement= arrangement_w_tcds( tcds_contents=relativity_root_conf.populator_for_relativity_option_root( DirContents([ File('1.txt', original_file_contents), File('2.txt', original_file_contents), ]) ), symbols=symbol_table_with_lines_transformer ), expectation= Expectation( ParseExpectation( symbol_references=expected_symbol_references ), ExecutionExpectation( main_result=etc.pass__if_positive__fail__if_negative, ), ) )
def runTest(self): successful_transformer = StringTransformerSymbolContext.of_identity( 'successful_transformer') for case in validation_cases.failing_validation_cases( 'failing_transformer'): failing_symbol_context = case.value.symbol_context symbols = SymbolContext.symbol_table_of_contexts([ failing_symbol_context, successful_transformer, ]) order_cases = [ NameAndValue( '1st transformer fails', [failing_symbol_context.name, successful_transformer.name ]), NameAndValue( '2nd transformer fails', [successful_transformer.name, failing_symbol_context.name ]), ] for order_case in order_cases: arguments = st_args.syntax_for_sequence_of_transformers( order_case.value) expected_symbol_references = asrt.matches_sequence([ is_reference_to_string_transformer(symbol_name) for symbol_name in order_case.value ]) with self.subTest(validation_case=case.name, order_case=order_case.name): integration_check.CHECKER__PARSE_FULL.check__w_source_variants( self, Arguments(arguments), model_constructor.of_lines(self, []), arrangement_w_tcds(symbols=symbols), Expectation( ParseExpectation( symbol_references=expected_symbol_references), ExecutionExpectation( validation=case.value.expectation, ), prim_asrt__constant( is_identity_transformer(False)), ))
def runTest(self): # ARRANGE # original_model_contents = 'some text' expected_model_contents = original_model_contents.upper() cases = [ NEA( 'transformation that makes matcher match', True, string_transformers.to_uppercase(), ), NEA( 'transformation that makes matcher NOT match', False, delete_everything(), ), ] # ACT & ASSERT # integration_check.CHECKER__PARSE_FULL.check_multi__w_source_variants( self, args2.Transformed( _TRANSFORMER_SYMBOL_NAME, args2.Equals.eq_string( surrounded_by_hard_quotes_str( expected_model_contents))).as_arguments, asrt.matches_singleton_sequence( is_reference_to_string_transformer(_TRANSFORMER_SYMBOL_NAME)), model_constructor.of_str(self, original_model_contents), [ NExArr( case.name, PrimAndExeExpectation.of_exe( main_result=asrt_matching_result.matches_value( case.expected), ), arrangement_w_tcds( symbols=StringTransformerSymbolContext.of_primitive( _TRANSFORMER_SYMBOL_NAME, case.actual).symbol_table, )) for case in cases ], )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): # ARRANGE # named_transformer = StringTransformerSymbolContext.of_primitive( 'the_transformer', every_line_empty()) checked_file = File('actual.txt', 'some\ntext') symbols = named_transformer.symbol_table expected_symbol_reference_to_transformer = is_reference_to_string_transformer( named_transformer.name) expected_symbol_usages = asrt.matches_sequence( [expected_symbol_reference_to_transformer]) # ACT & ASSERT # self._check_with_source_variants( arguments=arguments_for( sm_args.args( '{transform_option} {the_transformer} {maybe_not} {empty}', the_transformer=named_transformer.name, maybe_not=maybe_not. nothing__if_positive__not_option__if_negative)), model_constructor=integration_check.constant_relative_file_name( checked_file.name), arrangement=arrangement_w_tcds( non_hds_contents=single_file_in_current_dir(checked_file), symbols=symbols, ), expectation=Expectation( ParseExpectation(symbol_references=expected_symbol_usages), ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative, ), ))
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): # ARRANGE # string_to_prepend = '.' initial_model_contents = '\n' model_after_2_transformations = ''.join( [string_to_prepend, string_to_prepend, initial_model_contents]) initial_model = model_constructor.of_str(self, initial_model_contents) equals_expected_matcher = StringMatcherSymbolContext.of_primitive( 'EQUALS_EXPECTED', EqualsMatcherTestImpl(model_after_2_transformations)) prepend_transformer_symbol = StringTransformerSymbolContext.of_primitive( 'PREPEND_TRANSFORMER', string_transformers.of_line_transformer__w_preserved_line_ending( 'prepend to each line', lambda line: (line + string_to_prepend))) prepend_trans_arg = str_trans_syntax.syntax_for_transformer_option( prepend_transformer_symbol.name) trans_and_eq_expected_matcher_source = remaining_source( '{prepend_trans_arg} {equals_expected_matcher}'.format( prepend_trans_arg=prepend_trans_arg, equals_expected_matcher=equals_expected_matcher.name, )) # ACT & ASSERT # parser = sut.parsers().full prepend_and_equals_expected_matcher_sdv = parser.parse( trans_and_eq_expected_matcher_source) prepend_and_equals_expected_matcher = StringMatcherSymbolContext.of_sdv( 'PREPEND_AND_EQUALS_EXPECTED', prepend_and_equals_expected_matcher_sdv) symbols = SymbolContext.symbol_table_of_contexts([ equals_expected_matcher, prepend_transformer_symbol, prepend_and_equals_expected_matcher, ]) expected_symbol_references = asrt.matches_sequence([ is_reference_to_string_transformer( prepend_transformer_symbol.name), is_reference_to_string_matcher( prepend_and_equals_expected_matcher.name), ]) self._check_with_source_variants( test_configuration.arguments_for( args( '{prepend_trans_arg} {maybe_not} {prepend_and_equals_expected_matcher}', prepend_trans_arg=prepend_trans_arg, maybe_not=maybe_not. nothing__if_positive__not_option__if_negative, prepend_and_equals_expected_matcher= prepend_and_equals_expected_matcher.name)), initial_model, arrangement_w_tcds(symbols=symbols), Expectation( ParseExpectation( symbol_references=expected_symbol_references, ), ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative, ), ))
def reference_assertion(self, symbol_name: str) -> Assertion[SymbolReference]: return is_reference_to_string_transformer(symbol_name)
def test_with_transformation(self): # ARRANGE # stdout_contents = 'output on stdout' stderr_contents = 'output on stderr' exit_code_cases = [0, 72] to_upper_transformer = test_transformers_setup.TO_UPPER_CASE_TRANSFORMER transformation_cases = [ NIE( 'stdout', stdout_contents.upper(), ProcOutputFile.STDOUT, ), NIE( 'stderr', stderr_contents.upper(), ProcOutputFile.STDERR, ), ] for exit_code_case in exit_code_cases: for transformation_case in transformation_cases: with self.subTest(exit_code=exit_code_case, transformation=transformation_case.name): python_source = py_pgm_with_stdout_stderr_exit_code( stdout_contents, stderr_contents, exit_code_case) program_that_executes_py_source = ProgramSymbolContext.of_sdv( 'PROGRAM_THAT_EXECUTES_PY_SOURCE', program_sdvs.for_py_source_on_command_line( python_source)) source = pgm_args.symbol_ref_command_elements( program_that_executes_py_source.name, transformation=to_upper_transformer.name ).as_remaining_source symbols = SymbolContext.symbol_table_of_contexts([ program_that_executes_py_source, to_upper_transformer ]) # ACT & ASSERT # CHECKER_W_TRANSFORMATION.check( self, source, transformation_case.input_value, arrangement_w_tcds(symbols=symbols, ), Expectation( ParseExpectation( symbol_references=asrt.matches_sequence([ program_that_executes_py_source. reference_assertion, is_reference_to_string_transformer( to_upper_transformer.name), ]), ), ExecutionExpectation( main_result=assert_process_result_data( exitcode=asrt.equals(exit_code_case), stdout_contents=asrt.equals( stdout_contents), stderr_contents=asrt.equals( stderr_contents), contents_after_transformation=asrt.equals( transformation_case.expected_value), ))))
def test_successful_parse_of_sequence(self): # ARRANGE # regex_str = 'the_regex' replacement_str = 'the_replacement' symbol = StringTransformerSymbolContext.of_primitive( 'the_symbol_name', string_transformers.must_not_be_used() ) replace_transformer_syntax = argument_syntax.syntax_for_replace_transformer(regex_str, replacement_str) defined_name = 'defined_name' cases = [ SourceCase('Expression on single line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, argument_syntax.syntax_for_sequence_of_transformers([ symbol.name, replace_transformer_syntax, ])), following_lines=['following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(2) ), SourceCase('Expression on following line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, '{new_line} {transformer_argument}', transformer_argument=argument_syntax.syntax_for_sequence_of_transformers([ symbol.name, replace_transformer_syntax, ])), following_lines=['following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(3) ), SourceCase('1st expr on first line followed by operator, 2nd expr on next line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, '{the_symbol_name} {sequence_operator}', the_symbol_name=symbol.name, sequence_operator=SEQUENCE_OPERATOR_NAME), following_lines=[replace_transformer_syntax], ), source_assertion=asrt_source.source_is_at_end ), SourceCase('1st expr on first line followed by operator, 2nd expr on next line, non-exr on 3rd line', source= remaining_source( src2(ValueType.STRING_TRANSFORMER, defined_name, '{the_symbol_name} {sequence_operator}', the_symbol_name=symbol.name, sequence_operator=SEQUENCE_OPERATOR_NAME), following_lines=[replace_transformer_syntax, 'following line'], ), source_assertion=asrt_source.is_at_beginning_of_line(3) ), ] # EXPECTATION # expected_container = matches_container( asrt.equals(ValueType.STRING_TRANSFORMER), sdv=matches_sdv_of_string_transformer_constant( references=asrt.matches_sequence([ is_reference_to_string_transformer(symbol.name), ]), primitive_value=asrt_string_transformer.is_identity_transformer(False), symbols=symbol.symbol_table, ) ) for source_case in cases: with self.subTest(source_case.name): expectation = Expectation.phase_agnostic( symbol_usages=asrt.matches_sequence([ asrt_sym_usage.matches_definition(asrt.equals(defined_name), expected_container) ]), symbols_after_main=assert_symbol_table_is_singleton( defined_name, expected_container, ), source=source_case.source_assertion ) # ACT & ASSERT # INSTRUCTION_CHECKER.check(self, source_case.source, Arrangement.phase_agnostic(), expectation)