コード例 #1
0
 def runTest(self):
     actual_contents = lines_content(['no match', 'MATCH', 'not match'])
     regex_arg_str = syntax_for_regex_matcher('MATCH')
     self._check_variants_with_expectation_type(
         args_constructor_for(line_matcher=regex_arg_str),
         expected_result_of_positive_test=PassOrFail.FAIL,
         quantifier=Quantifier.ALL,
         actual_file_contents=actual_contents,
     )
コード例 #2
0
 def runTest(self):
     actual_contents = lines_content(
         ['the first MATCH', 'the MATCH again', 'MATCH finally'])
     regex_arg_str = syntax_for_regex_matcher('.*MATCH')
     self._check_variants_with_expectation_type(
         args_constructor_for(line_matcher=regex_arg_str),
         expected_result_of_positive_test=PassOrFail.PASS,
         quantifier=Quantifier.ALL,
         actual_file_contents=actual_contents,
     )
コード例 #3
0
ファイル: line_matcher.py プロジェクト: emilkarlen/exactly
    def test_successful_parse_of_regex(self):
        # ARRANGE #

        regex_str = 'the_regex'
        models_for_equivalence_check = [
            asrt_matcher.ModelInfo((1, regex_str)),
            asrt_matcher.ModelInfo((2, 'before' + regex_str + 'after')),
            asrt_matcher.ModelInfo((1, 'no match')),
        ]

        symbol = LineMatcherSymbolContext.of_sdv('the_symbol_name',
                                                 CONSTANT_TRUE_MATCHER_SDV)

        regex_matcher_syntax = argument_syntax.syntax_for_regex_matcher(
            regex_str)

        matcher_argument = argument_syntax.syntax_for_and([
            symbol.name,
            regex_matcher_syntax,
        ])

        defined_name = 'defined_name'

        argument_cases = [
            NameAndValue('value on same line', '{matcher_argument}'),
            NameAndValue('value on following line',
                         '{new_line} {matcher_argument}'),
        ]

        for argument_case in argument_cases:
            with self.subTest(argument_case.name):
                source = remaining_source(
                    src2(ValueType.LINE_MATCHER,
                         defined_name,
                         argument_case.value,
                         matcher_argument=matcher_argument),
                    following_lines=['following line'],
                )

                # EXPECTATION #

                symbol_table = symbol.symbol_table

                expected_matcher_sdv = parse_line_matcher.parsers().full.parse(
                    remaining_source(matcher_argument))

                expected_matcher = resolving_helper(
                    symbol_table).resolve_matcher(expected_matcher_sdv)

                expected_container = matches_container(
                    asrt.equals(ValueType.LINE_MATCHER),
                    sdv=type_sdv_assertions.matches_sdv_of_line_matcher(
                        references=asrt.matches_sequence([
                            is_reference_to_line_matcher(symbol.name),
                        ]),
                        primitive_value=asrt_matcher.is_equivalent_to(
                            expected_matcher, models_for_equivalence_check),
                        symbols=symbol_table,
                    ))

                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,
                    ))

                # ACT & ASSERT #

                INSTRUCTION_CHECKER.check(self, source,
                                          Arrangement.phase_agnostic(),
                                          expectation)