Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential issue with combinations #125

Closed
jmasonlee opened this issue Oct 6, 2022 · 2 comments
Closed

Potential issue with combinations #125

jmasonlee opened this issue Oct 6, 2022 · 2 comments

Comments

@jmasonlee
Copy link
Contributor

I have a method that wraps subprocess.run and returns the result:

def run(command, capture_output = False, text = True, shell=True, record=None, playback=None):
    output = subprocess.run(command, capture_output=capture_output, text=text, shell=shell)
    return output

I have a test that verifies all combinations of command, capture_output, text and shell:

def test_subprocess_run():
    commands = ["echo 'foo'", "echo 'foo' 1>&2", ["echo", "'foo'"], ["echo", "'foo'", "1>&2"]]
    text = [True, False]
    capture_output = [True, False]
    shell = [True,False]
    verify_all_combinations(run, [commands, capture_output, text, shell])
    verify_all_combinations_with_kwargs(run, command = commands, text = text, capture_output= capture_output, shell = shell)

I am trying to check that my verify_all_combinations_with_kwargs method works as well as verify_all_combinations, but when I run the two tests on an approved file generated by verify_all_combinations, I get an error for the second verify method:

received (from verify_all_combinations_with_kwargs)
args: ({'command': "echo 'foo'", 'text': True, 'capture_output': False, 'shell': True}) => CompletedProcess(args="echo 'foo'", returncode=0)

approved (from verify_all_combinations)
args: ("echo 'foo'", True, False, True) => CompletedProcess(args="echo 'foo'", returncode=0, stdout=b'foo\n', stderr=b'')

I want the keywords printed out with the arguments, so if I ignore that difference, you can see that the result from running verify_all_combinations adds stdout=b'foo\n', stderr=b''

received (from verify_all_combinations_with_kwargs)
args: ("echo 'foo'", True, False, True) => CompletedProcess(args="echo 'foo'", returncode=0)

approved (from verify_all_combinations)
args: ("echo 'foo'", True, False, True) => CompletedProcess(args="echo 'foo'", returncode=0, stdout=b'foo\n', stderr=b'')

I wrote a second test:

def test_bug_with_combinations():
    input = {'command': "echo 'foo'", 'capture_output': True, 'text': False, 'shell': True}
    verify(run(capture_output=input["capture_output"], command=input["command"], text=input["text"], shell=input["shell"]))
    verify(run(input["command"], input["capture_output"], input["text"], input["shell"]))

In both cases, the output is: CompletedProcess(args="echo 'foo'", returncode=0)

I wrote another test:

def test_bug_with_combinations():
    input = {'command': "echo 'foo'", 'capture_output': True, 'text': False, 'shell': True}
    verify_all_combinations(run, [[input['command']], [input['capture_output']], [input['text']], [input['shell']]])

This returns:

args: ("echo 'foo'", True, False, True) => CompletedProcess(args="echo 'foo'", returncode=0, stdout=b'foo\n', stderr=b'')

I think something is up with verify_all_combinations

@nitsanavni
Copy link
Contributor

Hey! We just did some work around running subprocess.
Did you know there's a subprocess.check_output method?

@jmasonlee
Copy link
Contributor Author

Yes thank you! This was an issue with my code :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants