def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): expected_content_line_template = 'expected content line, with {symbol} ref' def expected_content(symbol_content: str) -> str: return expected_content_line_template.format(symbol=symbol_content) symbol = StringConstantSymbolContext('symbol_name', 'the symbol value') self._check( test_configuration.source_for( args('{maybe_not} {equals} <<EOF', maybe_not=maybe_not.nothing__if_positive__not_option__if_negative), [expected_content(symbol.name__sym_ref_syntax), 'EOF', 'following line']), model_constructor.of_str(self, lines_content([expected_content(symbol.str_value)])), arrangement_w_tcds( post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY, symbols=symbol.symbol_table), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(3), symbol_references=asrt.matches_sequence([ symbol.reference_assertion__w_str_rendering ]), ), ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative, ), ), )
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 _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): self._check( source=source_for( sm_args.args('{maybe_not} {empty}', maybe_not=maybe_not. nothing__if_positive__not_option__if_negative)), model_constructor=integration_check.constant_relative_file_name( 'non-existing.txt'), arrangement=arrangement_w_tcds(), expectation=Expectation(execution=ExecutionExpectation( is_hard_error=asrt.anything_goes()), ), )
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 _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): parser = sut.parsers().full 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): source = test_configuration.source_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), ) with self.assertRaises(SingleInstructionInvalidArgumentException): parser.parse(source)
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): checked_file = File.empty('actual.txt') self._check_with_source_variants( arguments=arguments_for( sm_args.args('{maybe_not} {empty}', 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)), expectation=Expectation(execution=ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative)), )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): checked_file = Dir.empty('a-dir') self._check( source=source_for( sm_args.args('{maybe_not} {empty}', 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)), expectation=Expectation(execution=ExecutionExpectation( is_hard_error=asrt.anything_goes()), ), )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): parser = sut.parsers().full for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: with self.subTest(maybe_with_transformer_option=maybe_with_transformer_option): source = test_configuration.source_for( args('{maybe_with_transformer_option} {maybe_not}', maybe_with_transformer_option=maybe_with_transformer_option, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative), ) with self.assertRaises(SingleInstructionInvalidArgumentException) as cm: parser.parse(source) assert_is_single_instruction_invalid_argument_exception().apply_with_message( self, cm.exception, 'exception from parser' )
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 runTest(self): for case in validation_cases.failing_validation_cases(): symbol_context = case.value.symbol_context symbols = symbol_context.symbol_table with self.subTest(case.name): self._check( source=source_for(sm_args.args(symbol_context.name)), model_constructor=integration_check. constant_relative_file_name('non-existing.txt'), arrangement=arrangement_w_tcds(symbols=symbols, ), expectation=Expectation( ParseExpectation(symbol_references=symbol_context. references_assertion, ), ExecutionExpectation( validation=case.value.expectation, ), ), )
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 _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): self._check( test_configuration.source_for( args('{maybe_not} {equals} <<EOF', maybe_not=maybe_not.nothing__if_positive__not_option__if_negative), ['expected content line', 'EOF']), model_constructor.of_str(self, lines_content(['expected content line'])), arrangement_w_tcds( post_population_action=MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(3), ), ExecutionExpectation( main_result=maybe_not.pass__if_positive__fail__if_negative, ), ), )
def _doTest(self, maybe_not: ExpectationTypeConfigForNoneIsSuccess): for case in failing_validation_cases(): with self.subTest(validation_case=case.name): self._check( test_configuration.source_for( args('{transformer_option} {maybe_not} {matches} .', transformer_option=case.value.transformer_arguments_string, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative)), model_constructor.empty(self), Arrangement( symbols=case.value.symbol_context.symbol_table ), Expectation( ParseExpectation( symbol_references=case.value.symbol_context.references_assertion ), ExecutionExpectation( validation=case.value.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 # cases = [ NameAndValue('illegal option', option_syntax.long_option_syntax('this-is-an-illegal-option')), NameAndValue('illegal argument', 'this-is-an-illegal-argument'), ] parser = sut.parsers().full for case in cases: with self.subTest(case_name=case.name): source = test_configuration.source_for( args('{illegal_argument} {maybe_not} {empty}', illegal_argument=case.value, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative), ) with self.assertRaises(SingleInstructionInvalidArgumentException) as cm: parser.parse(source) assert_is_single_instruction_invalid_argument_exception().apply_with_message( self, cm.exception, 'exception from parser' )
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): cases = [ NameAndValue('illegal option', 'this-is-an-illegal-argument'), ] parser = sut.parsers().full for case in cases: for maybe_with_transformer_option in TRANSFORMER_OPTION_ALTERNATIVES: with self.subTest(illegal_check=case.name, maybe_with_transformer_option=maybe_with_transformer_option): source = test_configuration.source_for( args('{maybe_with_transformer_option} {maybe_not} {illegal_check}', maybe_with_transformer_option=maybe_with_transformer_option, maybe_not=maybe_not.nothing__if_positive__not_option__if_negative, illegal_check=case.value, ), ) with self.assertRaises(SingleInstructionInvalidArgumentException) as cm: parser.parse(source) assert_is_single_instruction_invalid_argument_exception().apply_with_message( self, cm.exception, 'exception from parser' )
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, ), ))