Example #1
0
    def parse_from_source(self,
                          source: ParseSource,
                          must_be_on_current_line: bool = True) -> AssertPhaseInstruction:
        with token_stream_parser.from_parse_source(
                source,
                consume_last_line_if_is_at_eof_after_parse=True) as token_parser:
            assert isinstance(token_parser,
                              token_stream_parser.TokenParser), 'Must have a TokenParser'  # Type info for IDE
            token_parser = token_parser_with_additional_error_message_format_map(token_parser,
                                                                                 self.format_map)
            if must_be_on_current_line:
                token_parser.require_is_not_at_eol('Missing {PATH} argument')

            path_to_check = parse_file_ref.parse_file_ref_from_token_parser(config.ACTUAL_RELATIVITY_CONFIGURATION,
                                                                            token_parser)

            actual_path_checker_assertion_part = self._actual_path_checker_assertion_part(path_to_check)

            files_matcher_resolver = parse_files_matcher.parse_files_matcher(token_parser,
                                                                             must_be_on_current_line=False)

            token_parser.report_superfluous_arguments_if_not_at_eol()
            token_parser.consume_current_line_as_string_of_remaining_part_of_current_line()

            assertions = assertion_part.compose(
                actual_path_checker_assertion_part,
                impl_utils.FilesMatcherAsDirContentsAssertionPart(files_matcher_resolver),
            )

            return assertion_part.AssertionInstructionFromAssertionPart(assertions,
                                                                        None,
                                                                        lambda x: FilesSource(path_to_check))
Example #2
0
 def parse_from_source(self, source: ParseSource) -> AssertPhaseInstruction:
     with token_stream_parser.from_parse_source(
             source,
             consume_last_line_if_is_at_eof_after_parse=True) as token_parser:
         assert isinstance(token_parser,
                           token_stream_parser.TokenParser), 'Must have a TokenParser'  # Type info for IDE
         return self._parse(token_parser)
Example #3
0
 def parse_from_source(self, source: ParseSource) -> AssertPhaseInstruction:
     with token_stream_parser.from_parse_source(
             source, consume_last_line_if_is_at_eof_after_parse=True
     ) as token_parser:
         assert isinstance(token_parser, token_stream_parser.TokenParser
                           ), 'Must have a TokenParser'  # Type info for IDE
         return self._parse(token_parser)
Example #4
0
 def parse(
     self,
     source: ParseSource,
     source_file_location: Optional[pathlib.Path] = None,
 ):
     with token_stream_parser.from_parse_source(source) as token_parser:
         return self.parse_from_token_parser(token_parser,
                                             source_file_location)
def parse_from_parse_source(source: ParseSource,
                            conf: RelOptionArgumentConfiguration = CONFIGURATION) -> StringOrFileRefResolver:
    with from_parse_source(source,
                           consume_last_line_if_is_at_eol_after_parse=False) as token_parser:
        ret_val = parse_from_token_parser(token_parser, conf)
    if ret_val.source_type is SourceType.HERE_DOC:
        if source.is_at_eol:
            source.consume_current_line()
    return ret_val
Example #6
0
    def parse(self, fs_location_info: FileSystemLocationInfo,
              source: ParseSource) -> AssertPhaseInstruction:
        with token_stream_parser.from_parse_source(
                source, consume_last_line_if_is_at_eol_after_parse=True
        ) as token_parser:
            object_name, model_getter = self._parse_setup(token_parser)
            int_matcher = self._matcher_parser.parse_from_token_parser(
                token_parser)

            token_parser.report_superfluous_arguments_if_not_at_eol()

            return _instruction(object_name, int_matcher, model_getter)
Example #7
0
    def parse_from_source(self, source: ParseSource) -> SetupPhaseInstruction:
        with from_parse_source(source,
                               consume_last_line_if_is_at_eof_after_parse=True
                               ) as token_parser:
            token_parser.consume_mandatory_constant_string_that_must_be_unquoted_and_equal(
                [instruction_arguments.ASSIGNMENT_OPERATOR], lambda x: x)
            string_source = self._str_src_parser.parse_from_token_parser(
                token_parser)

            token_parser.report_superfluous_arguments_if_not_at_eol()
            token_parser.consume_current_line_as_string_of_remaining_part_of_current_line(
            )

            return _Instruction(string_source)
