Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hawflau committed Jun 28, 2024
1 parent 9fe0738 commit f573dcc
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions tests/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from threading import Thread
from typing import Callable, List, Optional, cast
from collections import namedtuple
from subprocess import Popen, PIPE, TimeoutExpired, check_output
from subprocess import Popen, PIPE, TimeoutExpired, CalledProcessError
import subprocess
from queue import Queue

from samcli import __version__ as SAM_CLI_VERSION
Expand Down Expand Up @@ -67,68 +68,47 @@ def method_to_stack_name(method_name):
def run_command(command_list, cwd=None, env=None, timeout=TIMEOUT) -> CommandResult:
LOG.info("Running command: %s", " ".join(command_list))

import subprocess

try:
process = subprocess.run(command_list, cwd=cwd, timeout=timeout, stdout=PIPE, stderr=PIPE)
except subprocess.CalledProcessError as e:
except CalledProcessError as e:
LOG.error("Command %s failed: %s", command_list, e.returncode)
LOG.error("Stdout: %s", e.stdout.decode("utf-8"))
LOG.error("Stderr: %s", e.stderr.decode("utf-8"))
raise
except TimeoutExpired as e:
LOG.error("Command %s, TIMED OUT")
LOG.error("Stdout: %s", e.stdout.decode("utf-8"))
LOG.error("Stderr: %s", e.stderr.decode("utf-8"))
LOG.error("Command %s, TIMED OUT in %ss", command_list, timeout)
if e.stdout:
LOG.error("Stdout: %s", e.stdout.decode("utf-8"))
if e.stderr:
LOG.error("Stderr: %s", e.stderr.decode("utf-8"))
raise

LOG.info("Stdout: %s", process.stdout.decode("utf-8"))
LOG.info("Stderr: %s", process.stderr.decode("utf-8"))
return CommandResult(process, process.stdout, process.stderr)
# process_execute = Popen(command_list, cwd=cwd, env=env, stdout=PIPE, stderr=PIPE)
# try:
# stdout_data, stderr_data = process_execute.communicate(timeout=timeout)
# LOG.info(f"Stdout: {stdout_data.decode('utf-8')}")
# LOG.info(f"Stderr: {stderr_data.decode('utf-8')}")
# return CommandResult(process_execute, stdout_data, stderr_data)
# except TimeoutExpired:
# LOG.error(f"Command: {command_list}, TIMED OUT")
# LOG.error(f"Return Code: {process_execute.returncode}")
# process_execute.kill()
# raise


def run_command_with_input(command_list, stdin_input, timeout=TIMEOUT, cwd=None) -> CommandResult:
LOG.info("Running command: %s", " ".join(command_list))
LOG.info("With input: %s", stdin_input)
import subprocess

try:
process = subprocess.run(command_list, cwd=cwd, input=stdin_input, timeout=timeout, stdout=PIPE, stderr=PIPE)
except subprocess.CalledProcessError as e:
except CalledProcessError as e:
LOG.error("Command %s failed: %s", command_list, e.returncode)
LOG.error("Stdout: %s", e.stdout.decode("utf-8"))
LOG.error("Stderr: %s", e.stderr.decode("utf-8"))
raise
except TimeoutExpired as e:
LOG.error("Command %s, TIMED OUT")
LOG.error("Stdout: %s", e.stdout.decode("utf-8"))
LOG.error("Stderr: %s", e.stderr.decode("utf-8"))
LOG.error("Command %s, TIMED OUT in %ss", command_list, timeout)
if e.stdout:
LOG.error("Stdout: %s", e.stdout.decode("utf-8"))
if e.stderr:
LOG.error("Stderr: %s", e.stderr.decode("utf-8"))
raise
LOG.info("Stdout: %s", process.stdout.decode("utf-8"))
LOG.info("Stderr: %s", process.stderr.decode("utf-8"))
return CommandResult(process, process.stdout, process.stderr)
# process_execute = Popen(command_list, cwd=cwd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
# try:
# stdout_data, stderr_data = process_execute.communicate(stdin_input, timeout=timeout)
# LOG.info(f"Stdout: {stdout_data.decode('utf-8')}")
# LOG.info(f"Stderr: {stderr_data.decode('utf-8')}")
# return CommandResult(process_execute, stdout_data, stderr_data)
# except TimeoutExpired:
# LOG.error(f"Command: {command_list}, TIMED OUT")
# LOG.error(f"Return Code: {process_execute.returncode}")
# process_execute.kill()
# raise


def run_command_with_inputs(command_list: List[str], inputs: List[str], timeout=TIMEOUT) -> CommandResult:
Expand Down

0 comments on commit f573dcc

Please sign in to comment.