Beispiel #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])),
        )
Beispiel #2
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
                ])))
Beispiel #3
0
    def test_check_non_zero_exit_code(self):
        self._check_single_line_arguments_with_source_variants(
            args.sequence([pgm_args.interpret_py_source_file('exit-with-value-on-command-line.py'),
                           2]).as_str,
            tcds_test.Arrangement(
                hds_contents_before=hds_case_dir_contents(DirContents([
                    File('exit-with-value-on-command-line.py',
                         py_pgm_that_exits_with_1st_value_on_command_line('on stderr'))]))),
            tcds_test.Expectation(
                expected_action_result=result_assertions.equals(2, 'on stderr'),

            )
        )
Beispiel #4
0
    def test_invalid_executable(self):
        argument = '/not/an/executable/program {} {} {}'.format(args.option(syntax_elements.EXISTING_FILE_OPTION_NAME),
                                                                'exit-with-value-on-command-line.py',
                                                                0)
        self._check_single_line_arguments_with_source_variants(
            argument,
            tcds_test.Arrangement(
                hds_contents_before=hds_case_dir_contents(DirContents([
                    File('exit-with-value-on-command-line.py',
                         py_pgm_that_exits_with_1st_value_on_command_line(''))]))),
            tcds_test.Expectation(
                acton_raises_hard_error=True,

            ))
Beispiel #5
0
 def test_check_zero_exit_code__rel_tmp(self):
     self._check_single_line_arguments_with_source_variants(
         args.sequence([
             pgm_args.interpret_py_source_file(
                 path_arguments.RelOptPathArgument('exit-with-value-on-command-line.py',
                                                   RelOptionType.REL_TMP)),
             0,
         ]).as_str,
         tcds_test.Arrangement(
             sds_contents_before=contents_in(RelSdsOptionType.REL_TMP,
                                             DirContents([
                                                 File('exit-with-value-on-command-line.py',
                                                      py_pgm_that_exits_with_1st_value_on_command_line(''))]))),
         tcds_test.Expectation(
             expected_action_result=result_assertions.equals(0, None)),
     )
Beispiel #6
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
    ]