Пример #1
0
 def runTest(self):
     # ARRANGE #
     stdin_from_act_exe_input = 'the stdin from the Act Execution Input (via [setup])'
     stdin_defined_by_the_program = 'the stdin defined by the program'
     test_setup = StdinCheckViaCopyToOutputFileTestSetup(
         ProcOutputFile.STDOUT,
         stdin_defined_for_program=[
             ss_sdvs.const_str(stdin_defined_by_the_program)
         ])
     full_stdin = stdin_defined_by_the_program + stdin_from_act_exe_input
     # ACT & ASSERT #
     CHECKER.check__abs_stx(
         self,
         test_setup.program_that_copies_stdin_syntax(),
         Arrangement(
             symbols=SymbolContext.symbol_table_of_contexts(
                 test_setup.symbols),
             atc_exe_input=AtcExeInputArr(
                 stdin_contents=stdin_from_act_exe_input, ),
             tcds=TcdsArrangementPreAct(),
         ),
         Expectation(
             symbol_usages=SymbolContext.usages_assertion_of_contexts(
                 test_setup.symbols),
             post_sds=PostSdsExpectation.constant(
                 sub_process_result_from_execute=asrt_proc_result.
                 matches_proc_result(exit_code=asrt.equals(0),
                                     stdout=asrt.equals(full_stdin))),
         ),
     )
Пример #2
0
    def runTest(self):
        # ARRANGE #
        string_72_plus = StringSymbolContext.of_constant(
            'SYMBOL_72_PLUS',
            '72+',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        string_5 = StringSymbolContext.of_constant(
            'SYMBOL_5',
            '5',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        expected = 72 + 5

        all_symbols = [string_72_plus, string_5]

        value_syntax = StringConcatAbsStx([
            string_72_plus.abstract_syntax,
            string_5.abstract_syntax,
        ])
        # ACT & ASSERT #
        self.conf.instruction_checker.check_parsing__abs_stx__const(
            self, self.conf.parser(),
            InstructionArgumentsAbsStx.of_int(value_syntax),
            self.conf.arrangement(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ),
            self.conf.expect_success(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                instruction_settings=asrt_is.matches(
                    timeout=asrt.equals(expected))))
Пример #3
0
def _check(put: unittest.TestCase,
           integer_matcher: IntegerMatcherAbsStx,
           integer_matcher_symbols: List[SymbolContext]):
    # ARRANGE #
    program_symbol = ProgramSymbolContext.of_arbitrary_value('PROGRAM_SYMBOL')
    all_symbols = [program_symbol] + integer_matcher_symbols

    command_execution_counter = recording.Counter(initial_value=0)
    # ACT & ASSERT #
    CHECKER.check__abs_stx(
        put,
        InstructionArguments(
            program_symbol.abstract_syntax,
            integer_matcher,
        ),
        ArrangementPostAct2(
            symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
            process_execution=ProcessExecutionArrangement(
                os_services=os_services_w_cmd_exe_counting__w_wrapped(
                    command_execution_counter,
                    CommandExecutorThatJustReturnsConstant(1)
                ),
            )
        ),
        Expectation2(
            ParseExpectation(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(all_symbols)
            )
        ),
    )
    put.assertEqual(1,
                    command_execution_counter.value,
                    'number of times the program has been executed')
Пример #4
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), ),
            ))
 def runTest(self):
     # ARRANGE #
     sm_1 = StringMatcherSymbolContextOfPrimitiveConstant('sm_1', True)
     sm_2 = StringMatcherSymbolContextOfPrimitiveConstant('sm_2', False)
     symbols = [sm_1, sm_2]
     matcher_syntax = StringMatcherInfixOpAbsStx.disjunction([
         sm_1.abstract_syntax,
         sm_2.abstract_syntax,
     ])
     is_pass = sm_1.result_value or sm_2.result_value
     # ACT & ASSERT #
     self.configuration.checker.check__abs_stx__source_variants(
         self, self.configuration.syntax_for_matcher(matcher_syntax),
         self.configuration.arrangement_for_contents(
             actual_contents='',
             symbols=SymbolContext.symbol_table_of_contexts(symbols),
             post_sds_population_action=
             MK_SUB_DIR_OF_ACT_AND_MAKE_IT_CURRENT_DIRECTORY,
         ).as_arrangement_2(),
         MultiSourceExpectation(
             symbol_usages=SymbolContext.usages_assertion_of_contexts(
                 symbols),
             execution=ExecutionExpectation(
                 main_result=asrt_pfh.is_non_hard_error(is_pass), ),
         ))
Пример #6
0
    def runTest(self):
        string_72_plus = StringSymbolContext.of_constant(
            'SYMBOL_72_PLUS',
            '72+',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        string_5 = StringSymbolContext.of_constant(
            'SYMBOL_5',
            '5',
            default_restrictions=asrt_data_rest.
            is__string__w_all_indirect_refs_are_strings(),
        )
        expected = 72 + 5

        all_symbols = [string_72_plus, string_5]

        value_syntax = StringConcatAbsStx([
            string_72_plus.abstract_syntax,
            string_5.abstract_syntax,
        ])
        CHECKER.check__abs_stx__layout_and_source_variants(
            self,
            InstructionArgumentsAbsStx.of_int(value_syntax),
            Arrangement.phase_agnostic(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols), ),
            MultiSourceExpectation.phase_agnostic(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                instruction_settings=asrt_instr_settings.matches(
                    timeout=asrt.equals(expected))),
        )
Пример #7
0
    def test_stdin_is_concatenation_of_string_sources_WHEN_program_defines_multiple_stdin(
            self):
        # ARRANGE #
        test_setup = MultipleStdinOfProgramTestSetup(self, exit_code=0)
        all_symbols = [
            test_setup.program_symbol, CONST_TRUE_INT_MATCHER_SYMBOL
        ]

        # ACT & ASSERT #
        CHECKER.check__abs_stx__source_variants(
            self,
            InstructionArguments(
                test_setup.program_w_stdin_syntax,
                CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax,
            ),
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
                process_execution=test_setup.proc_exe_env__w_stdin_check,
            ),
            MultiSourceExpectation(
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                execution=ExecutionExpectation(main_result=asrt_pfh.is_pass()),
            ),
        )
Пример #8
0
    def runTest(self):
        vars_before = [
            ValueWSymRefsAndVarRefs.REFERENCED_VAR_1,
            ValueWSymRefsAndVarRefs.REFERENCED_VAR_2
        ]
        setup_before = EnvironsSetup(vars_before, vars_before)

        var_to_set__resolved = NameAndValue(
            NameWSymRefs.RESOLVED_STR,
            ValueWSymRefsAndVarRefs.VALUE_WO_VAR_REFS)

        all_symbols = NameWSymRefs.SYMBOL_CONTEXTS + ValueWSymRefsAndVarRefs.SYMBOL_CONTEXTS

        execution_cases = _exe_cases_of_modification(
            before_modification=setup_before,
            after_modification=setup_before.new_with_added(
                var_to_set__resolved, var_to_set__resolved),
            symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
        )
        # ACT & ASSERT #
        CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx(
                NameWSymRefs.STRING_ABS_STX,
                StringSourceOfStringAbsStx(
                    ValueWSymRefsAndVarRefs.STRING_ABS_STX),
                phase_spec=None,
            ),
            symbol_usages=SymbolContext.usages_assertion_of_contexts(
                all_symbols),
            execution_cases=execution_cases,
        )
Пример #9
0
    def runTest(self):
        # ARRANGE #
        program_symbol = StringConstantSymbolContext(
            'program_name_symbol',
            'the-program',
            default_restrictions=asrt_rest.is__string__w_all_indirect_refs_are_strings(),
        )
        argument_list_symbol = ListConstantSymbolContext(
            'arguments_symbol',
            ['1st', '2nd'],
        )
        symbols = [program_symbol, argument_list_symbol]

        expected_command = asrt_command.matches_command(
            driver=asrt_command.matches_system_program_command_driver(
                asrt.equals(program_symbol.str_value)
            ),
            arguments=asrt.equals(argument_list_symbol.constant),
        )

        # ACT & ASSERT #
        check_successful_execution(
            self,
            arguments=command_line(
                program_symbol.name__sym_ref_syntax,
                program_arguments.simple(argument_list_symbol.name__sym_ref_syntax),
            ),
            expected_command=expected_command,
            symbols=SymbolContext.symbol_table_of_contexts(symbols),
            symbol_usages=SymbolContext.usages_assertion_of_contexts(symbols)
        )
