Exemple #1
0
    def test_file__rel_non_hds(self):
        accepted_relativity_configurations = [
            rel_opt_conf.conf_rel_any(RelOptionType.REL_ACT),
            rel_opt_conf.conf_rel_any(RelOptionType.REL_TMP),
            rel_opt_conf.symbol_conf_rel_any(
                RelOptionType.REL_TMP, 'SYMBOL',
                RELATIVITY_OPTIONS_CONFIGURATION.options.
                accepted_relativity_variants),
        ]
        stdin_file = File('stdin.txt', 'contents of stdin / rel non-hds')

        for rel_conf in accepted_relativity_configurations:
            syntax = InstructionAbsStx(
                StringSourceOfFileAbsStx(
                    rel_conf.path_abs_stx_of_name(stdin_file.name)))
            with self.subTest(option_string=rel_conf.option_argument):
                CHECKER.check_multi_source__abs_stx(
                    self,
                    syntax,
                    Arrangement(
                        tcds_contents=rel_conf.
                        populator_for_relativity_option_root(
                            DirContents([stdin_file])),
                        symbols=rel_conf.symbols.in_arrangement(),
                    ),
                    MultiSourceExpectation(
                        symbols_after_parse=rel_conf.symbols.
                        usages_expectation(),
                        settings_builder=_stdin_is_present_and_valid(
                            stdin_file.contents,
                            may_depend_on_external_resources=True),
                    ),
                )
Exemple #2
0
    def runTest(self):
        file_in_root = File.empty('file-in-root.txt')
        files_in_root_dir = [file_in_root]

        file_matcher_symbol = FileMatcherSymbolContext.of_primitive_constant(
            'FILE_MATCHER_SYMBOL',
            True,
        )

        file_matcher_cases = [
            NInpArr(
                'wo file matcher',
                None,
                (),
            ),
            NInpArr(
                'w file matcher',
                file_matcher_symbol.abstract_syntax,
                [file_matcher_symbol],
            ),
        ]
        relativity_cases = [
            rel_opt_conf.conf_rel_any(RelOptionType.REL_TMP),
            rel_opt_conf.conf_rel_any(RelOptionType.REL_HDS_CASE),
        ]

        for expectation_type in ExpectationType:
            for file_matcher_case in file_matcher_cases:
                for rel_conf in relativity_cases:
                    with self.subTest(relativity=rel_conf.relativity,
                                      file_matcher=file_matcher_case.name,
                                      expectation_type=expectation_type):
                        CHECKER.check__abs_stx__source_variants(
                            self,
                            InstructionArguments(
                                rel_conf.path_abs_stx_of_name__c([
                                    file_in_root.name,
                                    'path-to-check'
                                ]),
                                expectation_type=expectation_type,
                                file_matcher=file_matcher_case.input,
                            ),
                            ArrangementPostAct2(
                                symbols=SymbolContext.symbol_table_of_contexts(file_matcher_case.arrangement),
                                tcds=TcdsArrangementPostAct(
                                    tcds_contents=rel_conf.populator_for_relativity_option_root(
                                        DirContents(files_in_root_dir)
                                    )
                                )
                            ),
                            MultiSourceExpectation(
                                symbol_usages=SymbolContext.usages_assertion_of_contexts(file_matcher_case.arrangement),
                                execution=ExecutionExpectation(
                                    main_result=pfh_assertions.is_pass_of_fail(
                                        expectation_type is ExpectationType.NEGATIVE
                                    )
                                )
                            )
                        )
Exemple #3
0
def relativity_options_of_symbol(
        symbol_name: str
) -> List[RelativityOptionConfigurationForRelOptionType]:
    return [
        rel_opt.default_conf_rel_any(RelOptionType.REL_HDS_CASE),
        rel_opt.conf_rel_any(RelOptionType.REL_ACT),
        rel_opt.conf_rel_any(RelOptionType.REL_TMP),
        rel_opt.symbol_conf_rel_any(
            RelOptionType.REL_TMP, symbol_name, syntax_elements.
            EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants),
        rel_opt.symbol_conf_rel_any(
            RelOptionType.REL_HDS_CASE, symbol_name, syntax_elements.
            EXE_FILE_REL_OPTION_ARG_CONF.options.accepted_relativity_variants),
    ]
    def runTest(self):
        output_to_stderr = 'on stderr'
        py_file = File(
            'exit-with-value-on-command-line.py',
            py_pgm_that_exits_with_1st_value_on_command_line(output_to_stderr))

        py_file_rel_opt_conf = relativity_options.conf_rel_any(
            RelOptionType.REL_TMP)
        py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

        program_that_executes_py_pgm_symbol = ProgramSymbolContext.of_sdv(
            'PROGRAM_THAT_EXECUTES_PY_FILE',
            program_sdvs.interpret_py_source_file_that_must_exist(
                py_file_conf.path_sdv))

        symbols = program_that_executes_py_pgm_symbol.symbol_table

        instruction_arguments = [
            pgm_args.symbol_ref_command_line(
                program_that_executes_py_pgm_symbol.name),
            0,
        ]
        self.conf.run_test(
            self,
            single_line_source(args.sequence(instruction_arguments).as_str),
            self.conf.arrangement(tcds_contents=py_file_rel_opt_conf.
                                  populator_for_relativity_option_root(
                                      DirContents([py_file])),
                                  symbols=symbols),
            self.conf.expect_success(symbol_usages=asrt.matches_sequence(
                [program_that_executes_py_pgm_symbol.reference_assertion])),
        )