Example #8
0
def _check_parse_from_token_parser(
        put: unittest.TestCase, source: ParseSource,
        expected_parsed_value: int,
        expected_source_after_parse: Assertion[ParseSource]):
    with token_stream_parser.from_parse_source(source, False,
                                               False) as token_parser:
        # ACT #
        actual = _SUT_PARSER_OF_INT.parse_from_token_parser(token_parser)
    # ASSERT #
    put.assertEqual(expected_parsed_value, actual, 'parsed value')
    expected_source_after_parse.apply_with_message(
        put,
        source,
        'source',
    )
Example #9
0
    def _parse(self, source: ParseSource) -> embryo.InstructionEmbryo:
        first_line_number = source.current_line_number
        with from_parse_source(source,
                               consume_last_line_if_is_at_eol_after_parse=True) as parser:
            assert isinstance(parser, TokenParser)  # Type info for IDE

            path_to_create = parse_file_ref.parse_file_ref_from_token_parser(REL_OPT_ARG_CONF, parser)
            instruction_config = InstructionConfig(
                InstructionSourceInfo(first_line_number,
                                      self._instruction_name),
                _src_rel_opt_arg_conf_for_phase(self._phase_is_after_act),
                CONTENTS_ARGUMENT
            )

            file_maker = parse_file_contents(instruction_config, parser)

            return TheInstructionEmbryo(path_to_create, file_maker)
Example #10
0
 def check__abs_stx__expr_parse_source_variants(
         self,
         put: unittest.TestCase,
         syntax: AbstractSyntax,
         symbols: Optional[SymbolTable],
         expectation: Expectation[T],
         sub_test_identifiers: Mapping[str, Any] = MappingProxyType({}),
 ):
     if symbols is None:
         symbols = SymbolTable.empty()
     for formatting_case in abs_stx_utils.formatting_cases(syntax):
         for equivalent_source_case in equivalent_source_variants.expr_parse__s__nsc(
                 formatting_case.value):
             with put.subTest(
                     zz_formatting=formatting_case.name,
                     zz_following_source_variant=equivalent_source_case.
                     name,
                     **sub_test_identifiers):
                 parse_source = equivalent_source_case.source
                 with token_stream_parser.from_parse_source(
                         parse_source) as token_parser:
                     # ACT
                     sdv = self._parser.parse(token_parser)
                 # ASSERT #
                 equivalent_source_case.expectation.apply_with_message(
                     put,
                     parse_source,
                     'source after parse',
                 )
                 expectation.symbol_references.apply_with_message(
                     put,
                     sdv.references,
                     'symbol references',
                 )
                 expectation.sdv.apply_with_message(
                     put, sdv, 'custom sdv expectation')
                 # ACT #
                 ddv = sdv.resolve(symbols)
                 # ASSERT #
                 expectation.ddv.apply_with_message(
                     put,
                     ddv,
                     'ddv',
                 )
 def test_failing_parse(self):
     cases = [
         (
             'no arguments',
             remaining_source(''),
         ),
         (
             'no arguments, but it appears on the following line',
             remaining_source('',
                              [comparators.EQ.name + ' 1']),
         ),
         (
             'invalid OPERATOR',
             remaining_source('- 72'),
         ),
         (
             'quoted OPERATOR',
             remaining_source('"{op}" 69'.format(op=comparators.EQ.name)),
         ),
         (
             'missing INTEGER',
             remaining_source(comparators.EQ.name),
         ),
         (
             'missing INTEGER, but it appears on following line',
             remaining_source(comparators.EQ.name,
                              ['72']),
         ),
         (
             'invalid INTEGER',
             remaining_source(comparators.EQ.name + ' 0.5'),
         ),
         (
             'invalid INTEGER expression',
             remaining_source(comparators.EQ.name + ' "1 + [50]"'),
         ),
     ]
     for name, source in cases:
         with self.subTest(case_name=name):
             with self.assertRaises(SingleInstructionInvalidArgumentException):
                 with from_parse_source(source) as parser:
                     sut.parse_integer_matcher(parser)
