예제 #1
0
    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])),
        )
예제 #2
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),
                    )
                )
            ),
        )
예제 #3
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)
                    )
                ),
            ),
        )
예제 #4
0
    def runTest(self):
        # ARRANGE #
        valid_program_line = args.symbol_ref_command_line(
            'PROGRAM_SYMBOL').as_str
        # ACT & ASSERT #
        for case in invalid_source_variants(valid_program_line):
            with self.subTest(case.name):
                with self.assertRaises(ParseException) as ctx:
                    sut.actor().parse(case.value)

                asrt_text_doc.is_any_text().apply_with_message(
                    self, ctx.exception.cause, 'error info')
예제 #5
0
 def _instructions_for_executing_py_source(
         self, py_src: List[str]) -> ContextManager[TestCaseSourceSetup]:
     py_file = fs.File('the-program.py', lines_content(py_src))
     symbol = 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_ACT,
                 py_file.name,
             )))
     program_line = args.symbol_ref_command_line(symbol.name).as_str
     yield TestCaseSourceSetup(
         act_phase_instructions=[instr([program_line])],
         home_act_dir_contents=DirContents([py_file]),
         symbols=symbol.symbol_table,
         symbol_usages=symbol.usages_assertion)
예제 #6
0
 def runTest(self):
     # ARRANGE #
     symbol = ProgramSymbolContext.of_sdv(
         'PROGRAM_SYMBOL',
         program_sdvs.system_program(
             string_sdvs.str_constant('non-existing-system-program')))
     program_line = args.symbol_ref_command_line(symbol.name).as_str
     # ACT & ASSERT #
     integration_check.check_execution(
         self,
         sut.actor(),
         [instr([program_line])],
         arrangement_w_tcds(symbol_table=symbol.symbol_table),
         Expectation.hard_error_from_execute(
             symbol_usages=symbol.usages_assertion),
     )
예제 #7
0
 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
             ])))
예제 #8
0
 def runTest(self):
     for case in VALIDATION_CASES:
         with self.subTest(case.name):
             program_sdv = program_sdvs.ref_to_exe_file(
                 path_sdvs.of_rel_option_with_const_file_name(
                     case.path_relativity, 'non-existing'))
             program_symbol = ProgramSymbolContext.of_sdv(
                 'PROGRAM_SYMBOL', program_sdv)
             integration_check.check_execution(
                 self,
                 sut.actor(),
                 [
                     instr([
                         args.symbol_ref_command_line(
                             program_symbol.name).as_str
                     ])
                 ],
                 arrangement_w_tcds(
                     symbol_table=program_symbol.symbol_table, ),
                 Expectation(symbol_usages=program_symbol.usages_assertion,
                             validation=case.expectation),
             )
예제 #9
0
    def runTest(self):
        # ARRANGE #
        exit_code_from_program = 0
        py_file = fs.File(
            'the-program',
            lines_content(py_program.exit_with_code(exit_code_from_program)),
        )
        program_symbol = 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,
                )))
        program_line = args.symbol_ref_command_line(program_symbol.name).as_str

        with tmp_dir_in_path_with_files(DirContents([py_file])) as environ:
            for source_case in valid_source_variants(program_line):
                with self.subTest(source_case.name):
                    # ACT & ASSERT #
                    integration_check.check_execution(
                        self,
                        sut.actor(),
                        [instr([program_line])],
                        arrangement_w_tcds(
                            symbol_table=program_symbol.symbol_table,
                            act_exe_input=AtcExeInputArr(environ=environ),
                            hds_contents=hds_populators.contents_in(
                                RelHdsOptionType.REL_HDS_CASE,
                                DirContents([py_file])),
                        ),
                        Expectation(
                            symbol_usages=program_symbol.usages_assertion,
                            execute=asrt_eh.is_exit_code(
                                exit_code_from_program)),
                    )