Exemple #5
0
    def runTest(self):
        # ARRANGE #
        checked_dir = Dir.empty('the-checked-dir')

        fsm_1 = FilesMatcherSymbolContextOfPrimitiveConstant('fsm_1', True)
        fsm_2 = FilesMatcherSymbolContextOfPrimitiveConstant('fsm_2', False)
        symbols = [fsm_1, fsm_2]

        rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_ACT)

        arguments = args.recursive(
            rel_conf.path_argument_of_rel_name(checked_dir.name),
            fsm_args.disjunction([fsm_1.argument, fsm_2.argument]),
        )
        is_pass = fsm_1.result_value or fsm_2.result_value
        # ACT # & ASSERT #
        INSTRUCTION_CHECKER.check_2(
            self, arguments.as_remaining_source,
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(symbols),
                tcds=TcdsArrangementPostAct(
                    tcds_contents=rel_conf.
                    populator_for_relativity_option_root(
                        DirContents([checked_dir])))),
            Expectation2(
                ParseExpectation(
                    source=asrt_source.source_is_at_end,
                    symbol_usages=SymbolContext.usages_assertion_of_contexts(
                        symbols),
                ),
                ExecutionExpectation(
                    main_result=asrt_pfh.is_non_hard_error(is_pass), ),
            ))
Exemple #6
0
 def _check(self,
            expected_contents: str,
            actual_contents: str,
            may_depend_on_external_resources: bool,
            expected_result: bool,
            ):
     expected_file_relativity = rel_opt.conf_rel_any(RelOptionType.REL_HDS_CASE)
     expected_contents_file = File('expected.txt', expected_contents)
     integration_check.CHECKER__PARSE_SIMPLE.check(
         self,
         args2.Equals.eq_file(
             expected_file_relativity.path_argument_of_rel_name(expected_contents_file.name)
         ).as_remaining_source,
         model_constructor.of_str(self, actual_contents,
                                  may_depend_on_external_resources=may_depend_on_external_resources),
         arrangement_w_tcds(
             tcds_contents=expected_file_relativity.populator_for_relativity_option_root(
                 DirContents([expected_contents_file])
             )
         ),
         Expectation(
             execution=ExecutionExpectation(
                 main_result=asrt_matching_result.matches_value(
                     expected_result
                 )
             ),
         ),
     )
    def check_parsing_with_different_source_variants(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        default_relativity: RelOptionType,
        non_default_relativity: RelOptionType,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        rel_opt_configs = [
            rel_opt_conf.default_conf_rel_any(default_relativity),
            rel_opt_conf.conf_rel_any(non_default_relativity),
        ]

        for rel_opt_config in rel_opt_configs:
            for expectation_type_of_test_case in ExpectationType:
                etc = pfh_expectation_type_config(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(
                    etc, rel_opt_config)

                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self.put, instruction_arguments):
                    self._check_(
                        source,
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
    def test_without_transformer(self):
        # ARRANGE #
        src_file = fs.File('source-file.txt', 'contents of source file')
        src_rel_opt_conf = conf_rel_any(RelOptionType.REL_TMP)

        checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_rel_opt_conf.relativity))

        file_contents_abs_stx = string_source_abs_stx.StringSourceOfFileAbsStx(
            src_rel_opt_conf.path_abs_stx_of_name(src_file.name)
        )
        # ACT & ASSERT #
        checker.check__abs_stx__layouts__std_source_variants__wo_input(
            self,
            OptionallyOnNewLine(file_contents_abs_stx),
            arrangement_w_tcds(
                tcds_contents=src_rel_opt_conf.populator_for_relativity_option_root(
                    DirContents([src_file]))
            ),
            MultiSourceExpectation.of_prim__const(
                asrt_string_source.pre_post_freeze__matches_str__const(
                    src_file.contents,
                    may_depend_on_external_resources=True,
                ),
                symbol_references=asrt.is_empty_sequence,
            )
        )
