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

refactor executeReplay to make it more testable. #6

Open
levlaz opened this issue Dec 17, 2018 · 1 comment
Open

refactor executeReplay to make it more testable. #6

levlaz opened this issue Dec 17, 2018 · 1 comment

Comments

@levlaz
Copy link
Contributor

levlaz commented Dec 17, 2018

Right now its pretty hard to write a unit test for this function because its calling commands outside of the process and not capturing any output.

We should use subprocess instead of run.

This will allow us to mock some responses and verify that the commands are being ran as expected.

@levlaz
Copy link
Contributor Author

levlaz commented Mar 11, 2019

Looking back on this I don't think that run is necessarily the issue here. I think I had a poor understanding of what run is doing. We can get similar introspection of command output using run, we just need to make sure that we are capturing it.

From the run docs:

Run command with arguments and return a CompletedProcess instance.

The returned instance will have attributes args, returncode, stdout and stderr. By default, stdout and stderr are not captured, and those attributes will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.

If check is True and the exit code was non-zero, it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute, and output & stderr attributes if those streams were captured.

If timeout is given, and the process takes too long, a TimeoutExpired exception will be raised.

There is an optional argument "input", allowing you to pass a string to the subprocess's stdin. If you use this argument you may not also use the Popen constructor's "stdin" argument, as it will be used internally.

The other arguments are the same as for the Popen constructor.

If universal_newlines=True is passed, the "input" argument must be a string and stdout/stderr in the returned object will be strings rather than bytes.

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

1 participant