Пример #10
0
    def _test_symbol_reference_in_contents(
            self, symbol_ref_syntax_2_contents_arguments: Callable[
                [str], StringSourceAbsStx],
            symbol_value_2_expected_contents: Callable[[str], str]):
        contents_symbol = StringConstantSymbolContext(
            'contents_symbol_name',
            'contents symbol value',
            default_restrictions=asrt_rest.is__w_str_rendering(),
        )

        expected_contents = symbol_value_2_expected_contents(
            contents_symbol.str_value)

        symbols = [contents_symbol]
        expected_symbol_references = SymbolContext.references_assertion_of_contexts(
            symbols)
        symbol_table = SymbolContext.symbol_table_of_contexts(symbols)

        string_source_syntax = symbol_ref_syntax_2_contents_arguments(
            symbol_reference_syntax_for_name(contents_symbol.name))

        CHECKER.check__abs_stx(
            self, string_source_syntax, None,
            arrangement_w_tcds(symbols=symbol_table, ),
            Expectation.of_prim__const(
                primitive=asrt_string_source.
                pre_post_freeze__matches_str__const(
                    expected_contents, may_depend_on_external_resources=False),
                parse=ParseExpectation(
                    symbol_references=expected_symbol_references, ),
            ))
Пример #11
0
    def runTest(self):
        vars_before = [
            ValueWSymRefsAndVarRefs.REFERENCED_VAR_1,
            ValueWSymRefsAndVarRefs.REFERENCED_VAR_2
        ]
        var_to_set__resolved = NameAndValue(
            NameWSymRefs.RESOLVED_STR,
            ValueWSymRefsAndVarRefs.VALUE_WO_VAR_REFS)

        all_symbols = NameWSymRefs.SYMBOL_CONTEXTS + ValueWSymRefsAndVarRefs.SYMBOL_CONTEXTS

        execution_cases = _exe_cases_of_modification(
            before_modification=vars_before,
            after_modification=vars_before + [var_to_set__resolved],
            symbols=SymbolContext.symbol_table_of_contexts(all_symbols),
        )
        # ACT & ASSERT #
        for phase_spec__source in [None, Phase.NON_ACT]:
            CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
                self,
                SetVariableArgumentsAbsStx(
                    NameWSymRefs.STRING_ABS_STX,
                    StringSourceOfStringAbsStx(
                        ValueWSymRefsAndVarRefs.STRING_ABS_STX),
                    phase_spec=phase_spec__source,
                ),
                symbol_usages=SymbolContext.usages_assertion_of_contexts(
                    all_symbols),
                execution_cases=execution_cases,
                sub_test_identifiers={
                    'phase_spec__source': phase_spec__source,
                },
            )
Пример #12
0
    def runTest(self):
        # ARRANGE #
        program_ref_case = pgm_and_args_cases.program_reference__w_argument_list()

        def expected_program(env: AssertionResolvingEnvironment) -> Assertion[Program]:
            return asrt_pgm_val.matches_program(
                asrt_command.matches_command(
                    driver=program_ref_case.expected_command_driver(env),
                    arguments=asrt.is_empty_sequence,
                ),
                stdin=asrt_pgm_val.is_no_stdin(),
                transformer=asrt_pgm_val.is_no_transformation(),
            )

        # ACT & ASSERT #
        CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
            self,
            equivalent_source_variants__for_expr_parse__s__nsc,
            OptionallyOnNewLine(WithinParensAbsStx(program_ref_case.pgm_and_args,
                                                   end_paren_on_separate_line=False)),
            arrangement_wo_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(program_ref_case.symbols),
            ),
            MultiSourceExpectation(
                symbol_references=SymbolContext.references_assertion_of_contexts(program_ref_case.symbols),
                primitive=expected_program,
            )
        )
Пример #13
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
                                    )
                                )
                            )
                        )
Пример #14
0
    def _check_with_exit_code(self, exit_code: int):
        # ARRANGE #
        result = SubProcessResult(
            exitcode=exit_code,
            stdout='output on stdout',
            stderr='output on stderr',
        )

        command_py_program = py_program.program_that_prints_and_exits_with_exit_code(result)

        py_file = fs.File(
            'the-program.py',
            command_py_program,
        )
        program_wo_transformation = ProgramSymbolContext.of_sdv(
            'PROGRAM_SYMBOL',
            program_sdvs.interpret_py_source_file_that_must_exist(
                path_sdvs.of_rel_option_with_const_file_name(
                    RelOptionType.REL_HDS_CASE,
                    py_file.name,
                )
            )
        )

        source = args.program(
            args.symbol_ref_command_line(program_wo_transformation.name),
            transformation=TO_UPPER_CASE_TRANSFORMER.name__sym_ref_syntax)

        symbols = [
            program_wo_transformation,
            TO_UPPER_CASE_TRANSFORMER,
        ]
        # ACT & ASSERT #

        integration_check.check_execution(
            self,
            sut.actor(),
            [instr(source.as_arguments.lines)],
            arrangement_w_tcds(
                symbol_table=SymbolContext.symbol_table_of_contexts(symbols),
                hds_contents=hds_populators.contents_in(
                    RelHdsOptionType.REL_HDS_CASE,
                    DirContents([py_file]),
                )
            ),
            Expectation(
                symbol_usages=SymbolContext.references_assertion_of_contexts(symbols),
                execute=asrt_eh.is_exit_code(result.exitcode),
                post_sds=PostSdsExpectation.constant(
                    sub_process_result_from_execute=asrt_proc_result.matches_proc_result(
                        exit_code=asrt.equals(result.exitcode),
                        stdout=asrt.equals(result.stdout.upper()),
                        stderr=asrt.equals(result.stderr),
                    )
                )
            ),
        )
Пример #15
0
    def runTest(self):
        # ARRANGE #

        command_py_program = py_program.exit_with_code(0)

        py_file = fs.File(
            'the-program.py',
            lines_content(command_py_program),
        )
        program_wo_transformation = ProgramSymbolContext.of_sdv(
            'PROGRAM_SYMBOL',
            program_sdvs.interpret_py_source_file_that_must_exist(
                path_sdvs.of_rel_option_with_const_file_name(
                    RelOptionType.REL_HDS_CASE,
                    py_file.name,
                )
            )
        )

        error_message = 'error message from transformer'
        transformer = StringTransformerPrimitiveSymbolContext(
            'HARD_ERROR_TRANSFORMER',
            string_transformers.model_access_raises_hard_error(error_message),
        )

        source = args.program(
            args.symbol_ref_command_line(program_wo_transformation.name),
            transformation=transformer.name__sym_ref_syntax)

        symbols = [
            program_wo_transformation,
            transformer,
        ]

        # ACT & ASSERT #

        integration_check.check_execution(
            self,
            sut.actor(),
            [instr(source.as_arguments.lines)],
            arrangement_w_tcds(
                symbol_table=SymbolContext.symbol_table_of_contexts(symbols),
                hds_contents=hds_populators.contents_in(
                    RelHdsOptionType.REL_HDS_CASE,
                    DirContents([py_file]),
                )
            ),
            Expectation(
                symbol_usages=SymbolContext.references_assertion_of_contexts(symbols),
                execute=asrt_eh.matches_hard_error(
                    asrt_failure_details.is_failure_message_matching__td(
                        asrt_text_doc.is_string_for_test_that_equals(error_message)
                    )
                ),
            ),
        )
Пример #16
0
    def _test_symbol_reference_in_dst_file_and_contents(
            self, symbol_ref_syntax_2_contents_arguments: Callable[
                [str], StringSourceAbsStx],
            symbol_value_2_expected_contents: Callable[[str], str]):
        sub_dir_symbol = ConstantSuffixPathDdvSymbolContext(
            'sub_dir_symbol',
            RelOptionType.REL_ACT,
            'sub-dir',
            ACCEPTED_DST_RELATIVITY_VARIANTS,
        )
        contents_symbol = StringConstantSymbolContext(
            'contents_symbol_name',
            'contents symbol value',
            default_restrictions=asrt_rest.is__w_str_rendering(),
        )

        expected_file_contents = symbol_value_2_expected_contents(
            contents_symbol.str_value)

        expected_file = fs.File('a-file-name.txt', expected_file_contents)

        symbols = [sub_dir_symbol, contents_symbol]
        expected_symbol_references = SymbolContext.references_assertion_of_contexts(
            symbols)
        symbol_table = SymbolContext.symbol_table_of_contexts(symbols)

        contents_arguments = symbol_ref_syntax_2_contents_arguments(
            symbol_reference_syntax_for_name(contents_symbol.name))

        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            path_abs_stx.PathStringAbsStx.of_plain_components(
                [sub_dir_symbol.name__sym_ref_syntax, expected_file.name]),
            contents_arguments,
        )

        integration_check.CHECKER__AFTER_ACT.check__abs_stx(
            self, instruction_syntax,
            Arrangement.phase_agnostic(
                tcds=TcdsArrangement(
                    pre_population_action=
                    SETUP_CWD_INSIDE_SDS_BUT_NOT_A_SDS_DIR__PLAIN, ),
                symbols=symbol_table,
            ),
            Expectation.phase_agnostic(
                main_result=IS_SUCCESS,
                symbol_usages=expected_symbol_references,
                main_side_effects_on_sds=dir_contains_exactly(
                    sub_dir_symbol.rel_option_type,
                    fs.DirContents(
                        [fs.Dir(sub_dir_symbol.path_suffix,
                                [expected_file])])),
            ))
Пример #17
0
    def test_stdin_only_as_source_argument(self):
        # ARRANGE #
        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            for validation_case in validation_cases.failing_validation_cases():
                program_w_stdin = FullProgramAbsStx(
                    pgm_and_args_case.pgm_and_args,
                    stdin=validation_case.value.syntax,
                )

                symbols = list(pgm_and_args_case.symbols) + [
                    validation_case.value.symbol_context
                ]

                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self,
                    equivalent_source_variants__for_expr_parse__s__nsc,
                    program_w_stdin,
                    pgm_and_args_case.mk_arrangement(
                        SymbolContext.symbol_table_of_contexts(symbols)),
                    MultiSourceExpectation.of_const(
                        symbol_references=SymbolContext.
                        references_assertion_of_contexts(symbols),
                        execution=ExecutionExpectation(
                            validation=validation_case.value.assertion, ),
                        primitive=asrt.anything_goes(),
                    ),
                    sub_test_identifiers={
                        'command': pgm_and_args_case.name,
                        'validation': validation_case.name
                    },
                )
Пример #18
0
    def test_file_matcher_SHOULD_be_parsed_as_full_expression(self):
        # ARRANGE #
        file_name = 'file-name'
        fm_1 = FileMatcherSymbolContextOfPrimitiveConstant(
            'file_matcher_1', False)
        fm_2 = FileMatcherSymbolContextOfPrimitiveConstant(
            'file_matcher_2', True)
        symbols = [fm_1, fm_2]

        arguments = args.FilesCondition([
            args.FileCondition(
                file_name, fm_args.disjunction([fm_1.argument, fm_2.argument]))
        ])
        expected_result = fm_1.result_value or fm_2.result_value
        # ACT & ASSERT #
        CHECKER.check__w_source_variants(
            self,
            arguments=arguments.as_arguments,
            input_=None,
            arrangement=arrangement_wo_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(symbols)),
            expectation=Expectation(
                ParseExpectation(symbol_references=SymbolContext.
                                 references_assertion_of_contexts(symbols)),
                primitive=prim_asrt__constant(
                    asrt_primitive.files_matches({
                        PurePosixPath(file_name):
                        asrt_primitive.is_matcher_that_gives(expected_result)
                    }))))
Пример #19
0
    def _check(
        self,
        arguments: ArgumentElements,
        expected_result: bool,
        all_symbols: Sequence[NameAndValue[MatcherWTrace[MODEL]]],
        expected_trace: tree.Node[bool],
    ):
        conf = self.configuration
        helper = self._asrt_helper

        conf.checker_for_parser_of_full_expr().check__w_source_variants(
            self,
            arguments.as_arguments,
            conf.arbitrary_model,
            Arrangement(symbols=SymbolContext.symbol_table_of_contexts([
                conf.mk_logic_type_context_of_primitive(sym.name, sym.value)
                for sym in all_symbols
            ]), ),
            Expectation(
                ParseExpectation(symbol_references=helper.is_sym_refs_to(
                    [sym.name for sym in all_symbols]), ),
                ExecutionExpectation(main_result=asrt_matching_result.matches(
                    value=asrt.equals(expected_result),
                    trace=trace_equals(expected_trace)))),
        )
Пример #20
0
    def runTest(self):
        # ARRANGE #
        valid_program_symbol = ProgramSymbolContext.of_arbitrary_value(
            'VALID_PROGRAM')

        for invalid_matcher_case in im_validation_case.failing_validation_cases(
        ):
            invalid_matcher_symbol = invalid_matcher_case.value.symbol_context
            all_symbols = [valid_program_symbol, invalid_matcher_symbol]
            with self.subTest(invalid_matcher_case.name):
                # ACT & ASSERT #
                invalid_matcher_symbol = invalid_matcher_case.value.symbol_context
                CHECKER.check__abs_stx(
                    self,
                    InstructionArguments(
                        valid_program_symbol.abstract_syntax,
                        invalid_matcher_symbol.abstract_syntax,
                    ),
                    ArrangementPostAct2(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            all_symbols), ),
                    Expectation2(
                        ParseExpectation(
                            symbol_usages=SymbolContext.
                            usages_assertion_of_contexts(all_symbols)),
                        ExecutionExpectation.
                        validation_corresponding_to__post_sds_as_hard_error(
                            invalid_matcher_case.value.actual, ),
                    ))
Пример #21
0
    def runTest(self):
        # ARRANGE #
        valid_int_matcher_symbol = IntegerMatcherSymbolContext.of_arbitrary_value(
            'VALID_INT_MATCHER')

        for invalid_program_case in pgm_validation_cases.failing_validation_cases(
        ):
            all_symbols = list(invalid_program_case.value.symbol_contexts) + [
                valid_int_matcher_symbol
            ]
            directly_referenced_symbols = [
                invalid_program_case.value.program_symbol_context,
                valid_int_matcher_symbol
            ]
            with self.subTest(invalid_program_case.name):
                # ACT & ASSERT #
                CHECKER.check__abs_stx(
                    self,
                    InstructionArguments(
                        invalid_program_case.value.abstract_syntax,
                        valid_int_matcher_symbol.abstract_syntax,
                    ),
                    ArrangementPostAct2(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            all_symbols), ),
                    Expectation2(
                        ParseExpectation(symbol_usages=SymbolContext.
                                         usages_assertion_of_contexts(
                                             directly_referenced_symbols), ),
                        ExecutionExpectation.
                        validation_corresponding_to__post_sds_as_hard_error(
                            invalid_program_case.value.actual, ),
                    ))
Пример #22
0
    def test_transformation_only_as_source_argument(self):
        # ARRANGE #
        transformer = StringTransformerPrimitiveSymbolContext(
            'STRING_TRANSFORMER', string_transformers.to_uppercase())

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            program_w_transformer = FullProgramAbsStx(
                pgm_and_args_case.pgm_and_args,
                transformation=transformer.abstract_syntax)

            symbols = list(pgm_and_args_case.symbols) + [transformer]

            with self.subTest(command=pgm_and_args_case.name):
                # ACT & ASSERT #
                CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
                    self, equivalent_source_variants__for_expr_parse__s__nsc,
                    program_w_transformer,
                    pgm_and_args_case.mk_arrangement(
                        SymbolContext.symbol_table_of_contexts(symbols)),
                    MultiSourceExpectation(
                        symbol_references=SymbolContext.
                        references_assertion_of_contexts(symbols),
                        primitive=lambda env: (asrt_pgm_val.matches_program(
                            asrt_command.
                            matches_command(driver=pgm_and_args_case.
                                            expected_command_driver(env),
                                            arguments=asrt.is_empty_sequence),
                            stdin=asrt_pgm_val.is_no_stdin(),
                            transformer=asrt.matches_singleton_sequence(
                                asrt.is_(transformer.primitive)),
                        ))))
Пример #23
0
 def runTest(self):
     for line_filter_case in LINE_FILTER_CASES:
         for preserve_new_lines in [False, True]:
             for regex_case in failing_regex_validation_cases():
                 all_symbols = line_filter_case.value.symbols + regex_case.symbols
                 source = ReplaceRegexAbsStx.of_str(
                     regex_case.regex_string,
                     'arbitrary_replacement',
                     preserve_new_lines=preserve_new_lines,
                     lines_filter=line_filter_case.value.syntax,
                 )
                 # ACT & ASSERT #
                 integration_check.CHECKER__PARSE_FULL.check__abs_stx__layout__std_source_variants(
                     self,
                     source,
                     model_constructor.arbitrary(self),
                     arrangement_w_tcds(
                         symbols=SymbolContext.symbol_table_of_contexts(
                             all_symbols)),
                     MultiSourceExpectation(
                         symbol_references=line_filter_case.value.
                         references_assertion__followed_by(
                             regex_case.reference_assertions),
                         execution=ExecutionExpectation(
                             validation=regex_case.expectation),
                         primitive=prim_asrt__constant(
                             is_identity_transformer(False)),
                     ),
                     sub_test_identifiers={
                         'regex_case': regex_case.case_name,
                         'preserve_new_lines': preserve_new_lines,
                         'lines_filtering': line_filter_case.name,
                     })
Пример #24
0
 def _test_relativity(
     self,
     rel_opt_conf: RelativityOptionConfigurationForRelNonHds,
 ):
     # ARRANGE #
     dst_path = rel_opt_conf.path_abs_stx_of_name('non-existing-file')
     for modification in fs_abs_stx.ModificationType:
         for validation_case in validation_cases.failing_validation_cases():
             instruction_syntax = NewDirArguments(
                 dst_path,
                 fs_abs_stx.DirContentsExplicitAbsStx(
                     modification, validation_case.value.syntax),
             )
             all_symbols = rel_opt_conf.symbols.contexts_for_arrangement(
             ) + [validation_case.value.symbol_context]
             # ACT & ASSERT
             self.conf.instruction_checker.check_parsing__abs_stx__const(
                 self, self.conf.parser(), instruction_syntax,
                 self.conf.arrangement(
                     symbols=SymbolContext.symbol_table_of_contexts(
                         all_symbols), ),
                 self.conf.expect_failing_validation(
                     validation_case.value.actual,
                     symbol_usages=SymbolContext.
                     usages_assertion_of_contexts(all_symbols),
                 ))
