remove unused "suspend/resume" on capturing, some formatting cleanup
This commit is contained in:
		
							parent
							
								
									7b63fa5966
								
							
						
					
					
						commit
						2263fcf6b7
					
				|  | @ -426,7 +426,7 @@ class StdCaptureBase(object): | ||||||
|         if hasattr(self, '_reset'): |         if hasattr(self, '_reset'): | ||||||
|             raise ValueError("was already reset") |             raise ValueError("was already reset") | ||||||
|         self._reset = True |         self._reset = True | ||||||
|         outfile, errfile = self.stop_capturing(save=False) |         outfile, errfile = self.stop_capturing() | ||||||
|         out, err = "", "" |         out, err = "", "" | ||||||
|         if outfile and not outfile.closed: |         if outfile and not outfile.closed: | ||||||
|             out = outfile.read() |             out = outfile.read() | ||||||
|  | @ -452,24 +452,9 @@ class StdCaptureFD(StdCaptureBase): | ||||||
|         is invalid it will not be captured. |         is invalid it will not be captured. | ||||||
|     """ |     """ | ||||||
|     def __init__(self, out=True, err=True, in_=True, patchsys=True): |     def __init__(self, out=True, err=True, in_=True, patchsys=True): | ||||||
|         self._options = { |  | ||||||
|             "out": out, |  | ||||||
|             "err": err, |  | ||||||
|             "in_": in_, |  | ||||||
|             "patchsys": patchsys, |  | ||||||
|         } |  | ||||||
|         self._save() |  | ||||||
| 
 |  | ||||||
|     def _save(self): |  | ||||||
|         in_ = self._options['in_'] |  | ||||||
|         out = self._options['out'] |  | ||||||
|         err = self._options['err'] |  | ||||||
|         patchsys = self._options['patchsys'] |  | ||||||
|         if in_: |         if in_: | ||||||
|             try: |             try: | ||||||
|                 self.in_ = FDCapture( |                 self.in_ = FDCapture(0, tmpfile=None, patchsys=patchsys) | ||||||
|                     0, tmpfile=None, |  | ||||||
|                     patchsys=patchsys) |  | ||||||
|             except OSError: |             except OSError: | ||||||
|                 pass |                 pass | ||||||
|         if out: |         if out: | ||||||
|  | @ -477,10 +462,7 @@ class StdCaptureFD(StdCaptureBase): | ||||||
|             if hasattr(out, 'write'): |             if hasattr(out, 'write'): | ||||||
|                 tmpfile = out |                 tmpfile = out | ||||||
|             try: |             try: | ||||||
|                 self.out = FDCapture( |                 self.out = FDCapture(1, tmpfile=tmpfile, patchsys=patchsys) | ||||||
|                     1, tmpfile=tmpfile, |  | ||||||
|                     patchsys=patchsys) |  | ||||||
|                 self._options['out'] = self.out.tmpfile |  | ||||||
|             except OSError: |             except OSError: | ||||||
|                 pass |                 pass | ||||||
|         if err: |         if err: | ||||||
|  | @ -489,10 +471,7 @@ class StdCaptureFD(StdCaptureBase): | ||||||
|             else: |             else: | ||||||
|                 tmpfile = None |                 tmpfile = None | ||||||
|             try: |             try: | ||||||
|                 self.err = FDCapture( |                 self.err = FDCapture(2, tmpfile=tmpfile, patchsys=patchsys) | ||||||
|                     2, tmpfile=tmpfile, |  | ||||||
|                     patchsys=patchsys) |  | ||||||
|                 self._options['err'] = self.err.tmpfile |  | ||||||
|             except OSError: |             except OSError: | ||||||
|                 pass |                 pass | ||||||
| 
 | 
 | ||||||
|  | @ -507,7 +486,7 @@ class StdCaptureFD(StdCaptureBase): | ||||||
|     #def pytest_sessionfinish(self): |     #def pytest_sessionfinish(self): | ||||||
|     #    self.reset_capturings() |     #    self.reset_capturings() | ||||||
| 
 | 
 | ||||||
