Added file-like methods to DontReadFromInput (#10173)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com> Fixes #10150
This commit is contained in:
		
							parent
							
								
									b4ab2f0942
								
							
						
					
					
						commit
						1c31a7e659
					
				|  | @ -0,0 +1 @@ | |||
| :data:`sys.stdin` now contains all expected methods of a file-like object when capture is enabled. | ||||
|  | @ -203,12 +203,39 @@ class DontReadFromInput: | |||
|     def fileno(self) -> int: | ||||
|         raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()") | ||||
| 
 | ||||
|     def flush(self) -> None: | ||||
|         raise UnsupportedOperation("redirected stdin is pseudofile, has no flush()") | ||||
| 
 | ||||
|     def isatty(self) -> bool: | ||||
|         return False | ||||
| 
 | ||||
|     def close(self) -> None: | ||||
|         pass | ||||
| 
 | ||||
|     def readable(self) -> bool: | ||||
|         return False | ||||
| 
 | ||||
|     def seek(self, offset: int) -> int: | ||||
|         raise UnsupportedOperation("redirected stdin is pseudofile, has no seek(int)") | ||||
| 
 | ||||
|     def seekable(self) -> bool: | ||||
|         return False | ||||
| 
 | ||||
|     def tell(self) -> int: | ||||
|         raise UnsupportedOperation("redirected stdin is pseudofile, has no tell()") | ||||
| 
 | ||||
|     def truncate(self, size: int) -> None: | ||||
|         raise UnsupportedOperation("cannont truncate stdin") | ||||
| 
 | ||||
|     def write(self, *args) -> None: | ||||
|         raise UnsupportedOperation("cannot write to stdin") | ||||
| 
 | ||||
|     def writelines(self, *args) -> None: | ||||
|         raise UnsupportedOperation("Cannot write to stdin") | ||||
| 
 | ||||
|     def writable(self) -> bool: | ||||
|         return False | ||||
| 
 | ||||
|     @property | ||||
|     def buffer(self): | ||||
|         return self | ||||
|  |  | |||
|  | @ -897,6 +897,15 @@ def test_dontreadfrominput() -> None: | |||
|     iter_f = iter(f) | ||||
|     pytest.raises(OSError, next, iter_f) | ||||
|     pytest.raises(UnsupportedOperation, f.fileno) | ||||
|     pytest.raises(UnsupportedOperation, f.flush) | ||||
|     assert not f.readable() | ||||
|     pytest.raises(UnsupportedOperation, f.seek, 0) | ||||
|     assert not f.seekable() | ||||
|     pytest.raises(UnsupportedOperation, f.tell) | ||||
|     pytest.raises(UnsupportedOperation, f.truncate, 0) | ||||
|     pytest.raises(UnsupportedOperation, f.write, b"") | ||||
|     pytest.raises(UnsupportedOperation, f.writelines, []) | ||||
|     assert not f.writable() | ||||
|     f.close()  # just for completeness | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue