# Path: crosscompute/exceptions.py
# class CrossComputeExecutionError(CrossComputeError):
#     pass
# 
# Path: crosscompute/routines/automation.py
# def _run_command(
#         command_string, command_folder, script_environment, o_file, e_file):
#     try:
#         process = subprocess.run(
#             shlex.split(command_string),
#             check=True,
#             cwd=command_folder,
#             env=script_environment,
#             stdout=o_file,
#             stderr=e_file)
#     except (IndexError, OSError):
#         e = CrossComputeExecutionError(
#             f'could not run {shlex.quote(command_string)} in {command_folder}')
#         e.return_code = Error.COMMAND_NOT_FOUND
#         raise e
#     except subprocess.CalledProcessError as e:
#         e_file.seek(0)
#         error_text = e_file.read().rstrip()
#         error = CrossComputeExecutionError(error_text)
#         error.return_code = e.returncode
#         raise error
#     return process.returncode


from pytest import raises
from crosscompute.exceptions import CrossComputeExecutionError
from crosscompute.routines.automation import _run_command



def test_run_command(tmp_path):
    o_path = tmp_path / 'o.txt'
    e_path = tmp_path / 'e.txt'
    with open(o_path, 'wt') as o_file, open(e_path, 'w+t') as e_file:
        with raises(CrossComputeExecutionError):
            _run_command('', tmp_path, {}, o_file, e_file)

# Path: crosscompute/exceptions.py
# class CrossComputeExecutionError(CrossComputeError):
#     pass
# 
# Path: crosscompute/routines/automation.py
# def _run_command(
#         command_string, command_folder, script_environment, o_file, e_file):
#     try:
#         process = subprocess.run(
#             shlex.split(command_string),
#             check=True,
#             cwd=command_folder,
#             env=script_environment,
#             stdout=o_file,
#             stderr=e_file)
#     except (IndexError, OSError):
#         e = CrossComputeExecutionError(
#             f'could not run {shlex.quote(command_string)} in {command_folder}')
#         e.return_code = Error.COMMAND_NOT_FOUND
#         raise e
#     except subprocess.CalledProcessError as e:
#         e_file.seek(0)
#         error_text = e_file.read().rstrip()
#         error = CrossComputeExecutionError(error_text)
#         error.return_code = e.returncode
#         raise error
#     return process.returncode


# Path: tests/test_routines_automation.py
from pytest import raises
from crosscompute.exceptions import CrossComputeExecutionError
from crosscompute.routines.automation import _run_command




def test_run_command(tmp_path):
    o_path = tmp_path / 'o.txt'
    e_path = tmp_path / 'e.txt'
    with open(o_path, 'wt') as o_file, open(e_path, 'w+t') as e_file:
        with raises(CrossComputeExecutionError):
            _run_command('', tmp_path, {}, o_file, e_file)

        with raises(CrossComputeExecutionError):