Example #12
0
    def parse_from_source(
            self,
            source: ParseSource,
            must_be_on_current_line: bool = True) -> AssertPhaseInstruction:
        with token_stream_parser.from_parse_source(
                source, consume_last_line_if_is_at_eof_after_parse=True
        ) as token_parser:
            token_parser = token_parser_with_additional_error_message_format_map(
                token_parser, self.format_map)

            if must_be_on_current_line:
                token_parser.require_is_not_at_eol('Missing {PATH} argument')

            path_to_check = self._path_parser.parse_from_token_parser(
                token_parser)

            token_parser.consume_mandatory_constant_unquoted_string(
                reserved_words.COLON, must_be_on_current_line=False)

            files_matcher_model_constructor = parse_file_matcher.DIR_CONTENTS_MODEL_PARSER.parse(
                token_parser)

            actual_path_checker_assertion_part = self._actual_path_checker_assertion_part(
                path_to_check)

            files_matcher_sdv = parse_files_matcher.parsers(
            ).full.parse_from_token_parser(token_parser)

            token_parser.report_superfluous_arguments_if_not_at_eol()
            token_parser.consume_current_line_as_string_of_remaining_part_of_current_line(
            )

            assertions = assertion_part.compose(
                actual_path_checker_assertion_part,
                impl_utils.FilesMatcherAsDirContentsAssertionPart(
                    files_matcher_model_constructor, files_matcher_sdv),
            )

            return assertion_part.AssertionInstructionFromAssertionPart(
                assertions, lambda x: FilesSource(path_to_check))
Example #13
0
    def parse(self,
              fs_location_info: FileSystemLocationInfo,
              source: ParseSource) -> TheInstructionEmbryo:
        first_line_number = source.current_line_number
        instruction_name_prefix = source.current_line_text[:source.column_index]
        remaining_source_before = source.remaining_source

        with from_parse_source(source,
                               consume_last_line_if_is_at_eol_after_parse=True,
                               consume_last_line_if_is_at_eof_after_parse=True) as token_parser:
            symbol_name, value_resolver = _parse(fs_location_info, token_parser)

        remaining_source_after = source.remaining_source
        num_chars_consumed = len(remaining_source_before) - len(remaining_source_after)
        parsed_str = remaining_source_before[:num_chars_consumed]
        source_lines = LineSequence(first_line_number,
                                    (instruction_name_prefix + parsed_str).splitlines())

        source_info = fs_location_info.current_source_file.source_location_info_for(source_lines)
        sym_def = SymbolDefinition(symbol_name,
                                   SymbolContainer(value_resolver,
                                                   source_info))

        return TheInstructionEmbryo(sym_def)
Example #14
0
 def _parse(self, source: ParseSource) -> _TheInstructionEmbryo:
     with from_parse_source(
             source,
             consume_last_line_if_is_at_eol_after_parse=True) as tokens:
         return self._parse_from_tokens(tokens)
Example #15
0
def parse_list(source: ParseSource) -> ListSdv:
    with from_parse_source(source) as token_parser:
        return parse_list_from_token_parser(token_parser)
Example #16
0
 def parse(self, source: ParseSource) -> PARSE_RESULT:
     with from_parse_source(source,
                            self._consume_last_line_if_is_at_eol_after_parse,
                            self._consume_last_line_if_is_at_eof_after_parse) as parser:
         return self.parse_from_token_parser(parser)
Example #17
0
def parse_list(source: ParseSource) -> ListResolver:
    with from_parse_source(source) as token_parser:
        return parse_list_from_token_parser(token_parser)
Example #18
0
def parse_from_parse_source(grammar: Grammar,
                            source: ParseSource):
    with token_stream_parser.from_parse_source(source) as tp:
        return parse(grammar, tp)
Example #19
0
 def parse(self, source: ParseSource) -> PARSE_RESULT:
     with from_parse_source(
             source, self._consume_last_line_if_is_at_eol_after_parse,
             self._consume_last_line_if_is_at_eof_after_parse) as parser:
         return self.parse_from_token_parser(parser)
Example #20
0
 def parse_from_source(self, source: ParseSource) -> AssertPhaseInstruction:
     with from_parse_source(source,
                            consume_last_line_if_is_at_eol_after_parse=True) as parser:
         return self.parse_from_token_parser(parser)
Example #21
0
 def _parse(self, source: ParseSource) -> InstructionEmbryo[T]:
     with token_stream_parser.from_parse_source(
             source, consume_last_line_if_is_at_eol_after_parse=True
     ) as token_parser:
         return self._parse_from_tokens(token_parser)
Example #22
0
def parse(source: ParseSource) -> NameAndValue[Actor]:
    with token_stream_parser.from_parse_source(
            source,
            consume_last_line_if_is_at_eol_after_parse=True) as token_parser:
        return _parse_from_token_parser(token_parser)
Example #23
0
 def parse_from_source(self, source: ParseSource) -> AssertPhaseInstruction:
     with from_parse_source(
             source,
             consume_last_line_if_is_at_eol_after_parse=True) as parser:
         return self.parse_from_token_parser(parser)
 def test_successful_parse(self):
     # ARRANGE #
     cases = [
         Case(comparators.EQ.name + ' plain integer',
              remaining_source(comparators.EQ.name + ' 1'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.EQ, 1),
                                                [
                                                    model_of(-1),
                                                    model_of(1),
                                                    model_of(2),
                                                ])),
         Case(comparators.NE.name,
              remaining_source(comparators.NE.name + ' 1'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.NE, 1),
                                                [
                                                    model_of(-1),
                                                    model_of(1),
                                                    model_of(2),
                                                ])),
         Case(comparators.LT.name,
              remaining_source(comparators.LT.name + ' 69'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.LT, 69),
                                                [
                                                    model_of(60),
                                                    model_of(69),
                                                    model_of(72),
                                                ])),
         Case(comparators.LTE.name,
              remaining_source(comparators.LTE.name + '  69'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.LTE, 69),
                                                [
                                                    model_of(60),
                                                    model_of(69),
                                                    model_of(72),
                                                ])),
         Case(comparators.GT.name,
              remaining_source(comparators.GT.name + ' 69'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.GT, 69),
                                                [
                                                    model_of(60),
                                                    model_of(69),
                                                    model_of(72),
                                                ])),
         Case(comparators.GTE.name,
              remaining_source(comparators.GTE.name + ' 69'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.GTE, 69),
                                                [
                                                    model_of(60),
                                                    model_of(69),
                                                    model_of(72),
                                                ])),
         Case(comparators.GTE.name + ' following content on line',
              remaining_source(comparators.GTE.name + ' 72 next'),
              source_assertion=
              assert_source(remaining_part_of_current_line=asrt.equals('next')),
              result_assertion=is_equivalent_to(matcher_of(comparators.GTE, 72),
                                                [
                                                    model_of(69),
                                                    model_of(72),
                                                    model_of(80),
                                                ])),
         Case(comparators.EQ.name + ' integer expression',
              remaining_source('== "69+72"'),
              source_assertion=
              assert_source(is_at_eol=asrt.is_true),
              result_assertion=is_equivalent_to(matcher_of(comparators.EQ, 69 + 72),
                                                [
                                                    model_of(69 + 72 - 1),
                                                    model_of(69 + 72),
                                                    model_of(69 + 72 + 1),
                                                ])),
     ]
     for case in cases:
         with from_parse_source(case.source) as parser:
             # ACT #
             actual = sut.parse_integer_matcher(parser, _NAME_OF_LHS)
             # ASSERT #
         case.source_assertion.apply_with_message(self, case.source, 'source')
         case.result_assertion.apply_with_message(self, actual, 'parsed value')