Merge pull request #1866 from joguSD/bugfix-stdin-stub-buffer
Add buffer attribute to DontReadFromInput
This commit is contained in:
commit
9c45d6cd83
1
AUTHORS
1
AUTHORS
|
@ -69,6 +69,7 @@ Javier Domingo Cansino
|
||||||
Javier Romero
|
Javier Romero
|
||||||
John Towler
|
John Towler
|
||||||
Jon Sonesen
|
Jon Sonesen
|
||||||
|
Jordan Guymon
|
||||||
Joshua Bronson
|
Joshua Bronson
|
||||||
Jurko Gospodnetić
|
Jurko Gospodnetić
|
||||||
Justyna Janczyszyn
|
Justyna Janczyszyn
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
* Improve error message when passing non-string ids to ``pytest.mark.parametrize`` (`#1857`_).
|
* Improve error message when passing non-string ids to ``pytest.mark.parametrize`` (`#1857`_).
|
||||||
Thanks `@okken`_ for the report and `@nicoddemus`_ for the PR.
|
Thanks `@okken`_ for the report and `@nicoddemus`_ for the PR.
|
||||||
|
|
||||||
*
|
* Add ``buffer`` attribute to stdin stub class ``pytest.capture.DontReadFromInput``
|
||||||
|
Thanks `@joguSD`_ for the PR.
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
.. _@joguSD: https://github.com/joguSD
|
||||||
|
|
||||||
.. _#1857: https://github.com/pytest-dev/pytest/issues/1857
|
.. _#1857: https://github.com/pytest-dev/pytest/issues/1857
|
||||||
|
|
||||||
|
|
|
@ -455,6 +455,13 @@ class DontReadFromInput:
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@property
|
||||||
|
def buffer(self):
|
||||||
|
if sys.version_info >= (3,0):
|
||||||
|
return self
|
||||||
|
else:
|
||||||
|
raise AttributeError('redirected stdin has no attribute buffer')
|
||||||
|
|
||||||
|
|
||||||
def _readline_workaround():
|
def _readline_workaround():
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -662,6 +662,28 @@ def test_dontreadfrominput():
|
||||||
f.close() # just for completeness
|
f.close() # just for completeness
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif('sys.version_info < (3,)', reason='python2 has no buffer')
|
||||||
|
def test_dontreadfrominput_buffer_python3():
|
||||||
|
from _pytest.capture import DontReadFromInput
|
||||||
|
f = DontReadFromInput()
|
||||||
|
fb = f.buffer
|
||||||
|
assert not fb.isatty()
|
||||||
|
pytest.raises(IOError, fb.read)
|
||||||
|
pytest.raises(IOError, fb.readlines)
|
||||||
|
pytest.raises(IOError, iter, fb)
|
||||||
|
pytest.raises(ValueError, fb.fileno)
|
||||||
|
f.close() # just for completeness
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif('sys.version_info >= (3,)', reason='python2 has no buffer')
|
||||||
|
def test_dontreadfrominput_buffer_python2():
|
||||||
|
from _pytest.capture import DontReadFromInput
|
||||||
|
f = DontReadFromInput()
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
f.buffer
|
||||||
|
f.close() # just for completeness
|
||||||
|
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.yield_fixture
|
||||||
def tmpfile(testdir):
|
def tmpfile(testdir):
|
||||||
f = testdir.makepyfile("").open('wb+')
|
f = testdir.makepyfile("").open('wb+')
|
||||||
|
|
Loading…
Reference in New Issue