Пример #25
0
    def _do_check(
        self,
        program: ProgramAbsStx,
        process_execution_w_stdin_check: ProcessExecutionArrangement,
        program_symbols: Sequence[SymbolContext],
        tcds_contents: tcds_populators.TcdsPopulator = tcds_populators.empty(),
    ):
        # ARRANGE #
        string_matcher_const_true = StringMatcherSymbolContext.of_primitive(
            'CONSTANT_TRUE',
            ConstantMatcherWithCustomName('const true', True),
        )
        symbols = list(program_symbols) + [string_matcher_const_true]
        copy_stdin_and_check_via_matcher = StdoutErrFromProgramAbsStx(
            program,
            string_matcher_const_true.abstract_syntax,
        )

        checker = instruction_check.Checker(self.configuration.parser())
        # ACT & ASSERT #
        checker.check__abs_stx__source_variants(
            self,
            copy_stdin_and_check_via_matcher,
            ArrangementPostAct2(
                symbols=SymbolContext.symbol_table_of_contexts(symbols),
                tcds=TcdsArrangementPostAct(tcds_contents=tcds_contents),
                process_execution=process_execution_w_stdin_check,
            ),
            MultiSourceExpectation(symbol_usages=SymbolContext.
                                   usages_assertion_of_contexts(symbols)),
        )
Пример #26
0
 def test_validation_should_fail_pre_sds_when_regex_is_invalid(self):
     for regex_case in failing_regex_validation_cases():
         arguments = self.conf.arguments(NameRegexVariant.of(regex_case.regex_string))
         for expectation_type in ExpectationType:
             with self.subTest(expectation_type=expectation_type,
                               validation_case=regex_case.case_name):
                 integration_check.CHECKER__PARSE_SIMPLE.check__w_source_variants(
                     self,
                     arguments=
                     arguments.as_arguments,
                     input_=
                     ARBITRARY_MODEL,
                     arrangement=
                     arrangement_w_tcds(
                         symbols=SymbolContext.symbol_table_of_contexts(regex_case.symbols)
                     ),
                     expectation=
                     Expectation(
                         ParseExpectation(
                             symbol_references=asrt.matches_sequence(regex_case.reference_assertions),
                         ),
                         ExecutionExpectation(
                             validation=regex_case.expectation
                         ),
                     )
                 )
Пример #27
0
 def runTest(self):
     # ARRANGE #
     model_contents = 'the contents of stdin of program'
     stdin_string_source_syntax = string_source_abs_stx.StringSourceOfStringAbsStx.of_str_hard(
         model_contents, )
     for output_file in ProcOutputFile:
         for ignore_exit_code in [False, True]:
             with self.subTest(output_file=output_file,
                               ignore_exit_code=ignore_exit_code):
                 test_setup = StdinCheckViaCopyToOutputFileTestSetup(
                     output_file)
                 # ACT & ASSERT #
                 CHECKER.check__abs_stx__wo_input(
                     self,
                     StringSourceOfProgramAbsStx(
                         output_file,
                         FullProgramAbsStx(
                             test_setup.program_that_copies_stdin_syntax(),
                             stdin=stdin_string_source_syntax),
                         ignore_exit_code,
                     ),
                     arrangement_w_tcds(
                         symbols=SymbolContext.symbol_table_of_contexts(
                             test_setup.symbols), ),
                     Expectation.of_prim__const(
                         parse=ParseExpectation(
                             symbol_references=SymbolContext.
                             references_assertion_of_contexts(
                                 test_setup.symbols)),
                         primitive=asrt_string_source.
                         pre_post_freeze__identical(
                             asrt_contents.matches__str(
                                 asrt.equals(model_contents))),
                     ),
                 )
Пример #28
0
 def test_here_document_with_symbol_references(self):
     symbol1 = StringConstantSymbolContext('symbol_1_name',
                                           'symbol 1 value')
     symbol2 = StringConstantSymbolContext('symbol_2_name',
                                           'symbol 2 value')
     symbol3 = StringConstantSymbolContext('symbol_3_name',
                                           'symbol 3 value')
     line_with_sym_ref_template = 'before symbol {symbol} after symbol'
     line_with_two_sym_refs_template = '{first_symbol} between symbols {second_symbol}'
     cases = [
         SuccessfulCase(
             source_lines=[
                 '<<eof',
                 line_with_sym_ref_template.format(
                     symbol=symbol1.name__sym_ref_syntax),
                 'eof',
                 'following line',
             ],
             expected_document_contents=hd.matches_resolved_value(
                 [
                     line_with_sym_ref_template.format(
                         symbol=symbol1.str_value),
                 ],
                 symbol_references=[
                     symbol1.reference__w_str_rendering,
                 ],
                 symbols=symbol1.symbol_table),
             source_after_parse=asrt_source.is_at_end_of_line(3),
         ),
         SuccessfulCase(
             source_lines=[
                 '<<eof',
                 line_with_sym_ref_template.format(
                     symbol=symbol1.name__sym_ref_syntax),
                 line_with_two_sym_refs_template.format(
                     first_symbol=symbol2.name__sym_ref_syntax,
                     second_symbol=symbol3.name__sym_ref_syntax),
                 'eof',
                 'following line',
             ],
             expected_document_contents=hd.matches_resolved_value(
                 [
                     line_with_sym_ref_template.format(
                         symbol=symbol1.str_value),
                     line_with_two_sym_refs_template.format(
                         first_symbol=symbol2.str_value,
                         second_symbol=symbol3.str_value),
                 ],
                 symbol_references=[
                     symbol1.reference__w_str_rendering,
                     symbol2.reference__w_str_rendering,
                     symbol3.reference__w_str_rendering,
                 ],
                 symbols=SymbolContext.symbol_table_of_contexts(
                     [symbol1, symbol2, symbol3], )),
             source_after_parse=asrt_source.is_at_end_of_line(4),
         ),
     ]
     for case in cases:
         self._check_case(case)
Пример #29
0
    def test_stdin_is_contents_of_string_source_WHEN_program_defines_single_stdin(
            self):
        # ARRANGE #
        test_setup = SingleStdinOfProgramTestSetup(self, exit_code=0)

        for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference(
        ):
            all_symbols = list(
                pgm_and_args_case.symbols) + [CONST_TRUE_INT_MATCHER_SYMBOL]
            with self.subTest(pgm_and_args_case.name):
                # ACT & ASSERT #
                CHECKER.check__abs_stx__source_variants(
                    self,
                    InstructionArguments(
                        test_setup.program_w_stdin_syntax(
                            pgm_and_args_case.pgm_and_args),
                        CONST_TRUE_INT_MATCHER_SYMBOL.abstract_syntax,
                    ),
                    ArrangementPostAct2(
                        symbols=SymbolContext.symbol_table_of_contexts(
                            all_symbols),
                        process_execution=test_setup.
                        proc_exe_env__w_stdin_check,
                        tcds=TcdsArrangementPostAct(
                            tcds_contents=pgm_and_args_case.tcds, ),
                    ),
                    MultiSourceExpectation(
                        symbol_usages=SymbolContext.
                        usages_assertion_of_contexts(all_symbols),
                        execution=ExecutionExpectation(
                            main_result=asrt_pfh.is_pass()),
                    ),
                )
Пример #30
0
class TestErrorMessage(unittest.TestCase):
    string_sym_def_1 = StringConstantSymbolContext('symbol1')
    string_sym_def_2 = StringConstantSymbolContext('symbol2')

    symbol_table = SymbolContext.symbol_table_of_contexts(
        [string_sym_def_1, string_sym_def_2])

    def test_invalid_type(self):
        # ACT #
        actual = sut.ErrorMessage(self.string_sym_def_1.name,
                                  self.symbol_table,
                                  InvalidValueTypeFailure([ValueType.PATH]))
        # ASSERT #
        asrt_text_doc.assert_is_valid_text_renderer(self, actual)

    def test_direct_reference(self):
        # ACT #
        actual = sut.ErrorMessage(
            self.string_sym_def_1.name, self.symbol_table,
            FailureOfDirectReference(_new_em('the message', 'the how to fix')))
        # ASSERT #
        asrt_text_doc.assert_is_valid_text_renderer(self, actual)

    def test_indirect_reference(self):
        # ACT #
        actual = sut.ErrorMessage(
            self.string_sym_def_1.name, self.symbol_table,
            FailureOfIndirectReference(
                self.string_sym_def_1.name, [self.string_sym_def_2.name],
                _new_em('the message', 'the how to fix')))
        # ASSERT #
        asrt_text_doc.assert_is_valid_text_renderer(self, actual)