Exemple #9
0
def environment_exe_case(
    environment: Dict[str, str],
    program_symbol_name: str,
) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult], Arrangement]:
    py_file = File(
        'environment-vars-check.py',
        py_programs.
        pgm_that_exists_with_zero_exit_code_iff_environment_vars_not_included(
            environment))

    py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)
    py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

    program_symbol = ProgramSymbolContext.of_sdv(
        program_symbol_name,
        program_sdvs.interpret_py_source_file_that_must_exist(
            py_file_conf.path_sdv))

    return NExArr(
        'Environment: {}'.format(repr(environment)),
        PrimAndExeExpectation.of_exe(
            main_result=asrt_run.is_result_for_py_interpreter(
                py_run_programs.EXIT_CODE_FOR_SUCCESS)),
        arrangement_w_tcds(
            tcds_contents=py_file_rel_opt_conf.
            populator_for_relativity_option_root(DirContents([py_file])),
            symbols=program_symbol.symbol_table,
            process_execution=ProcessExecutionArrangement(
                process_execution_settings=ProcessExecutionSettings.
                with_environ(environment))))
    def run_test(self):
        relativity_conf = relativity_options.conf_rel_any(
            self._missing_file_relativity)

        referenced_program_arguments = [
            'valid arg 1 of referenced', 'valid arg 2 of referenced'
        ]
        referenced_system_program_sdv = program_sdvs.system_program(
            string_sdvs.str_constant('valid-system-program'),
            ArgumentsSdv.new_without_validation(
                list_sdvs.from_str_constants(referenced_program_arguments)))

        valid_program_symbol = ProgramSymbolContext.of_sdv(
            'VALID_PROGRAM', referenced_system_program_sdv)

        invalid_argument_syntax = ArgumentOfExistingPathAbsStx(
            relativity_conf.path_abs_stx_of_name('non-existing-file'))
        reference_and_additional_invalid_argument = self.source_to_parse(
            valid_program_symbol.name,
            [invalid_argument_syntax],
        )
        # ACT & ASSERT #
        self.integration_checker(
        ).check__abs_stx__layouts__source_variants__wo_input(
            self.put,
            equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
            reference_and_additional_invalid_argument,
            arrangement_w_tcds(symbols=valid_program_symbol.symbol_table, ),
            MultiSourceExpectation.of_const(
                symbol_references=valid_program_symbol.references_assertion,
                primitive=asrt.anything_goes(),
                execution=ExecutionExpectation(
                    validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[
                        relativity_conf.directory_structure_partition], )),
        )
 def test_disallowed_relativities(self):
     # ARRANGE #
     arguments_cases = [
         NameAndValue(
             'here doc',
             string_source_abs_stx.StringSourceOfStringAbsStx(
                 rich_str_abs_stx.HereDocAbsStx('contents line\n'))),
         NameAndValue(
             'raw string',
             string_source_abs_stx.StringSourceOfStringAbsStx.of_str(
                 'raw_string_argument')),
         NameAndValue(
             'quoted string',
             string_source_abs_stx.StringSourceOfStringAbsStx.of_str(
                 'quoted string argument', QuoteType.SOFT)),
     ]
     for relativity in DISALLOWED_DST_RELATIVITIES:
         relativity_conf = conf_rel_any(relativity)
         for contents_case in arguments_cases:
             instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                 relativity_conf.path_abs_stx_of_name('file-name'),
                 contents_case.value,
             )
             with self.subTest(relativity=str(relativity),
                               contents=contents_case.name):
                 # ACT & ASSERT #
                 check_invalid_syntax__abs_stx(self, instruction_syntax)
    def check_parsing_with_different_source_variants(
        self,
        make_instruction_arguments: FilesMatcherArgumentsConstructor,
        model_constructor: ModelConstructorFromRelOptConf,
        default_relativity: RelOptionType,
        non_default_relativity: RelOptionType,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        rel_opt_configs = [
            rel_opt_conf.default_conf_rel_any(default_relativity),
            rel_opt_conf.conf_rel_any(non_default_relativity),
        ]

        for rel_opt_config in rel_opt_configs:
            for expectation_type_of_test_case in ExpectationType:
                etc = expectation_type_config__non_is_success(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(etc)

                for source in equivalent_source_variants__for_expression_parser(
                        self.put, Arguments(instruction_arguments)):
                    self._check_(
                        source,
                        model_constructor(rel_opt_config),
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
Exemple #13
0
class TestProgramViaSymbolReference(unittest.TestCase):
    output_to_stderr = 'on stderr'
    py_file = File(
        'exit-with-value-on-command-line.py',
        py_pgm_that_exits_with_1st_value_on_command_line(output_to_stderr))

    py_file_rel_opt_conf = relativity_options.conf_rel_any(
        RelOptionType.REL_TMP)
    py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

    program_that_executes_py_pgm_symbol = ProgramSymbolContext.of_sdv(
        'PROGRAM_THAT_EXECUTES_PY_FILE',
        program_sdvs.interpret_py_source_file_that_must_exist(
            py_file_conf.path_sdv))

    symbols = program_that_executes_py_pgm_symbol.symbol_table

    def test_check_zero_exit_code(self):
        EXECUTION_CHECKER.check__w_source_variants(
            self,
            args.sequence([
                pgm_args.symbol_ref_command_line(
                    self.program_that_executes_py_pgm_symbol.name), 0
            ]).as_str,
            Arrangement.phase_agnostic(
                tcds=TcdsArrangement(tcds_contents=self.py_file_rel_opt_conf.
                                     populator_for_relativity_option_root(
                                         DirContents([self.py_file])), ),
                symbols=self.symbols),
            MultiSourceExpectation.phase_agnostic(
                main_result=result_assertions.equals(0, None),
                symbol_usages=asrt.matches_sequence([
                    self.program_that_executes_py_pgm_symbol.
                    reference_assertion
                ])))

    def test_check_non_zero_exit_code(self):
        exit_code = 87
        EXECUTION_CHECKER.check__w_source_variants(
            self,
            args.sequence([
                pgm_args.symbol_ref_command_line(
                    self.program_that_executes_py_pgm_symbol.name), exit_code
            ]).as_str,
            Arrangement.phase_agnostic(
                tcds=TcdsArrangement(tcds_contents=self.py_file_rel_opt_conf.
                                     populator_for_relativity_option_root(
                                         DirContents([self.py_file])), ),
                symbols=self.symbols),
            MultiSourceExpectation.phase_agnostic(
                main_result=result_assertions.equals(exit_code,
                                                     self.output_to_stderr),
                symbol_usages=asrt.matches_sequence([
                    self.program_that_executes_py_pgm_symbol.
                    reference_assertion
                ])))
Exemple #14
0
    def test_referenced_file_does_not_exist__rel_hds(self):
        rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_HDS_CASE)
        syntax = InstructionAbsStx(
            StringSourceOfFileAbsStx(
                rel_conf.path_abs_stx_of_name('non-existing-file')))

        CHECKER.check_multi_source__abs_stx(
            self, syntax, Arrangement(),
            MultiSourceExpectation(
                validation=ValidationExpectationSvh.fails__pre_sds(), ))
Exemple #15
0
    def _check(
        self,
        output: StdOutputFilesContents,
        exit_code_cases: List[int],
        ignore_exit_code: bool,
        execution_expectation: ExecutionExpectation,
    ):
        # ARRANGE #

        py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)

        for exit_code in exit_code_cases:
            with self.subTest(non_zero_exit_code=exit_code):
                py_file = File(
                    'exit-with-hard-coded-exit-code.py',
                    py_programs.py_pgm_with_stdout_stderr_exit_code(
                        stdout_output=output.out,
                        stderr_output=output.err,
                        exit_code=exit_code,
                    ),
                )

                py_file_conf = py_file_rel_opt_conf.named_file_conf(
                    py_file.name)

                program_symbol = ProgramSymbolContext.of_sdv(
                    'PROGRAM_SYMBOL_NAME',
                    program_sdvs.interpret_py_source_file_that_must_exist(
                        py_file_conf.path_sdv))

                # ACT && ASSERT #

                integration_check.CHECKER__PARSE_FULL.check(
                    self,
                    args.syntax_for_run(
                        program_args.symbol_ref_command_elements(
                            program_symbol.name),
                        ignore_exit_code=ignore_exit_code,
                    ).as_remaining_source,
                    model_constructor.arbitrary(self),
                    arrangement_w_tcds(
                        symbols=program_symbol.symbol_table,
                        tcds_contents=py_file_rel_opt_conf.
                        populator_for_relativity_option_root(
                            DirContents([py_file])),
                    ),
                    Expectation(
                        ParseExpectation(
                            source=asrt_source.is_at_end_of_line(1),
                            symbol_references=program_symbol.
                            references_assertion),
                        execution_expectation,
                    ),
                )
    def runTest(self):
        # ARRANGE #
        clashing_file_name = 'clashing-file'
        non_clashing_file_name = 'non-clashing-file'

        clash_cases: Sequence[NameAndValue[FileSystemElements]] = [
            NameAndValue(
                'exists as regular',
                [fs.File.empty(clashing_file_name)],
            ),
            NameAndValue(
                'exists as dir',
                [fs.Dir.empty(clashing_file_name)],
            ),
            NameAndValue(
                'exists as sym-link to regular',
                [fs.File.empty(non_clashing_file_name),
                 fs.sym_link(clashing_file_name, non_clashing_file_name)],
            ),
            NameAndValue(
                'exists as broken sym-link',
                [fs.sym_link(clashing_file_name, non_clashing_file_name)],
            ),
        ]
        src_dir_relativity = relativity_options.conf_rel_any(RelOptionType.REL_HDS_CASE)
        src_dir_symbol = PathDdvSymbolContext.of_no_suffix(
            'SRC_PATH_SYMBOL',
            src_dir_relativity.relativity,
            accepted_relativities=RELATIVITY_VARIANTS__READ__BEFORE_ACT,
        )
        arguments_syntax = abs_stx.CopyOfDirContentsAbsStx(src_dir_symbol.abstract_syntax)
        for clash_case in clash_cases:
            with self.subTest(clash_case.name):
                # ACT & ASSERT #
                integration_check.CHECKER.check__abs_stx(
                    self,
                    arguments_syntax,
                    clash_case.value,
                    Arrangement(
                        symbols=src_dir_symbol.symbol_table,
                        tcds=TcdsArrangement(
                            tcds_contents=src_dir_relativity.populator_for_relativity_option_root__s(
                                [fs.File.empty(clashing_file_name)]
                            )
                        )
                    ),
                    Expectation(
                        ParseExpectation(
                            source=asrt_source.is_at_end_of_line(1),
                            symbol_references=src_dir_symbol.references_assertion,
                        ),
                        execution=ExecutionExpectation.is_any_hard_error()
                    ),
                )
Exemple #17
0
    def _check_failing_validation_of_referenced_program__for_relativity(self, missing_file_relativity: RelOptionType):
        relativity_conf = relativity_options.conf_rel_any(missing_file_relativity)

        program_symbol_with_ref_to_non_exiting_exe_file = ProgramSymbolContext.of_sdv(
            'PGM_WITH_REF_TO_EXE_FILE',
            program_sdvs.ref_to_exe_file(
                constant(simple_of_rel_option(relativity_conf.relativity_option,
                                              'non-existing-exe-file')))
        )

        program_symbol_with_ref_to_non_exiting_file_as_argument = ProgramSymbolContext.of_sdv(
            'PGM_WITH_ARG_WITH_REF_TO_FILE',
            program_sdvs.interpret_py_source_file_that_must_exist(
                constant(simple_of_rel_option(relativity_conf.relativity_option,
                                              'non-existing-python-file.py')))
        )

        expectation = MultiSourceExpectation.of_const(
            symbol_references=asrt.anything_goes(),
            primitive=asrt.anything_goes(),
            execution=ExecutionExpectation(
                validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[relativity_conf.directory_structure_partition],
            )
        )

        symbols = SymbolContext.symbol_table_of_contexts([
            program_symbol_with_ref_to_non_exiting_exe_file,
            program_symbol_with_ref_to_non_exiting_file_as_argument,
        ])
        arrangement = arrangement_w_tcds(
            symbols=symbols,
        )

        cases = [
            NameAndValue(
                'executable does not exist',
                RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_exe_file.name),
            ),
            NameAndValue(
                'file referenced from argument does not exist',
                RawProgramOfSymbolReferenceAbsStx(program_symbol_with_ref_to_non_exiting_file_as_argument.name),
            ),
        ]

        for case in cases:
            with self.subTest(case=case.name):
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self,
                    equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
                    case.value,
                    arrangement,
                    expectation,
                )
