def _check_variants_with_expectation_type( self, args_variant_constructor: InstructionArgumentsVariantConstructor, expected_result_of_positive_test: PassOrFail, actual_file_contents: str, symbols: SymbolTable = None, expected_symbol_references: Assertion[Sequence[SymbolReference]] = asrt.is_empty_sequence): for expectation_type in ExpectationType: etc = expectation_type_config__non_is_success(expectation_type) with self.subTest(expectation_type=expectation_type): args_variant = args_variant_constructor.construct(expectation_type) complete_instruction_arguments = test_configuration.arguments_for(args_variant) for source in equivalent_source_variants__for_expression_parser( self, complete_instruction_arguments): integration_check.CHECKER__PARSE_FULL.check( self, source, model_constructor.of_str(self, actual_file_contents), Arrangement( tcds=TcdsArrangement( 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=etc.main_result(expected_result_of_positive_test), ), ) )
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 runTest(self): failure_message = 'failure' failing_validation_result = asrt_validation.new_single_string_text_for_test( failure_message) line_matcher_symbol_name = 'line_matcher_with_failing_validation' asserted_symbol_references = asrt.matches_sequence( [is_reference_to_line_matcher(line_matcher_symbol_name)]) validation_cases = [ NEA('failure pre sds', expected=Expectation( ParseExpectation( symbol_references=asserted_symbol_references, ), ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails( asrt.equals(failure_message)), ), ), actual=ConstantDdvValidator( pre_sds_result=failing_validation_result)), NEA('failure post sds', expected=Expectation( ParseExpectation( symbol_references=asserted_symbol_references, ), ExecutionExpectation(validation=ValidationAssertions. post_sds_fails__w_any_msg(), ), ), actual=ConstantDdvValidator( post_sds_result=failing_validation_result)), ] for case in validation_cases: symbols = LineMatcherSymbolContext.of_sdv( line_matcher_symbol_name, successful_matcher_with_validation(case.actual)).symbol_table for quantifier in Quantifier: arguments_constructor = arguments_building.ImplicitActualFileArgumentsConstructor( CommonArgumentsConstructor(), arguments_building. LineMatchesAssertionArgumentsConstructor( quantifier, line_matcher_symbol_name)) for expectation_type in ExpectationType: arguments = arguments_constructor.apply(expectation_type) source = test_configuration.arguments_for( arguments).as_remaining_source with self.subTest(case=case.name, expectation_type=expectation_type, quantifier=quantifier): self._check(source=source, model=model_constructor.arbitrary(self), arrangement=Arrangement(symbols=symbols), expectation=case.expected)
def runTest(self): self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_not} {equals} {file_option} {relativity_option} non-existing-file.txt', maybe_not=self.not_opt.nothing__if_positive__not_option__if_negative, relativity_option=self.rel_opt.option_argument)), model_constructor.empty(self), arrangement_w_tcds( post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, symbols=self.rel_opt.symbols.in_arrangement(), ), expectation_that_file_for_expected_contents_is_invalid(self.rel_opt), )
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 _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): actual_contents = '01234' for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: with self.subTest(maybe_with_transformer_option=maybe_with_transformer_option): self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_with_transformer_option} {maybe_not} {matches} {full_match} 1.3', maybe_with_transformer_option=maybe_with_transformer_option, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative)), model_constructor.of_str(self, actual_contents), arrangement_w_tcds(), Expectation( execution=ExecutionExpectation( main_result=maybe_not.fail__if_positive__pass_if_negative ), ), )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): expected_contents = 'expected contents' self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_not} {equals} {expected_contents}', expected_contents=surrounded_by_hard_quotes_str(expected_contents), maybe_not=maybe_not.nothing__if_positive__not_option__if_negative), ), model_constructor.of_str(self, expected_contents), arrangement_w_tcds( post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY), Expectation( execution=ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative ), ), )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: for maybe_full_match in FULL_MATCH_OPTION_ALTERNATIVES: with self.subTest(maybe_with_transformer_option=maybe_with_transformer_option, maybe_full_match=maybe_full_match): self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_with_transformer_option} {maybe_not} {matches} {maybe_full_match} **', maybe_with_transformer_option=maybe_with_transformer_option, maybe_full_match=maybe_full_match, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative)), model_constructor.empty(self), Arrangement(), Expectation( execution=ExecutionExpectation( validation=ValidationAssertions.pre_sds_fails__w_any_msg() ), ) )
def _check_expectation_variants( self, common_arguments: CommonArgumentsConstructor, line_matcher: str, expected_symbols: Assertion[Sequence[SymbolReference]]): parser = sut.parsers().full for expectation_type in ExpectationType: for quantifier in Quantifier: with self.subTest(expectation_type=expectation_type, quantifier=quantifier.name): arguments_for_implicit_file = arguments_building.ImplicitActualFileArgumentsConstructor( common_arguments, arguments_building. LineMatchesAssertionArgumentsConstructor( quantifier, line_matcher)).apply(expectation_type) source = test_configuration.arguments_for( arguments_for_implicit_file).as_remaining_source sdv = parser.parse(source) assert isinstance(sdv, MatcherSdv) # Sanity check expected_symbols.apply_without_message( self, sdv.references)
def _check_single_expression_type( self, args_variant_constructor: InstructionArgumentsVariantConstructor, expectation_type: ExpectationType, model: ModelConstructor, arrangement: Arrangement, expectation: Expectation): args_variant = args_variant_constructor.construct(expectation_type) complete_instruction_arguments = test_configuration.arguments_for(args_variant) for source in equivalent_source_variants__for_expression_parser( self, complete_instruction_arguments): integration_check.CHECKER__PARSE_FULL.check( self, source, model, arrangement, expectation, )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: with self.subTest( maybe_with_transformer_option=maybe_with_transformer_option ): self._check_with_source_variants( test_configuration.arguments_for( args( '{maybe_with_transformer_option} {maybe_not} {empty}', maybe_with_transformer_option= maybe_with_transformer_option, maybe_not=maybe_not. nothing__if_positive__not_option__if_negative)), model_constructor.empty(self), arrangement_w_tcds( post_population_action= MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY), Expectation(execution=ExecutionExpectation( main_result=maybe_not. pass__if_positive__fail__if_negative), ), )
def runTest(self): self._check_with_source_variants( test_configuration.arguments_for( args('{maybe_not} {equals} {file_option} {relativity_option} expected.txt', maybe_not=self.not_opt.nothing__if_positive__not_option__if_negative, relativity_option=self.rel_opt.option_argument)), model_constructor.of_str(self, 'expected'), arrangement_w_tcds( self.rel_opt.populator_for_relativity_option_root( DirContents([File('expected.txt', 'expected')])), post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, symbols=self.rel_opt.symbols.in_arrangement(), ), Expectation( ParseExpectation( symbol_references=self.rel_opt.symbols.usages_expectation(), ), ExecutionExpectation( main_result=self.not_opt.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, ), ))