mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3723 from deantvv/io-buffered-args
io: enhance error message in Buffered* class
This commit is contained in:
6
Lib/test/test_io.py
vendored
6
Lib/test/test_io.py
vendored
@@ -1593,8 +1593,6 @@ class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
|
||||
support.gc_collect()
|
||||
self.assertIsNone(wr(), wr)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_args_error(self):
|
||||
# Issue #17275
|
||||
with self.assertRaisesRegex(TypeError, "BufferedReader"):
|
||||
@@ -1974,8 +1972,6 @@ class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
|
||||
with self.open(os_helper.TESTFN, "rb") as f:
|
||||
self.assertEqual(f.read(), b"123xxx")
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_args_error(self):
|
||||
# Issue #17275
|
||||
with self.assertRaisesRegex(TypeError, "BufferedWriter"):
|
||||
@@ -2460,8 +2456,6 @@ class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
|
||||
CBufferedReaderTest.test_garbage_collection(self)
|
||||
CBufferedWriterTest.test_garbage_collection(self)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_args_error(self):
|
||||
# Issue #17275
|
||||
with self.assertRaisesRegex(TypeError, "BufferedRandom"):
|
||||
|
||||
@@ -1367,6 +1367,7 @@ mod _io {
|
||||
|
||||
#[pyimpl]
|
||||
trait BufferedMixin: PyPayload {
|
||||
const CLASS_NAME: &'static str;
|
||||
const READABLE: bool;
|
||||
const WRITABLE: bool;
|
||||
const SEEKABLE: bool = false;
|
||||
@@ -1380,7 +1381,11 @@ mod _io {
|
||||
#[pyslot]
|
||||
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let zelf: PyRef<Self> = zelf.try_into_value(vm)?;
|
||||
let (raw, BufferSize { buffer_size }): (PyObjectRef, _) = args.bind(vm)?;
|
||||
let (raw, BufferSize { buffer_size }): (PyObjectRef, _) =
|
||||
args.bind(vm).map_err(|e| {
|
||||
let msg = format!("{}() {}", Self::CLASS_NAME, *e.str(vm));
|
||||
vm.new_exception_msg(e.class().clone(), msg)
|
||||
})?;
|
||||
zelf.init(raw, BufferSize { buffer_size }, vm)
|
||||
}
|
||||
|
||||
@@ -1663,6 +1668,7 @@ mod _io {
|
||||
data: PyThreadMutex<BufferedData>,
|
||||
}
|
||||
impl BufferedMixin for BufferedReader {
|
||||
const CLASS_NAME: &'static str = "BufferedReader";
|
||||
const READABLE: bool = true;
|
||||
const WRITABLE: bool = false;
|
||||
fn data(&self) -> &PyThreadMutex<BufferedData> {
|
||||
@@ -1712,6 +1718,7 @@ mod _io {
|
||||
data: PyThreadMutex<BufferedData>,
|
||||
}
|
||||
impl BufferedMixin for BufferedWriter {
|
||||
const CLASS_NAME: &'static str = "BufferedWriter";
|
||||
const READABLE: bool = false;
|
||||
const WRITABLE: bool = true;
|
||||
fn data(&self) -> &PyThreadMutex<BufferedData> {
|
||||
@@ -1740,6 +1747,7 @@ mod _io {
|
||||
data: PyThreadMutex<BufferedData>,
|
||||
}
|
||||
impl BufferedMixin for BufferedRandom {
|
||||
const CLASS_NAME: &'static str = "BufferedRandom";
|
||||
const READABLE: bool = true;
|
||||
const WRITABLE: bool = true;
|
||||
const SEEKABLE: bool = true;
|
||||
|
||||
Reference in New Issue
Block a user