Skip to content

Commit

Permalink
Fix compatibility issue with capture_output=True on Python 3.6 (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
xen0l authored Apr 21, 2020
1 parent 6cfafbd commit 6df6d85
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion aws_gate/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tarfile
import tempfile
import zipfile
from subprocess import PIPE

import requests
import unix_ar
Expand All @@ -22,7 +23,7 @@


def _check_plugin_version(path=PLUGIN_INSTALL_PATH):
return execute(path, ["--version"], capture_output=True)
return execute(path, ["--version"], stdout=PIPE, stderr=PIPE)


class Plugin:
Expand Down
3 changes: 2 additions & 1 deletion aws_gate/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from subprocess import PIPE

from wrapt import decorator

Expand Down Expand Up @@ -35,7 +36,7 @@ def plugin_version(required_version):
def wrapper(
wrapped_function, instance, args, kwargs
): # pylint: disable=unused-argument
version = execute_plugin(["--version"], capture_output=True)
version = execute_plugin(["--version"], stdout=PIPE, stderr=PIPE)
logger.debug(
"session-manager-plugin version: %s (required version: %s)",
version,
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from subprocess import PIPE

import pytest
import requests

Expand Down Expand Up @@ -38,7 +40,7 @@ def test_check_plugin_version(mocker):

assert m.called
assert m.call_args == mocker.call(
PLUGIN_INSTALL_PATH, ["--version"], capture_output=True
PLUGIN_INSTALL_PATH, ["--version"], stdout=PIPE, stderr=PIPE
)


Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from subprocess import PIPE

import pytest

from aws_gate.decorators import (
Expand Down Expand Up @@ -47,7 +49,7 @@ def test_function():
return "executed"

assert test_function() == "executed"
assert m.call_args == mocker.call(["--version"], capture_output=True)
assert m.call_args == mocker.call(["--version"], stdout=PIPE, stderr=PIPE)


def test_plugin_version_bad_version(mocker):
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

import pytest

from aws_gate.list import list_instances, serialize
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import errno
import os
import subprocess
from subprocess import PIPE

import pytest
from botocore.exceptions import ClientError
from botocore import credentials
from botocore.exceptions import ClientError
from hypothesis import given
from hypothesis.strategies import lists, text

Expand Down Expand Up @@ -158,18 +159,20 @@ def test_execute_command_not_found(mocker):

def test_execute_plugin(mocker):
mocker.patch("aws_gate.utils.execute", return_value="output")
output = execute_plugin(["--version"], capture_output=True)
output = execute_plugin(["--version"], stdout=PIPE, stderrr=PIPE)

assert output == "output"


def test_execute_plugin_args(mocker):
m = mocker.patch("aws_gate.utils.execute", return_value="output")

execute_plugin(["--version"], capture_output=True)
execute_plugin(["--version"], stdout=PIPE, stderr=PIPE)

assert m.called
assert "['--version'], capture_output=True" in str(m.call_args)
assert "['--version']" in str(m.call_args[0])
assert m.call_args[1]["stdout"] == PIPE
assert m.call_args[1]["stderr"] == PIPE


def test_fetch_instance_details_from_config(config):
Expand Down

0 comments on commit 6df6d85

Please sign in to comment.