Skip to content

check for detached stream buffer in utils.misc.isatty() - #1948

Merged
pekkaklarck merged 2 commits into
robotframework:masterfrom
userzimmermann:isatty
May 26, 2015
Merged

pekkaklarck merged 2 commits into
robotframework:masterfrom
userzimmermann:isatty

Conversation

@userzimmermann

Copy link
Copy Markdown
Contributor

If the .buffer of an io module based stream was detached, the stream.isatty() method called in utils.misc.isatty() will raise a ValueError. As utils.misc.isatty() is usually only applied to sys.stdout and sys.stderr it most likely won't happen in Python 2. But who knows what other streams this function might be used with or what other projects might do with sys.std... before importing robot. And the buffer check is definitely needed for Python 3 compatibility. I encountered it recently on adding Sphinx based docs to my robotframework-tools project and running setup.py build_sphinx with Python 3, using a conf.py which imports robot. And just imprting robot is enough, because the creation of robot.output.logger.LOGGER leads to the use of isatty(). Maybe my fix is not at the best place and streams should be checked earlier...

@robotci

robotci commented Mar 12, 2015

Copy link
Copy Markdown

Admin, can CI be enabled?

@pekkaklarck

Copy link
Copy Markdown
Member
  1. The change itself looks good to me.
  2. Is it possible to create a unit test for this?
  3. Do you have references to docs about io based streams raising ValueError? I would like to study this topic a bit more myself.
  4. @robotci: Enable

@robotci

robotci commented Mar 27, 2015

Copy link
Copy Markdown

@userzimmermann

Copy link
Copy Markdown
Contributor Author

I've added a utest in utils/test_misc

@robotci

robotci commented May 9, 2015

Copy link
Copy Markdown

@robotci

robotci commented May 9, 2015

Copy link
Copy Markdown

@robotci

robotci commented May 9, 2015

Copy link
Copy Markdown

Comment thread utest/utils/test_misc.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: No need to have an empty row between standard library imports.

@pekkaklarck

Copy link
Copy Markdown
Member

Looks very good to me. Few more comments, though:

  • As I already commented in a line note, it would be better to have individual tests for different stream types.
  • Have you tested this using Jython and IronPython? The latter has a totally different isatty implementation that shouldn't be affected, but testing with Jython 2.7 would be great.
  • Was there already an issue about this? Although this is a pretty minor issue, it would be good to have one for reference.

@pekkaklarck

Copy link
Copy Markdown
Member

@userzimmermann, have you had a change to look at this lately? I'm going through PRs today and would like to merge as many as I can. This one looks pretty good already.

@robotci

robotci commented May 24, 2015

Copy link
Copy Markdown

@userzimmermann

Copy link
Copy Markdown
Contributor Author
  • Did even further split and cleaned up imports
  • Added Jython 2.7 support
  • No existing issue

@robotci

robotci commented May 24, 2015

Copy link
Copy Markdown

@pekkaklarck

Copy link
Copy Markdown
Member

This PR looks good to be merged. Could you still squash commits and submit an issue about this?

@userzimmermann

Copy link
Copy Markdown
Contributor Author

As you like it ;) #2003

@robotci

robotci commented May 26, 2015

Copy link
Copy Markdown

pekkaklarck added a commit that referenced this pull request May 26, 2015
check for detached stream buffer in utils.misc.isatty()
@pekkaklarck
pekkaklarck merged commit b497bd7 into robotframework:master May 26, 2015
@pekkaklarck

Copy link
Copy Markdown
Member

Thanks @userzimmermann!

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

Successfully merging this pull request may close these issues.

3 participants