Beispiel #1
0
class Parser(ComparisonActualFileParser):
    _PROGRAM_PARSER = parse_program.program_parser()

    def __init__(self, checked_file: process_output_files.ProcOutputFile):
        super().__init__()
        self._checked_file = checked_file
        self._checked_file_name = process_output_files.PROC_OUTPUT_FILE_NAMES[
            checked_file]
        self._default = self._default(checked_file)

    def parse_from_token_parser(
            self, parser: TokenParser) -> ComparisonActualFileConstructor:
        return parser.consume_and_handle_optional_option(
            self._default, self._parse_program,
            defs.OUTPUT_FROM_PROGRAM_OPTION_NAME)

    def _parse_program(self,
                       parser: TokenParser) -> ComparisonActualFileConstructor:
        program = self._PROGRAM_PARSER.parse_from_token_parser(parser)
        return _ComparisonActualFileConstructorForProgram(
            self._checked_file, program)

    @staticmethod
    def _default(
        checked_file: process_output_files.ProcOutputFile
    ) -> ComparisonActualFileConstructor:
        return actual_files.ConstructorForPath(
            path_sdvs.of_rel_option(
                RelOptionType.REL_RESULT,
                path_ddvs.constant_path_part(
                    process_output_files.PROC_OUTPUT_FILE_NAMES[checked_file])
            ),
            texts.target_name_of_proc_output_file_from_act_phase(checked_file),
            False,
        )
Beispiel #2
0
class ProgramParser(TypeValueParser):
    _PARSER = parse_program.program_parser(must_be_on_current_line=False, )

    def parse(
        self,
        fs_location_info: FileSystemLocationInfo,
        token_parser: TokenParser,
    ) -> SymbolDependentValue:
        return self._PARSER.parse_from_token_parser(token_parser)
    ) -> ResultWithTransformationData:
        process_execution_settings = proc_exe_env_for_test(
            timeout_in_seconds=5)

        pgm_output_dir = resolving_environment.application_environment.tmp_files_space.new_path_as_existing_dir(
        )
        execution_result = pgm_execution.make_transformed_file_from_output(
            pgm_output_dir, process_execution_settings,
            os_services_access.new_for_current_os(),
            resolving_environment.application_environment.tmp_files_space,
            input_, primitive)
        proc_exe_result = execution_result.process_result
        stderr_contents = misc_utils.contents_of(
            proc_exe_result.files.path_of_std(ProcOutputFile.STDERR))
        stdout_contents = misc_utils.contents_of(
            proc_exe_result.files.path_of_std(ProcOutputFile.STDOUT))
        result_of_transformation = misc_utils.contents_of(
            execution_result.path_of_file_with_transformed_contents)
        proc_result_data = SubProcessResult(proc_exe_result.exit_code,
                                            stdout_contents, stderr_contents)
        return ResultWithTransformationData(proc_result_data,
                                            result_of_transformation)


CHECKER_W_TRANSFORMATION = IntegrationChecker(
    parse_program.program_parser(),
    integration_check_config.ProgramPropertiesConfiguration(
        _ExecutionAndTransformationApplier()),
    True,
)
Beispiel #4
0
    from exactly_lib.impls.types.string_matcher.impl import run_program
    return run_program.sdv(program)


class SyntaxDescription(documentation.SyntaxDescriptionBase):
    @property
    def description_rest(self) -> Sequence[ParagraphItem]:
        from exactly_lib.impls.types.matcher import help_texts
        from exactly_lib.util.textformat.textformat_parser import TextParser
        tp = TextParser({
            'MODEL': matcher_model.TEXT_MODEL,
            'PROGRAM': syntax_elements.PROGRAM_SYNTAX_ELEMENT.singular_name,
            'stdin': misc_texts.STDIN,
        })
        return help_texts.run_program_matcher_description(
            tp.fnap(_EXE_ENV_DESCRIPTION)
        )


_PROGRAM_PARSER = parse_program.program_parser(
    must_be_on_current_line=False,
)

_EXE_ENV_DESCRIPTION = """\
The {MODEL} to match is given as {stdin}.

If {PROGRAM} defines {stdin},
then the {MODEL} to match is appended to that {stdin}.
"""
Beispiel #5
0
def embryo_parser(instruction_name: str) -> spe_parts.InstructionEmbryoParser:
    return spe_parts.InstructionEmbryoParser(instruction_name,
                                             parse_program.program_parser())
Beispiel #6
0
 def __init__(self):
     self._matcher_parser = parse_integer_matcher.parsers(False).full
     self._program_parser = parse_program.program_parser(
         must_be_on_current_line=False)
Beispiel #7
0
 def __init__(self):
     self._program_parser = parse_program.program_parser(
         exe_file_relativity=relativity_configuration_of_action_to_check(
             syntax_elements.PATH_SYNTAX_ELEMENT.singular_name))
from exactly_lib.impls.types.program.parse import parse_program as sut
from exactly_lib_test.impls.types.logic.test_resources import integration_check
from exactly_lib_test.impls.types.program.test_resources import integration_check_config
from exactly_lib_test.type_val_deps.dep_variants.full_deps.test_resources import common_properties_checker

CHECKER_WO_EXECUTION = integration_check.IntegrationChecker(
    sut.program_parser(),
    integration_check_config.ProgramPropertiesConfiguration(
        common_properties_checker.ApplierThatDoesNothing(),
    ),
    True,
)
Beispiel #9
0
class TestInvalidTransformer(unittest.TestCase):
    def runTest(self):
        # ARRANGE #
        for program_case in pgm_and_args_cases.cases__w_argument_list__including_program_reference():
            for transformer_case in invalid_syntax.transformer_cases():
                with self.subTest(program=program_case.name,
                                  transformer=transformer_case.name):
                    syntax = FullProgramAbsStx(program_case.pgm_and_args,
                                               transformation=transformer_case.value)
                    # ACT & ASSERT #
                    PARSE_CHECKER.check_invalid_syntax__abs_stx(self, syntax)


class TestInvalidStdin(unittest.TestCase):
    def runTest(self):
        # ARRANGE #
        for program_case in pgm_and_args_cases.cases__w_argument_list__including_program_reference():
            for transformer_case in invalid_syntax.stdin_cases():
                with self.subTest(program=program_case.name,
                                  transformer=transformer_case.name):
                    syntax = FullProgramAbsStx(program_case.pgm_and_args,
                                               stdin=transformer_case.value)
                    # ACT & ASSERT #
                    PARSE_CHECKER.check_invalid_syntax__abs_stx(self, syntax)


PARSE_CHECKER = parse_checker.Checker(ParserAsLocationAwareParser(sut.program_parser()))

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())