Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 48 additions & 51 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1818,10 +1818,6 @@ def test_garbage_collection(self):
support.gc_collect()
self.assertIsNone(wr(), wr)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_error_through_destructor(self):
return super().test_error_through_destructor()

def test_args_error(self):
# Issue #17275
with self.assertRaisesRegex(TypeError, "BufferedReader"):
Expand All @@ -1844,12 +1840,8 @@ def test_bad_readinto_type(self):
self.assertIsInstance(cm.exception.__cause__, TypeError)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_flush_error_on_close(self):
return super().test_flush_error_on_close()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_seek_character_device_file(self):
return super().test_seek_character_device_file()
def test_error_through_destructor(self):
return super().test_error_through_destructor()

def test_truncate_on_read_only(self):
return super().test_truncate_on_read_only()
Expand Down Expand Up @@ -2166,10 +2158,6 @@ def test_slow_close_from_thread(self):
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
tp = io.BufferedWriter

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_error_through_destructor(self):
return super().test_error_through_destructor()

def test_initialization(self):
rawio = self.MockRawIO()
bufio = self.tp(rawio)
Expand Down Expand Up @@ -2205,8 +2193,8 @@ def test_args_error(self):
self.tp(self.BytesIO(), 1024, 1024, 1024)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_flush_error_on_close(self):
return super().test_flush_error_on_close()
def test_error_through_destructor(self):
return super().test_error_through_destructor()

@unittest.skip('TODO: RUSTPYTHON; fallible allocation')
def test_constructor(self):
Expand Down Expand Up @@ -2692,10 +2680,6 @@ def test_interleaved_readline_write(self):
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
tp = io.BufferedRandom

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_error_through_destructor(self):
return super().test_error_through_destructor()

@unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON; cyclic GC not supported, causes file locking')
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_garbage_collection(self):
Expand All @@ -2708,16 +2692,8 @@ def test_args_error(self):
self.tp(self.BytesIO(), 1024, 1024, 1024)

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_flush_error_on_close(self):
return super().test_flush_error_on_close()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_seek_character_device_file(self):
return super().test_seek_character_device_file()

@unittest.expectedFailure # TODO: RUSTPYTHON; f.read1(1) returns b'a'
def test_read1_after_write(self):
return super().test_read1_after_write()
def test_error_through_destructor(self):
return super().test_error_through_destructor()

@unittest.skip('TODO: RUSTPYTHON; fallible allocation')
def test_constructor(self):
Expand Down Expand Up @@ -3395,7 +3371,24 @@ def test_multibyte_seek_and_tell(self):
self.assertEqual(f.tell(), p1)
f.close()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_tell_after_readline_with_cr(self):
# Test for gh-141314: TextIOWrapper.tell() assertion failure
# when dealing with standalone carriage returns
data = b'line1\r'
with self.open(os_helper.TESTFN, "wb") as f:
f.write(data)

with self.open(os_helper.TESTFN, "r") as f:
# Read line that ends with \r
line = f.readline()
self.assertEqual(line, "line1\n")
# This should not cause an assertion failure
pos = f.tell()
# Verify we can seek back to this position
f.seek(pos)
remaining = f.read()
self.assertEqual(remaining, "")

def test_seek_with_encoder_state(self):
f = self.open(os_helper.TESTFN, "w", encoding="euc_jis_2004")
f.write("\u00e6\u0300")
Expand Down Expand Up @@ -4130,10 +4123,6 @@ class CTextIOWrapperTest(TextIOWrapperTest):
io = io
shutdown_error = "LookupError: unknown encoding: ascii"

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_error_through_destructor(self):
return super().test_error_through_destructor()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_initialization(self):
r = self.BytesIO(b"\xc3\xa9\n\n")
Expand Down Expand Up @@ -4291,6 +4280,10 @@ def test_reconfigure_write_fromascii(self):
def test_reconfigure_write_through(self):
return super().test_reconfigure_write_through()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_error_through_destructor(self):
return super().test_error_through_destructor()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_repr(self):
return super().test_repr()
Expand All @@ -4306,6 +4299,11 @@ def test_recursive_repr(self):
def test_pickling_subclass(self):
return super().test_pickling_subclass()

# TODO: RUSTPYTHON; euc_jis_2004 encoding not supported
@unittest.expectedFailure
def test_seek_with_encoder_state(self):
return super().test_seek_with_encoder_state()


class PyTextIOWrapperTest(TextIOWrapperTest):
io = pyio
Expand All @@ -4319,6 +4317,11 @@ def test_constructor(self):
def test_newlines(self):
return super().test_newlines()

# TODO: RUSTPYTHON; euc_jis_2004 encoding not supported
@unittest.expectedFailure
def test_seek_with_encoder_state(self):
return super().test_seek_with_encoder_state()


class IncrementalNewlineDecoderTest(unittest.TestCase):

Expand Down Expand Up @@ -4836,22 +4839,6 @@ class CMiscIOTest(MiscIOTest):
name_of_module = "io", "_io"
extra_exported = "BlockingIOError",

@unittest.expectedFailure # TODO: RUSTPYTHON; BufferedWriter seeks on non-seekable pipe
def test_nonblock_pipe_write_bigbuf(self):
return super().test_nonblock_pipe_write_bigbuf()

@unittest.expectedFailure # TODO: RUSTPYTHON; BufferedWriter seeks on non-seekable pipe
def test_nonblock_pipe_write_smallbuf(self):
return super().test_nonblock_pipe_write_smallbuf()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_warn_on_dealloc(self):
return super().test_warn_on_dealloc()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_warn_on_dealloc_fd(self):
return super().test_warn_on_dealloc_fd()

def test_readinto_buffer_overflow(self):
# Issue #18025
class BadReader(self.io.BufferedIOBase):
Expand Down Expand Up @@ -4916,6 +4903,16 @@ def test_daemon_threads_shutdown_stderr_deadlock(self):
def test_check_encoding_errors(self):
return super().test_check_encoding_errors()

# TODO: RUSTPYTHON; ResourceWarning not triggered by _io.FileIO
@unittest.expectedFailure
def test_warn_on_dealloc(self):
return super().test_warn_on_dealloc()

# TODO: RUSTPYTHON; ResourceWarning not triggered by _io.FileIO
@unittest.expectedFailure
def test_warn_on_dealloc_fd(self):
return super().test_warn_on_dealloc_fd()


class PyMiscIOTest(MiscIOTest):
io = pyio
Expand Down
47 changes: 40 additions & 7 deletions crates/derive-impl/src/pystructseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,53 @@ pub(crate) fn impl_pystruct_sequence_data(

// Generate try_from_elements trait override only when try_from_object=true
let try_from_elements_trait_override = if try_from_object {
let visible_field_idents: Vec<_> = visible_fields.iter().map(|f| &f.ident).collect();
let skipped_field_idents: Vec<_> = skipped_fields.iter().map(|f| &f.ident).collect();
let visible_field_inits: Vec<_> = visible_fields
.iter()
.map(|f| {
let ident = &f.ident;
let cfg_attrs = &f.cfg_attrs;
if cfg_attrs.is_empty() {
quote! { #ident: iter.next().unwrap().clone().try_into_value(vm)?, }
} else {
quote! {
#(#cfg_attrs)*
#ident: iter.next().unwrap().clone().try_into_value(vm)?,
}
}
})
.collect();
let skipped_field_inits: Vec<_> = skipped_fields
.iter()
.map(|f| {
let ident = &f.ident;
let cfg_attrs = &f.cfg_attrs;
if cfg_attrs.is_empty() {
quote! {
#ident: match iter.next() {
Some(v) => v.clone().try_into_value(vm)?,
None => vm.ctx.none(),
},
}
} else {
quote! {
#(#cfg_attrs)*
#ident: match iter.next() {
Some(v) => v.clone().try_into_value(vm)?,
None => vm.ctx.none(),
},
}
}
})
.collect();
quote! {
fn try_from_elements(
elements: Vec<::rustpython_vm::PyObjectRef>,
vm: &::rustpython_vm::VirtualMachine,
) -> ::rustpython_vm::PyResult<Self> {
let mut iter = elements.into_iter();
Ok(Self {
#(#visible_field_idents: iter.next().unwrap().clone().try_into_value(vm)?,)*
#(#skipped_field_idents: match iter.next() {
Some(v) => v.clone().try_into_value(vm)?,
None => vm.ctx.none(),
},)*
#(#visible_field_inits)*
#(#skipped_field_inits)*
})
}
}
Expand Down
Loading
Loading