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

FakeProcess doesn't respect universal_newlines #37

Open
bjornt opened this issue Mar 13, 2017 · 3 comments
Open

FakeProcess doesn't respect universal_newlines #37

bjornt opened this issue Mar 13, 2017 · 3 comments

Comments

@bjornt
Copy link

bjornt commented Mar 13, 2017

FakeProcess always returns stdout.getvalue() and stderr.getvalue() as they are. This is a problem when you're testing code that sometimes passe universal_newlines to the subprocess calls.

In Python 2.7, universal_newlines doesn't make much of a difference, but in Python 3, if you pass universal_newlines=True, you will get strings instead of bytes for stdout and stderr in the subprocess calls.kaasjrzrrzr

@freeekanayaka
Copy link
Member

I guess the solution would be make FakeProcess honor universal_newline and decode the bytes in that case?

@bjornt
Copy link
Author

bjornt commented Mar 13, 2017

Yeah, I think that makes sense. Note that this should be done for Python 3 only. For Python 2 str is always returned, universal_newlines doesn't make a difference there.

Popen is tricky to fake. In another project I faked Popen I did so by creating temp scripts that wrote to stdout and stderr. That way I could use the real Popen to fake the output part by executing those scripts, so all subtle behaviors were taken care of the way the should.

@freeekanayaka
Copy link
Member

@bjornt yes, I think both approaches (fake popen vs fake executables) make sense in different situations. You might have noticed already, but for there's support in systemfixtures for faking executables:

http://systemfixtures.readthedocs.io/en/latest/#executables

Depending on your situation you might prefer one or the other or a combination of both. Happy to help improving any rough edges you might find (either in FakePopen or FakeExecutable).

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