예제 #1
0
    def runTest(self):
        # ARRANGE #
        string_transformer_argument = ab.binary_operator(
            names.SEQUENCE_OPERATOR_NAME,
            [
                ab.symbol_reference('TRANSFORMER_SYMBOL_1'),
                ab.symbol_reference('TRANSFORMER_SYMBOL_2'),
            ],
        )
        arguments = args2.Transformed(
            str(string_transformer_argument),
            args2.SymbolReferenceWReferenceSyntax('STRING_MATCHER_SYMBOL'))
        cases = [
            NameAndValue(
                'parse STRING-MATCHER as simple expr',
                sut.parsers().simple,
            ),
            NameAndValue(
                'parse STRING-MATCHER as full expr',
                sut.parsers().full,
            ),
        ]

        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                with self.assertRaises(
                        SingleInstructionInvalidArgumentException):
                    case.value.parse(arguments.as_remaining_source)
예제 #2
0
 def _check_variants_with_expectation_type(
         self,
         args_variant_constructor: InstructionArgumentsVariantConstructor):
     for expectation_type in ExpectationType:
         with self.subTest(expectation_type=expectation_type):
             args_variant = args_variant_constructor.construct(
                 expectation_type)
             with self.assertRaises(
                     SingleInstructionInvalidArgumentException):
                 sut.parsers().full.parse(
                     test_configuration.source_for(args_variant))
예제 #3
0
 def _check_variants_with_expectation_type_and_any_or_every(
     self, args_variant_constructor: tr.
     InstructionArgumentsConstructorForExpTypeAndQuantifier):
     for expectation_type in ExpectationType:
         for quantifier in Quantifier:
             with self.subTest(expectation_type=expectation_type,
                               any_or_every_keyword=quantifier):
                 args_variant = args_variant_constructor.construct(
                     expectation_type, quantifier)
                 with self.assertRaises(
                         SingleInstructionInvalidArgumentException):
                     sut.parsers().full.parse(
                         test_configuration.source_for(args_variant))
def parse(
    token_parser: TokenParser
) -> AssertionPart[ComparisonActualFile, StringSource]:
    string_matcher_sdv = parsers().full.parse_from_token_parser(token_parser)
    return assertion_part.compose(
        ConstructFileToCheckAssertionPart(),
        StringMatcherAssertionPart(string_matcher_sdv))
예제 #5
0
 def parse(
     self,
     fs_location_info: FileSystemLocationInfo,
     token_parser: TokenParser,
 ) -> SymbolDependentValue:
     return parse_string_matcher.parsers().full.parse_from_token_parser(
         token_parser)
예제 #6
0
 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)
예제 #7
0
 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'
             )
예제 #8
0
    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)
예제 #9
0
 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'
             )
예제 #10
0
 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'
                 )
예제 #11
0
    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,
                ),
            ))
예제 #12
0
 def parsers_for_expr_on_any_line(
         self) -> GrammarParsers[MatcherSdv[StringSource]]:
     return parse_string_matcher.parsers()
예제 #13
0
def _parse_regular_file_contents(token_parser: TokenParser) -> FileMatcherSdv:
    string_matcher = parse_string_matcher.parsers().simple.parse_from_token_parser(token_parser)
    return regular_file_contents.sdv(string_matcher)
예제 #14
0
from exactly_lib.impls.types.string_matcher import parse_string_matcher
from exactly_lib_test.impls.types.logic.test_resources import integration_check
from exactly_lib_test.impls.types.matcher.test_resources.matcher_checker import \
    MatcherPropertiesConfiguration

CHECKER__PARSE_FULL = integration_check.IntegrationChecker(
    parse_string_matcher.parsers().full,
    MatcherPropertiesConfiguration(),
    False,
)

CHECKER__PARSE_SIMPLE = integration_check.IntegrationChecker(
    parse_string_matcher.parsers().simple,
    MatcherPropertiesConfiguration(),
    False,
)
예제 #15
0
파일: parse.py 프로젝트: emilkarlen/exactly
 def parse(self, token_parser: TokenParser) -> LineMatcherSdv:
     from exactly_lib.impls.types.string_matcher import parse_string_matcher
     string_matcher_parser = parse_string_matcher.parsers(False).simple
     contents_matcher = string_matcher_parser.parse_from_token_parser(
         token_parser)
     return sdv(contents_matcher)