Exemple #18
0
 def test_disallowed_relativities(self):
     # ARRANGE #
     for relativity in DISALLOWED_DST_RELATIVITIES:
         relativity_conf = conf_rel_any(relativity)
         instruction_syntax = abs_stx.without_contents(
             relativity_conf.path_abs_stx_of_name('file-name'))
         # ACT & ASSERT #
         check_invalid_syntax__abs_stx(self,
                                       instruction_syntax,
                                       sub_test_identifiers={
                                           'relativity': relativity,
                                       })
Exemple #19
0
    def runTest(self):
        # ARRANGE #

        py_file = File('stdin-to-upper.py',
                       _PGM_THAT_OUTPUTS_STDIN_IN_UPPER_CASE)

        py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)
        py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

        program_symbol = ProgramSymbolContext.of_sdv(
            'PROGRAM_THAT_EXECUTES_PY_FILE',
            program_sdvs.interpret_py_source_file_that_must_exist(py_file_conf.path_sdv)
        )

        input_model_lines = [
            'the\n',
            'input\n',
            'model',
        ]
        expected_output_model_lines = list(map(str.upper, input_model_lines))

        for with_ignored_exit_code in [False, True]:
            with self.subTest(with_ignored_exit_code=with_ignored_exit_code):
                # ACT && ASSERT #

                integration_check.CHECKER__PARSE_FULL.check__w_source_variants_for_full_line_parser(
                    self,
                    args.syntax_for_run(
                        program_args.symbol_ref_command_elements(program_symbol.name),
                        ignore_exit_code=with_ignored_exit_code,
                    ),
                    model_constructor.of_lines(self, input_model_lines),
                    arrangement_w_tcds(
                        tcds_contents=py_file_rel_opt_conf.populator_for_relativity_option_root(
                            DirContents([py_file])
                        ),
                        symbols=program_symbol.symbol_table,
                    ),
                    MultiSourceExpectation(
                        symbol_references=program_symbol.references_assertion,
                        execution=ExecutionExpectation(
                            main_result=asrt_string_source.pre_post_freeze__matches_lines(
                                asrt.equals(expected_output_model_lines),
                                may_depend_on_external_resources=asrt.equals(True),
                                frozen_may_depend_on_external_resources=asrt.anything_goes(),
                            )
                        ),
                        primitive=prim_asrt__constant(
                            asrt_string_transformer.is_identity_transformer(False)
                        ),
                    ),
                )
Exemple #20
0
    def _check_of_invalid_src_file(
            self, is_after_act_2_every_src_file_rel_conf: Callable[
                [bool], Sequence[RelativityOptionConfiguration]],
            step_of_expected_failure: Step):
        # ARRANGE #
        transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )
        symbols = transformer.symbol_table

        dst_file_rel_conf = conf_rel_any(RelOptionType.REL_TMP)

        expectation_ = self._expect_failure_in(step_of_expected_failure)

        for phase_is_after_act in [False, True]:
            checker = integration_check.checker(phase_is_after_act)
            for src_file_rel_conf in is_after_act_2_every_src_file_rel_conf(
                    phase_is_after_act):
                contents_builder = string_source_abs_stx.TransformableAbsStxBuilder(
                    string_source_abs_stx.StringSourceOfFileAbsStx(
                        src_file_rel_conf.path_abs_stx_of_name(
                            self.src_file_name)))
                for actual_src_file_variant in self.src_file_variants:
                    for contents_arguments in contents_builder.with_and_without_transformer_cases(
                            transformer.abstract_syntax):
                        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                            dst_file_rel_conf.path_abs_stx_of_name(
                                'dst-file.txt'),
                            contents_arguments.value,
                        )
                        # ACT & ASSERT #
                        checker.check__abs_stx__std_layouts_and_source_variants(
                            self,
                            instruction_syntax,
                            Arrangement.phase_agnostic(
                                tcds=TcdsArrangement(
                                    pre_population_action=
                                    SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN,
                                    tcds_contents=src_file_rel_conf.
                                    populator_for_relativity_option_root(
                                        actual_src_file_variant.value),
                                ),
                                symbols=symbols,
                            ),
                            expectation_,
                            sub_test_identifiers={
                                'phase_is_after_act': phase_is_after_act,
                                'contents': contents_arguments.name,
                                'relativity_of_src_path':
                                src_file_rel_conf.name,
                            })
Exemple #21
0
    def runTest(self):
        # ARRANGE #
        model_contents = DirContents([
            Dir('a-dir', [File.empty('a-file-in-pruned-dir')]),
        ])

        file_matcher = FileMatcherSymbolContextOfPrimitiveConstant(
            'FILE_MATCHER_SYMBOL',
            True,
        )
        files_matcher__parsed = FilesMatcherSymbolContext.of_primitive(
            'FILES_MATCHER_1',
            files_matcher_test_impl.FilesMatcherNumFilesTestImpl(1))
        symbols = [file_matcher, files_matcher__parsed]

        files_matcher_bin_op_expr = fsm_args.conjunction([
            fm_args.SymbolReferenceWReferenceSyntax(
                files_matcher__parsed.name),
            fsm_args.Custom('after bin op'),
        ])

        arguments = fsm_args.Prune(
            fm_args.SymbolReferenceWReferenceSyntax(file_matcher.name),
            files_matcher_bin_op_expr,
        )
        model_rel_opt_conf = rel_opt_confs.conf_rel_any(RelOptionType.REL_ACT)
        # ACT & ASSERT #
        integration_check.CHECKER__PARSE_SIMPLE.check(
            self,
            arguments.as_remaining_source,
            models.model_constructor__recursive(
                model_rel_opt_conf.path_sdv_for_root_dir()),
            arrangement_w_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(symbols),
                tcds_contents=model_rel_opt_conf.
                populator_for_relativity_option_root(model_contents)),
            Expectation(
                ParseExpectation(
                    source=asrt_source.is_at_line(
                        current_line_number=1,
                        remaining_part_of_current_line=' '.join([
                            files_matcher_bin_op_expr.operator,
                            files_matcher_bin_op_expr.operands[1].as_str,
                        ])),
                    symbol_references=SymbolContext.
                    references_assertion_of_contexts(symbols),
                ),
                ExecutionExpectation(
                    main_result=matcher_assertions.is_matching_success(), ),
            ),
        )
Exemple #22
0
    def _check_failing_validation___for_relativity(
            self, missing_file_relativity: RelOptionType):
        relativity_conf = relativity_options.conf_rel_any(
            missing_file_relativity)

        invalid_argument_syntax = ArgumentOfExistingPathAbsStx(
            relativity_conf.path_abs_stx_of_name('non-existing-file'))

        arguments_cases = [
            NameAndValue(
                '1st argument fails validation',
                [invalid_argument_syntax],
            ),
            NameAndValue(
                '2nd argument fails validation',
                [
                    ArgumentOfRichStringAbsStx.of_str('valid1'),
                    invalid_argument_syntax,
                    ArgumentOfRichStringAbsStx.of_str('valid2')
                ],
            ),
        ]

        for pgm_and_args_case in pgm_and_args_cases.cases__w_argument_list__excluding_program_reference(
        ):
            for arguments_case in arguments_cases:
                pgm_w_args = PgmAndArgsWArgumentsAbsStx(
                    pgm_and_args_case.pgm_and_args, arguments_case.value)
                with self.subTest(pgm_and_args=pgm_and_args_case.name,
                                  arguments=arguments_case.name):
                    # ACT & ASSERT #
                    CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                        self,
                        equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
                        pgm_w_args,
                        arrangement_w_tcds(
                            symbols=SymbolContext.symbol_table_of_contexts(
                                pgm_and_args_case.symbols),
                            tcds_contents=pgm_and_args_case.tcds,
                        ),
                        MultiSourceExpectation.of_const(
                            symbol_references=SymbolContext.
                            references_assertion_of_contexts(
                                pgm_and_args_case.symbols),
                            primitive=asrt.anything_goes(),
                            execution=ExecutionExpectation(
                                validation=
                                FAILING_VALIDATION_ASSERTION_FOR_PARTITION[
                                    relativity_conf.
                                    directory_structure_partition], )),
                    )
Exemple #23
0
 def runTest(self):
     # ARRANGE #
     rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_ACT)
     syntax = InstructionAbsStx(
         StringSourceOfFileAbsStx(
             rel_conf.path_abs_stx_of_name('non-existing-stdin-file.txt')))
     # ACT & ASSERT #
     CHECKER.check_multi_source__abs_stx(
         self, syntax,
         Arrangement(symbols=rel_conf.symbols.in_arrangement(), ),
         MultiSourceExpectation(
             symbols_after_parse=rel_conf.symbols.usages_expectation(),
             settings_builder=asrt_settings.stdin_is_present_but_invalid(),
         ))
Exemple #24
0
def configurations() -> Sequence[RelativityConfiguration]:
    all_except_rel_result = set(RelOptionType).difference(
        {RelOptionType.REL_RESULT})

    for_non_default = [
        RelativityConfiguration(
            relativity_options.conf_rel_any(rel_option_type))
        for rel_option_type in all_except_rel_result
    ]
    return for_non_default + [
        RelativityConfiguration(
            relativity_options.default_conf_rel_any(
                RelOptionType.REL_HDS_CASE)),
    ]
Exemple #25
0
class StdinCheckWithProgramWExitCode0ForSuccess:
    _SRC_FILE_REL_CONF = rel_opt_conf.conf_rel_any(RelOptionType.REL_HDS_CASE)
    _CHECKER_PROGRAM_FILE_NAME = 'read-and-check-stdin.py'

    _CHECKER_PROGRAM_PY_SRC = """\
import sys

expected = sys.argv[1]

actual = sys.stdin.read()

if expected == actual:
  sys.exit(0)
else:
  sys.stderr.write('\\n'.join([
      'Expected: ' + repr(expected),
      'Actual  : ' + repr(actual),
  ]))
  sys.stderr.write('\\n')
  sys.exit(1)
"""

    def program_that_checks_stdin__syntax(
        self,
        program_stdin: str,
        additional_expected_stdin: str = '',
    ) -> FullProgramAbsStx:
        expected_contents_arg_syntax = ArgumentOfRichStringAbsStx.of_str(
            program_stdin + additional_expected_stdin, QuoteType.HARD)
        checker_pgm_syntax = ProgramOfPythonInterpreterAbsStx.of_execute_python_src_file(
            self._SRC_FILE_REL_CONF.path_abs_stx_of_name(
                self._CHECKER_PROGRAM_FILE_NAME),
            [expected_contents_arg_syntax],
        )
        return FullProgramAbsStx(
            checker_pgm_syntax,
            stdin=StringSourceOfStringAbsStx.of_str_hard(program_stdin))

    @property
    def tcds_contents(self) -> TcdsPopulator:
        return self._SRC_FILE_REL_CONF.populator_for_relativity_option_root(
            DirContents([
                File(self._CHECKER_PROGRAM_FILE_NAME,
                     self._CHECKER_PROGRAM_PY_SRC)
            ]))

    @property
    def exit_code_of_successful_application(self) -> int:
        return 0
Exemple #26
0
    def test_referenced_file_is_a_directory__pre_sds(self):
        the_dir = Dir.empty('a-directory')
        rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_HDS_CASE)
        syntax = InstructionAbsStx(
            StringSourceOfFileAbsStx(
                rel_conf.path_abs_stx_of_name(the_dir.name)))

        CHECKER.check_multi_source__abs_stx(
            self,
            syntax,
            Arrangement(
                tcds_contents=rel_conf.populator_for_relativity_option_root(
                    DirContents([the_dir])), ),
            MultiSourceExpectation(
                validation=ValidationExpectationSvh.fails__pre_sds(), ),
        )
Exemple #27
0
    def runTest(self):
        # ARRANGE #
        checked_dir_rel_conf = relativity_options.conf_rel_any(RelOptionType.REL_ACT)
        checked_dir_populator = checked_dir_rel_conf.populator_for_relativity_option_root(
            DirContents([
                File.empty('a-file-so-that-checked-dir-is-not-empty')
            ]
            )
        )

        file_matcher = FileMatcherSymbolContextOfPrimitiveConstant(
            'MATCHER',
            True,
        )
        after_bin_op = 'after bin op'
        fm_argument = fm_args.conjunction([
            fm_args.SymbolReference(file_matcher.name),
            fm_args.Custom(after_bin_op),
        ])
        # ACT & ASSERT #
        for quantifier in Quantifier:
            arguments = args.Quantification(quantifier, fm_argument)
            with self.subTest(quantifier):
                # ACT & ASSERT #
                integration_check.CHECKER__PARSE_SIMPLE.check(
                    self,
                    source=arguments.as_remaining_source,
                    input_=model.model_constructor__non_recursive(
                        path_sdvs.of_rel_option(checked_dir_rel_conf.relativity)
                    ),
                    arrangement=arrangement_w_tcds(
                        symbols=file_matcher.symbol_table,
                        tcds_contents=checked_dir_populator
                    ),
                    expectation=Expectation(
                        ParseExpectation(
                            source=asrt_source.is_at_line(
                                current_line_number=1,
                                remaining_part_of_current_line=fm_argument.operator + ' ' + after_bin_op),
                            symbol_references=file_matcher.references_assertion
                        ),
                        ExecutionExpectation(
                            main_result=asrt_matching_result.matches_value(file_matcher.result_value)
                        )
                    ),
                )
Exemple #28
0
    def test_referenced_file_is_a_directory__post_sds(self):
        the_dir = Dir.empty('a-directory')
        rel_conf = rel_opt_conf.conf_rel_any(RelOptionType.REL_TMP)
        syntax = InstructionAbsStx(
            StringSourceOfFileAbsStx(
                rel_conf.path_abs_stx_of_name(the_dir.name)))

        CHECKER.check_multi_source__abs_stx(
            self,
            syntax,
            Arrangement(
                tcds_contents=rel_conf.populator_for_relativity_option_root(
                    DirContents([the_dir])), ),
            MultiSourceExpectation(
                settings_builder=asrt_settings.stdin_is_present_but_invalid(),
            ),
        )
    def _check_of_invalid_src_file(
            self,
            src_file_relativity: RelOptionType,
            validation: ValidationAssertions,
    ):
        # ARRANGE #
        checker = integration_check.checker(parse_check.rel_opts_conf_of_single(src_file_relativity))

        expectation_ = MultiSourceExpectation(
            symbol_references=asrt.anything_goes(),
            execution=ExecutionExpectation(
                validation=validation
            )
        )

        src_file_rel_conf = conf_rel_any(src_file_relativity)

        transformer = StringTransformerSymbolContext.of_primitive(
            'TRANSFORMER_SYMBOL',
            string_transformers.to_uppercase(),
        )
        symbols = transformer.symbol_table

        contents_builder = string_source_abs_stx.TransformableAbsStxBuilder(
            string_source_abs_stx.StringSourceOfFileAbsStx(
                src_file_rel_conf.path_abs_stx_of_name(self.src_file_name)
            )
        )
        for actual_src_file_variant in self.src_file_variants:
            for contents_arguments in contents_builder.with_and_without_transformer_cases(
                    transformer.abstract_syntax):
                with self.subTest(src_file_variant=actual_src_file_variant.name,
                                  contents=contents_arguments.name,
                                  relativity_of_src_path=src_file_rel_conf.option_argument):
                    # ACT & ASSERT #
                    checker.check__abs_stx__layouts__std_source_variants__wo_input(
                        self,
                        OptionallyOnNewLine(contents_arguments.value),
                        arrangement_w_tcds(
                            tcds_contents=src_file_rel_conf.populator_for_relativity_option_root(
                                actual_src_file_variant.value),
                            symbols=symbols,
                        ),
                        expectation_,
                    )
Exemple #30
0
def exit_code_exe_cases(
    program_symbol_name: str,
    exit_code_symbol_name: str,
) -> Sequence[NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult],
                     Arrangement]]:
    py_file = File(
        'exit-with-value-on-command-line.py',
        py_programs.py_pgm_that_exits_with_1st_value_on_command_line(''))

    py_file_rel_opt_conf = rel_opt.conf_rel_any(RelOptionType.REL_TMP)
    py_file_conf = py_file_rel_opt_conf.named_file_conf(py_file.name)

    program_symbol = ProgramSymbolContext.of_sdv(
        program_symbol_name,
        program_sdvs.interpret_py_source_file_that_must_exist(
            py_file_conf.path_sdv))

    def case(
        exit_code_from_program: int
    ) -> NExArr[PrimAndExeExpectation[MatcherWTrace, MatchingResult],
                Arrangement]:
        exit_code_symbol = StringIntConstantSymbolContext(
            exit_code_symbol_name, exit_code_from_program)

        return NExArr(
            'Exit code {}'.format(exit_code_from_program),
            PrimAndExeExpectation.of_exe(
                main_result=asrt_run.is_result_for_py_interpreter(
                    exit_code_from_program)),
            arrangement_w_tcds(
                tcds_contents=py_file_rel_opt_conf.
                populator_for_relativity_option_root(DirContents([py_file])),
                symbols=SymbolContext.symbol_table_of_contexts([
                    program_symbol,
                    exit_code_symbol,
                ]),
            ))

    exit_code_from_program_cases = [0, 1, 3, 69, 72]

    return [
        case(exit_code_from_program)
        for exit_code_from_program in exit_code_from_program_cases
    ]