def get(self) -> ExitCodeAndStderrFile:
     processor = ProcessorThatStoresStderrInFiles(
         self._app_env.os_services.command_executor,
         str_src_as_stdin.of_sequence(self._program.stdin,
                                      self._app_env.mem_buff_size),
         file_ctx_managers.dev_null(),
         self._app_env.tmp_files_space.new_path(
             process_output_files.STDERR_FILE_NAME),
     )
     return processor.process(self._app_env.process_execution_settings,
                              self._program.command)
Exemple #2
0
    def test_invalid_executable_SHOULD_raise_hard_error(self):
        # ARRANGE #
        with tmp_dir.tmp_dir() as tmp_dir_path:
            with self.assertRaises(HardErrorException) as ctx:
                executor = sut.ProcessorThatStoresResultInFilesInDir(COMMAND_EXECUTOR,
                                                                     tmp_dir_path,
                                                                     file_ctx_managers.dev_null(),
                                                                     )

                # ACT & ASSERT #
                executor.process(
                    ProcessExecutionSettings.null(),
                    command_for_exe_file(tmp_dir_path / 'non-existing-program'),
                )
        assert isinstance(ctx.exception, HardErrorException)
        asrt_text_doc.is_any_text().apply_with_message(
            self,
            ctx.exception.error,
            'exception error message'
        )
Exemple #3
0
    def test_exit_code(self):
        # ARRANGE #
        exit_code = 3

        program_file = File(
            'program.py',
            py_programs.py_pgm_with_stdout_stderr_exit_code(exit_code=exit_code),
        )
        with tmp_dir.tmp_dir(DirContents([program_file])) as tmp_dir_path:
            executor = sut.ProcessorThatStoresResultInFilesInDir(COMMAND_EXECUTOR,
                                                                 tmp_dir_path,
                                                                 file_ctx_managers.dev_null(),
                                                                 )
            # ACT #
            result = executor.process(ProcessExecutionSettings.null(),
                                      py_exe.command_for_interpreting(tmp_dir_path / program_file.name))
            # ASSERT #
            self.assertEqual(exit_code,
                             result.exit_code,
                             'Exit code')
Exemple #4
0
 def test_storage_of_result_in_files__existing_dir(self):
     # ARRANGE #
     py_pgm_file = File(
         'program.py',
         program_that_prints_and_exits_with_exit_code(PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS),
     )
     with tmp_dir.tmp_dir(DirContents([py_pgm_file])) as pgm_dir_path:
         with tmp_dir.tmp_dir() as output_dir_path:
             executor = sut.ProcessorThatStoresResultInFilesInDir(COMMAND_EXECUTOR,
                                                                  output_dir_path,
                                                                  file_ctx_managers.dev_null(),
                                                                  )
             # ACT #
             result = executor.process(ProcessExecutionSettings.null(),
                                       py_exe.command_for_interpreting(pgm_dir_path / py_pgm_file.name)
                                       )
             # ASSERT #
             assert_is_success_and_output_dir_contains_at_exactly_result_files(
                 self,
                 output_dir_path,
                 PROCESS_OUTPUT_WITH_NON_ZERO_EXIT_STATUS,
                 result,
             )
Exemple #5
0
    def test_fail_WHEN_storage_dir_is_an_existing_regular_file(self):
        # ARRANGE #
        successful_py_program = File(
            'successful.py',
            py_programs.py_pgm_with_stdout_stderr_exit_code(exit_code=0),
        )
        existing_file = File.empty('a-file')
        dir_contents = DirContents([successful_py_program, existing_file])

        with tmp_dir.tmp_dir(dir_contents) as tmp_dir_path:
            path_of_existing_regular_file = tmp_dir_path / existing_file.name
            executor = sut.ProcessorThatStoresResultInFilesInDir(
                COMMAND_EXECUTOR,
                path_of_existing_regular_file,
                file_ctx_managers.dev_null(),
            )
            with self.assertRaises(exception.ImplementationError) as ctx:
                # ACT & ASSERT #
                executor.process(
                    ProcessExecutionSettings.null(),
                    command_for_exe_file(tmp_dir_path / successful_py_program.name),
                )
        assert isinstance(ctx.exception, exception.ImplementationError)
        self.assertIsInstance(ctx.exception.message, str, 'exception info')