|     def stop_capturing(self, save=True): |     def stop_capturing(self): | ||||||
|         """ return (outfile, errfile) and stop capturing. """ |         """ return (outfile, errfile) and stop capturing. """ | ||||||
|         outfile = errfile = None |         outfile = errfile = None | ||||||
|         if hasattr(self, 'out') and not self.out.tmpfile.closed: |         if hasattr(self, 'out') and not self.out.tmpfile.closed: | ||||||
|  | @ -516,8 +495,6 @@ class StdCaptureFD(StdCaptureBase): | ||||||
|             errfile = self.err.done() |             errfile = self.err.done() | ||||||
|         if hasattr(self, 'in_'): |         if hasattr(self, 'in_'): | ||||||
|             self.in_.done() |             self.in_.done() | ||||||
|         if save: |  | ||||||
|             self._save() |  | ||||||
|         return outfile, errfile |         return outfile, errfile | ||||||
| 
 | 
 | ||||||
|     def readouterr(self): |     def readouterr(self): | ||||||
|  | @ -577,7 +554,7 @@ class StdCapture(StdCaptureBase): | ||||||
|         if self.in_: |         if self.in_: | ||||||
|             sys.stdin = self.in_ = DontReadFromInput() |             sys.stdin = self.in_ = DontReadFromInput() | ||||||
| 
 | 
 | ||||||
|     def stop_capturing(self, save=True): |     def stop_capturing(self): | ||||||
|         """ return (outfile, errfile) and stop capturing. """ |         """ return (outfile, errfile) and stop capturing. """ | ||||||
|         outfile = errfile = None |         outfile = errfile = None | ||||||
|         if self.out and not self.out.closed: |         if self.out and not self.out.closed: | ||||||
|  |  | ||||||
|  | @ -873,25 +873,6 @@ class TestStdCapture: | ||||||
|         pytest.raises(IOError, "sys.stdin.read()") |         pytest.raises(IOError, "sys.stdin.read()") | ||||||
|         out, err = cap.reset() |         out, err = cap.reset() | ||||||
| 
 | 
 | ||||||
|     def test_suspend_resume(self): |  | ||||||
|         cap = self.getcapture(out=True, err=False, in_=False) |  | ||||||
|         try: |  | ||||||
|             print ("hello") |  | ||||||
|             sys.stderr.write("error\n") |  | ||||||
|             out, err = cap.readouterr() |  | ||||||
|             cap.stop_capturing() |  | ||||||
|             assert out == "hello\n" |  | ||||||
|             assert not err |  | ||||||
|             print ("in between") |  | ||||||
|             sys.stderr.write("in between\n") |  | ||||||
|             cap.start_capturing() |  | ||||||
|             print ("after") |  | ||||||
|             sys.stderr.write("error_after\n") |  | ||||||
|         finally: |  | ||||||
|             out, err = cap.reset() |  | ||||||
|         assert out == "after\n" |  | ||||||
|         assert not err |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| class TestStdCaptureFD(TestStdCapture): | class TestStdCaptureFD(TestStdCapture): | ||||||
|     pytestmark = needsosdup |     pytestmark = needsosdup | ||||||
|  | @ -925,12 +906,9 @@ class TestStdCaptureFD(TestStdCapture): | ||||||
| @needsosdup | @needsosdup | ||||||
| def test_stdcapture_fd_tmpfile(tmpfile): | def test_stdcapture_fd_tmpfile(tmpfile): | ||||||
|     capfd = capture.StdCaptureFD(out=tmpfile) |     capfd = capture.StdCaptureFD(out=tmpfile) | ||||||
|     try: |     os.write(1, "hello".encode("ascii")) | ||||||
|         os.write(1, "hello".encode("ascii")) |     os.write(2, "world".encode("ascii")) | ||||||
|         os.write(2, "world".encode("ascii")) |     outf, errf = capfd.stop_capturing() | ||||||
|         outf, errf = capfd.stop_capturing() |  | ||||||
|     finally: |  | ||||||
|         capfd.reset() |  | ||||||
|     assert outf == tmpfile |     assert outf == tmpfile | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue