4 new commits in pytest:
https://bitbucket.org/hpk42/pytest/commits/ed13d2637cdf/
Changeset: ed13d2637cdf
Branch: capsimple1
User: hpk42
Date: 2014-01-25 19:42:45
Summary: remove now parameter because pytest only used now==False everywhere
Affected #: 2 files
diff -r cd028703f029183cce422260040080920dabda63 -r
ed13d2637cdf16e33aca6f632ade29753dca4236 _pytest/capture.py
--- a/_pytest/capture.py
+++ b/_pytest/capture.py
@@ -126,13 +126,11 @@
def _getcapture(self, method):
if method == "fd":
return StdCaptureFD(
- now=False,
out=self._maketempfile(),
err=self._maketempfile(),
)
elif method == "sys":
return StdCapture(
- now=False,
out=self._makestringio(),
err=self._makestringio(),
)
@@ -283,7 +281,7 @@
class CaptureFixture:
def __init__(self, captureclass):
- self._capture = captureclass(now=False)
+ self._capture = captureclass()
def _start(self):
self._capture.startall()
@@ -307,7 +305,7 @@
class FDCapture:
""" Capture IO to/from a given os-level filedescriptor. """
- def __init__(self, targetfd, tmpfile=None, now=True, patchsys=False):
+ def __init__(self, targetfd, tmpfile=None, patchsys=False):
""" save targetfd descriptor, and open a new
temporary file there. If no tmpfile is
specified a tempfile.Tempfile() will be opened
@@ -322,8 +320,6 @@
self._savefd = os.dup(self.targetfd)
if patchsys:
self._oldsys = getattr(sys, patchsysdict[targetfd])
- if now:
- self.start()
def start(self):
try:
@@ -421,6 +417,7 @@
and capture output/error during its execution.
"""
so = cls()
+ so.startall()
try:
res = func(*args, **kwargs)
finally:
@@ -457,18 +454,15 @@
is invalid it will not be captured.
"""
def __init__(self, out=True, err=True, mixed=False,
- in_=True, patchsys=True, now=True):
+ in_=True, patchsys=True):
self._options = {
"out": out,
"err": err,
"mixed": mixed,
"in_": in_,
"patchsys": patchsys,
- "now": now,
}
self._save()
- if now:
- self.startall()
def _save(self):
in_ = self._options['in_']
@@ -479,7 +473,7 @@
if in_:
try:
self.in_ = FDCapture(
- 0, tmpfile=None, now=False,
+ 0, tmpfile=None,
patchsys=patchsys)
except OSError:
pass
@@ -490,7 +484,7 @@
try:
self.out = FDCapture(
1, tmpfile=tmpfile,
- now=False, patchsys=patchsys)
+ patchsys=patchsys)
self._options['out'] = self.out.tmpfile
except OSError:
pass
@@ -504,7 +498,7 @@
try:
self.err = FDCapture(
2, tmpfile=tmpfile,
- now=False, patchsys=patchsys)
+ patchsys=patchsys)
self._options['err'] = self.err.tmpfile
except OSError:
pass
@@ -562,7 +556,7 @@
modifies sys.stdout|stderr|stdin attributes and does not
touch underlying File Descriptors (use StdCaptureFD for that).
"""
- def __init__(self, out=True, err=True, in_=True, mixed=False, now=True):
+ def __init__(self, out=True, err=True, in_=True, mixed=False):
self._oldout = sys.stdout
self._olderr = sys.stderr
self._oldin = sys.stdin
@@ -576,8 +570,6 @@
err = TextIO()
self.err = err
self.in_ = in_
- if now:
- self.startall()
def startall(self):
if self.out:
diff -r cd028703f029183cce422260040080920dabda63 -r
ed13d2637cdf16e33aca6f632ade29753dca4236 testing/test_capture.py
--- a/testing/test_capture.py
+++ b/testing/test_capture.py
@@ -661,21 +661,6 @@
class TestFDCapture:
pytestmark = needsosdup
- def test_not_now(self, tmpfile):
- fd = tmpfile.fileno()
- cap = capture.FDCapture(fd, now=False)
- data = tobytes("hello")
- os.write(fd, data)
- f = cap.done()
- s = f.read()
- assert not s
- cap = capture.FDCapture(fd, now=False)
- cap.start()
- os.write(fd, data)
- f = cap.done()
- s = f.read()
- assert s == "hello"
-
def test_simple(self, tmpfile):
fd = tmpfile.fileno()
cap = capture.FDCapture(fd)
@@ -683,8 +668,13 @@
os.write(fd, data)
f = cap.done()
s = f.read()
+ assert not s
+ cap = capture.FDCapture(fd)
+ cap.start()
+ os.write(fd, data)
+ f = cap.done()
+ s = f.read()
assert s == "hello"
- f.close()
def test_simple_many(self, tmpfile):
for i in range(10):
@@ -702,6 +692,7 @@
def test_stderr(self):
cap = capture.FDCapture(2, patchsys=True)
+ cap.start()
print_("hello", file=sys.stderr)
f = cap.done()
s = f.read()
@@ -711,6 +702,7 @@
tmpfile.write(tobytes("3"))
tmpfile.seek(0)
cap = capture.FDCapture(0, tmpfile=tmpfile)
+ cap.start()
# check with os.read() directly instead of raw_input(), because
# sys.stdin itself may be redirected (as pytest now does by default)
x = os.read(0, 100).strip()
@@ -721,6 +713,7 @@
data1, data2 = tobytes("foo"), tobytes("bar")
try:
cap = capture.FDCapture(tmpfile.fileno())
+ cap.start()
tmpfile.write(data1)
cap.writeorg(data2)
finally:
@@ -734,7 +727,9 @@
class TestStdCapture:
def getcapture(self, **kw):
- return capture.StdCapture(**kw)
+ cap = capture.StdCapture(**kw)
+ cap.startall()
+ return cap
def test_capturing_done_simple(self):
cap = self.getcapture()
@@ -879,19 +874,13 @@
assert not err
-class TestStdCaptureNotNow(TestStdCapture):
- def getcapture(self, **kw):
- kw['now'] = False
- cap = capture.StdCapture(**kw)
- cap.startall()
- return cap
-
-
class TestStdCaptureFD(TestStdCapture):
pytestmark = needsosdup
def getcapture(self, **kw):
- return capture.StdCaptureFD(**kw)
+ cap = capture.StdCaptureFD(**kw)
+ cap.startall()
+ return cap
def test_intermingling(self):
cap = self.getcapture()
@@ -926,15 +915,6 @@
lsof_check(f)
-class TestStdCaptureFDNotNow(TestStdCaptureFD):
- pytestmark = needsosdup
-
- def getcapture(self, **kw):
- kw['now'] = False
- cap = capture.StdCaptureFD(**kw)
- cap.startall()
- return cap
-
@needsosdup
def test_stdcapture_fd_tmpfile(tmpfile):
@@ -974,7 +954,7 @@
def test_capture_not_started_but_reset():
- capsys = capture.StdCapture(now=False)
+ capsys = capture.StdCapture()
capsys.done()
capsys.done()
capsys.reset()
@@ -985,6 +965,7 @@
capsys = capture.StdCapture()
try:
cap = capture.StdCaptureFD(patchsys=False)
+ cap.startall()
sys.stdout.write("hello")
sys.stderr.write("world")
oswritebytes(1, "1")
@@ -1006,6 +987,7 @@
return 42
capfd = capture.StdCaptureFD(patchsys=False)
+ capfd.startall()
try:
res, out, err = capture.StdCapture.call(func, 3, y=4)
finally:
@@ -1020,7 +1002,7 @@
def test_fdcapture_tmpfile_remains_the_same(tmpfile, use):
if not use:
tmpfile = True
- cap = capture.StdCaptureFD(out=False, err=tmpfile, now=False)
+ cap = capture.StdCaptureFD(out=False, err=tmpfile)
try:
cap.startall()
capfile = cap.err.tmpfile
@@ -1042,6 +1024,7 @@
import py, logging
from _pytest import capture
cap = capture.%s(out=False, in_=False)
+ cap.startall()
logging.warn("hello1")
outerr = cap.suspend()
https://bitbucket.org/hpk42/pytest/commits/a1c004249dce/
Changeset: a1c004249dce
Branch: capsimple1
User: hpk42
Date: 2014-01-25 19:43:57
Summary: remove "StdCapture*.call" classmethod because pytest does not use
it.
Affected #: 2 files
diff -r ed13d2637cdf16e33aca6f632ade29753dca4236 -r
a1c004249dcea37a6e62768ecfbe65aefbf24647 _pytest/capture.py
--- a/_pytest/capture.py
+++ b/_pytest/capture.py
@@ -409,22 +409,6 @@
class Capture(object):
- def call(cls, func, *args, **kwargs):
- """ return a (res, out, err) tuple where
- out and err represent the output/error output
- during function execution.
- call the given function with args/kwargs
- and capture output/error during its execution.
- """
- so = cls()
- so.startall()
- try:
- res = func(*args, **kwargs)
- finally:
- out, err = so.reset()
- return res, out, err
- call = classmethod(call)
-
def reset(self):
""" reset sys.stdout/stderr and return captured output as strings. """
if hasattr(self, '_reset'):
diff -r ed13d2637cdf16e33aca6f632ade29753dca4236 -r
a1c004249dcea37a6e62768ecfbe65aefbf24647 testing/test_capture.py
--- a/testing/test_capture.py
+++ b/testing/test_capture.py
@@ -896,17 +896,6 @@
assert out == "123"
assert err == "abc"
- def test_callcapture(self):
- def func(x, y):
- print (x)
- sys.stderr.write(str(y))
- return 42
-
- res, out, err = capture.StdCaptureFD.call(func, 3, y=4)
- assert res == 42
- assert out.startswith("3")
- assert err.startswith("4")
-
def test_many(self, capfd):
def f():
for i in range(10):
@@ -978,26 +967,6 @@
@needsosdup
-def test_callcapture_nofd():
- def func(x, y):
- oswritebytes(1, "hello")
- oswritebytes(2, "hello")
- print (x)
- sys.stderr.write(str(y))
- return 42
-
- capfd = capture.StdCaptureFD(patchsys=False)
- capfd.startall()
- try:
- res, out, err = capture.StdCapture.call(func, 3, y=4)
- finally:
- capfd.reset()
- assert res == 42
- assert out.startswith("3")
- assert err.startswith("4")
-
-
-@needsosdup
@pytest.mark.parametrize('use', [True, False])
def test_fdcapture_tmpfile_remains_the_same(tmpfile, use):
if not use:
https://bitbucket.org/hpk42/pytest/commits/0de40fd1fe9f/
Changeset: 0de40fd1fe9f
Branch: capsimple1
User: hpk42
Date: 2014-01-25 19:56:27
Summary: remove "mixed" capturing mode which is not used by pytest
Affected #: 2 files
diff -r a1c004249dcea37a6e62768ecfbe65aefbf24647 -r
0de40fd1fe9fb0f8f05bd7762db5840eef0d80db _pytest/capture.py
--- a/_pytest/capture.py
+++ b/_pytest/capture.py
@@ -437,12 +437,10 @@
reads from sys.stdin). If any of the 0,1,2 file descriptors
is invalid it will not be captured.
"""
- def __init__(self, out=True, err=True, mixed=False,
- in_=True, patchsys=True):
+ def __init__(self, out=True, err=True, in_=True, patchsys=True):
self._options = {
"out": out,
"err": err,
- "mixed": mixed,
"in_": in_,
"patchsys": patchsys,
}
@@ -452,7 +450,6 @@
in_ = self._options['in_']
out = self._options['out']
err = self._options['err']
- mixed = self._options['mixed']
patchsys = self._options['patchsys']
if in_:
try:
@@ -473,9 +470,7 @@
except OSError:
pass
if err:
- if out and mixed:
- tmpfile = self.out.tmpfile
- elif hasattr(err, 'write'):
+ if hasattr(err, 'write'):
tmpfile = err
else:
tmpfile = None
@@ -540,7 +535,7 @@
modifies sys.stdout|stderr|stdin attributes and does not
touch underlying File Descriptors (use StdCaptureFD for that).
"""
- def __init__(self, out=True, err=True, in_=True, mixed=False):
+ def __init__(self, out=True, err=True, in_=True):
self._oldout = sys.stdout
self._olderr = sys.stderr
self._oldin = sys.stdin
@@ -548,9 +543,7 @@
out = TextIO()
self.out = out
if err:
- if mixed:
- err = out
- elif not hasattr(err, 'write'):
+ if not hasattr(err, 'write'):
err = TextIO()
self.err = err
self.in_ = in_
diff -r a1c004249dcea37a6e62768ecfbe65aefbf24647 -r
0de40fd1fe9fb0f8f05bd7762db5840eef0d80db testing/test_capture.py
--- a/testing/test_capture.py
+++ b/testing/test_capture.py
@@ -780,15 +780,6 @@
out, err = cap.readouterr()
assert out == py.builtin._totext('\ufffd\n', 'unicode-escape')
- def test_capturing_mixed(self):
- cap = self.getcapture(mixed=True)
- sys.stdout.write("hello ")
- sys.stderr.write("world")
- sys.stdout.write(".")
- out, err = cap.reset()
- assert out.strip() == "hello world."
- assert not err
-
def test_reset_twice_error(self):
cap = self.getcapture()
print ("hello")
https://bitbucket.org/hpk42/pytest/commits/4f3a783d4b7a/
Changeset: 4f3a783d4b7a
User: hpk42
Date: 2014-01-26 12:07:45
Summary: Merged in hpk42/pytest-capsimple/capsimple1 (pull request #115)
some simplifications in capturing code
Affected #: 2 files
diff -r cd028703f029183cce422260040080920dabda63 -r
4f3a783d4b7afc276205d7dd3247ee91f8722a34 _pytest/capture.py
--- a/_pytest/capture.py
+++ b/_pytest/capture.py
@@ -126,13 +126,11 @@
def _getcapture(self, method):
if method == "fd":
return StdCaptureFD(
- now=False,
out=self._maketempfile(),
err=self._maketempfile(),
)
elif method == "sys":
return StdCapture(
- now=False,
out=self._makestringio(),
err=self._makestringio(),
)
@@ -283,7 +281,7 @@
class CaptureFixture:
def __init__(self, captureclass):
- self._capture = captureclass(now=False)
+ self._capture = captureclass()
def _start(self):
self._capture.startall()
@@ -307,7 +305,7 @@
class FDCapture:
""" Capture IO to/from a given os-level filedescriptor. """
- def __init__(self, targetfd, tmpfile=None, now=True, patchsys=False):
+ def __init__(self, targetfd, tmpfile=None, patchsys=False):
""" save targetfd descriptor, and open a new
temporary file there. If no tmpfile is
specified a tempfile.Tempfile() will be opened
@@ -322,8 +320,6 @@
self._savefd = os.dup(self.targetfd)
if patchsys:
self._oldsys = getattr(sys, patchsysdict[targetfd])
- if now:
- self.start()
def start(self):
try:
@@ -413,21 +409,6 @@
class Capture(object):
- def call(cls, func, *args, **kwargs):
- """ return a (res, out, err) tuple where
- out and err represent the output/error output
- during function execution.
- call the given function with args/kwargs
- and capture output/error during its execution.
- """
- so = cls()
- try:
- res = func(*args, **kwargs)
- finally:
- out, err = so.reset()
- return res, out, err
- call = classmethod(call)
-
def reset(self):
""" reset sys.stdout/stderr and return captured output as strings. """
if hasattr(self, '_reset'):
@@ -456,30 +437,24 @@
reads from sys.stdin). If any of the 0,1,2 file descriptors
is invalid it will not be captured.
"""
- def __init__(self, out=True, err=True, mixed=False,
- in_=True, patchsys=True, now=True):
+ def __init__(self, out=True, err=True, in_=True, patchsys=True):
self._options = {
"out": out,
"err": err,
- "mixed": mixed,
"in_": in_,
"patchsys": patchsys,
- "now": now,
}
self._save()
- if now:
- self.startall()
def _save(self):
in_ = self._options['in_']
out = self._options['out']
err = self._options['err']
- mixed = self._options['mixed']
patchsys = self._options['patchsys']
if in_:
try:
self.in_ = FDCapture(
- 0, tmpfile=None, now=False,
+ 0, tmpfile=None,
patchsys=patchsys)
except OSError:
pass
@@ -490,21 +465,19 @@
try:
self.out = FDCapture(
1, tmpfile=tmpfile,
- now=False, patchsys=patchsys)
+ patchsys=patchsys)
self._options['out'] = self.out.tmpfile
except OSError:
pass
if err:
- if out and mixed:
- tmpfile = self.out.tmpfile
- elif hasattr(err, 'write'):
+ if hasattr(err, 'write'):
tmpfile = err
else:
tmpfile = None
try:
self.err = FDCapture(
2, tmpfile=tmpfile,
- now=False, patchsys=patchsys)
+ patchsys=patchsys)
self._options['err'] = self.err.tmpfile
except OSError:
pass
@@ -562,7 +535,7 @@
modifies sys.stdout|stderr|stdin attributes and does not
touch underlying File Descriptors (use StdCaptureFD for that).
"""
- def __init__(self, out=True, err=True, in_=True, mixed=False, now=True):
+ def __init__(self, out=True, err=True, in_=True):
self._oldout = sys.stdout
self._olderr = sys.stderr
self._oldin = sys.stdin
@@ -570,14 +543,10 @@
out = TextIO()
self.out = out
if err:
- if mixed:
- err = out
- elif not hasattr(err, 'write'):
+ if not hasattr(err, 'write'):
err = TextIO()
self.err = err
self.in_ = in_
- if now:
- self.startall()
def startall(self):
if self.out:
diff -r cd028703f029183cce422260040080920dabda63 -r
4f3a783d4b7afc276205d7dd3247ee91f8722a34 testing/test_capture.py
--- a/testing/test_capture.py
+++ b/testing/test_capture.py
@@ -661,21 +661,6 @@
class TestFDCapture:
pytestmark = needsosdup
- def test_not_now(self, tmpfile):
- fd = tmpfile.fileno()
- cap = capture.FDCapture(fd, now=False)
- data = tobytes("hello")
- os.write(fd, data)
- f = cap.done()
- s = f.read()
- assert not s
- cap = capture.FDCapture(fd, now=False)
- cap.start()
- os.write(fd, data)
- f = cap.done()
- s = f.read()
- assert s == "hello"
-
def test_simple(self, tmpfile):
fd = tmpfile.fileno()
cap = capture.FDCapture(fd)
@@ -683,8 +668,13 @@
os.write(fd, data)
f = cap.done()
s = f.read()
+ assert not s
+ cap = capture.FDCapture(fd)
+ cap.start()
+ os.write(fd, data)
+ f = cap.done()
+ s = f.read()
assert s == "hello"
- f.close()
def test_simple_many(self, tmpfile):
for i in range(10):
@@ -702,6 +692,7 @@
def test_stderr(self):
cap = capture.FDCapture(2, patchsys=True)
+ cap.start()
print_("hello", file=sys.stderr)
f = cap.done()
s = f.read()
@@ -711,6 +702,7 @@
tmpfile.write(tobytes("3"))
tmpfile.seek(0)
cap = capture.FDCapture(0, tmpfile=tmpfile)
+ cap.start()
# check with os.read() directly instead of raw_input(), because
# sys.stdin itself may be redirected (as pytest now does by default)
x = os.read(0, 100).strip()
@@ -721,6 +713,7 @@
data1, data2 = tobytes("foo"), tobytes("bar")
try:
cap = capture.FDCapture(tmpfile.fileno())
+ cap.start()
tmpfile.write(data1)
cap.writeorg(data2)
finally:
@@ -734,7 +727,9 @@
class TestStdCapture:
def getcapture(self, **kw):
- return capture.StdCapture(**kw)
+ cap = capture.StdCapture(**kw)
+ cap.startall()
+ return cap
def test_capturing_done_simple(self):
cap = self.getcapture()
@@ -785,15 +780,6 @@
out, err = cap.readouterr()
assert out == py.builtin._totext('\ufffd\n', 'unicode-escape')
- def test_capturing_mixed(self):
- cap = self.getcapture(mixed=True)
- sys.stdout.write("hello ")
- sys.stderr.write("world")
- sys.stdout.write(".")
- out, err = cap.reset()
- assert out.strip() == "hello world."
- assert not err
-
def test_reset_twice_error(self):
cap = self.getcapture()
print ("hello")
@@ -879,19 +865,13 @@
assert not err
-class TestStdCaptureNotNow(TestStdCapture):
- def getcapture(self, **kw):
- kw['now'] = False
- cap = capture.StdCapture(**kw)
- cap.startall()
- return cap
-
-
class TestStdCaptureFD(TestStdCapture):
pytestmark = needsosdup
def getcapture(self, **kw):
- return capture.StdCaptureFD(**kw)
+ cap = capture.StdCaptureFD(**kw)
+ cap.startall()
+ return cap
def test_intermingling(self):
cap = self.getcapture()
@@ -907,17 +887,6 @@
assert out == "123"
assert err == "abc"
- def test_callcapture(self):
- def func(x, y):
- print (x)
- sys.stderr.write(str(y))
- return 42
-
- res, out, err = capture.StdCaptureFD.call(func, 3, y=4)
- assert res == 42
- assert out.startswith("3")
- assert err.startswith("4")
-
def test_many(self, capfd):
def f():
for i in range(10):
@@ -926,15 +895,6 @@
lsof_check(f)
-class TestStdCaptureFDNotNow(TestStdCaptureFD):
- pytestmark = needsosdup
-
- def getcapture(self, **kw):
- kw['now'] = False
- cap = capture.StdCaptureFD(**kw)
- cap.startall()
- return cap
-
@needsosdup
def test_stdcapture_fd_tmpfile(tmpfile):
@@ -974,7 +934,7 @@
def test_capture_not_started_but_reset():
- capsys = capture.StdCapture(now=False)
+ capsys = capture.StdCapture()
capsys.done()
capsys.done()
capsys.reset()
@@ -985,6 +945,7 @@
capsys = capture.StdCapture()
try:
cap = capture.StdCaptureFD(patchsys=False)
+ cap.startall()
sys.stdout.write("hello")
sys.stderr.write("world")
oswritebytes(1, "1")
@@ -997,30 +958,11 @@
@needsosdup
-def test_callcapture_nofd():
- def func(x, y):
- oswritebytes(1, "hello")
- oswritebytes(2, "hello")
- print (x)
- sys.stderr.write(str(y))
- return 42
-
- capfd = capture.StdCaptureFD(patchsys=False)
- try:
- res, out, err = capture.StdCapture.call(func, 3, y=4)
- finally:
- capfd.reset()
- assert res == 42
- assert out.startswith("3")
- assert err.startswith("4")
-
-
-@needsosdup
@pytest.mark.parametrize('use', [True, False])
def test_fdcapture_tmpfile_remains_the_same(tmpfile, use):
if not use:
tmpfile = True
- cap = capture.StdCaptureFD(out=False, err=tmpfile, now=False)
+ cap = capture.StdCaptureFD(out=False, err=tmpfile)
try:
cap.startall()
capfile = cap.err.tmpfile
@@ -1042,6 +984,7 @@
import py, logging
from _pytest import capture
cap = capture.%s(out=False, in_=False)
+ cap.startall()
logging.warn("hello1")
outerr = cap.suspend()
Repository URL: https://bitbucket.org/hpk42/pytest/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
pytest-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-commit