From d6e8d99a0747ff3428356278a34501402959697e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sun, 1 Dec 2024 21:19:28 -0500 Subject: [PATCH 1/2] Fix issues after merge --- Src/IronPython.Modules/_operator.cs | 12 ++-- .../Cases/CPythonCasesManifest.ini | 3 - Tests/test_base64_stdlib.py | 28 -------- Tests/test_io_stdlib.py | 64 +++++++++++++++---- 4 files changed, 58 insertions(+), 49 deletions(-) delete mode 100644 Tests/test_base64_stdlib.py diff --git a/Src/IronPython.Modules/_operator.cs b/Src/IronPython.Modules/_operator.cs index 7dd04872a..c10432010 100644 --- a/Src/IronPython.Modules/_operator.cs +++ b/Src/IronPython.Modules/_operator.cs @@ -23,6 +23,7 @@ namespace IronPython.Modules { public static class PythonOperator { public const string __doc__ = "Provides programmatic access to various operators (addition, accessing members, etc...)"; + [PythonType] public sealed class attrgetter : ICodeFormattable { private readonly object[] _names; @@ -40,31 +41,32 @@ public attrgetter([NotNone] params object[] attrs) { public PythonTuple __reduce__() => PythonTuple.MakeTuple(DynamicHelpers.GetPythonType(this), PythonTuple.MakeTuple(_names)); [SpecialName] - public object Call(CodeContext context, object param) { + public object? Call(CodeContext context, object? param) { if (_names.Length == 1) { return GetOneAttr(context, param, _names[0]); } - object[] res = new object[_names.Length]; + object?[] res = new object[_names.Length]; for (int i = 0; i < _names.Length; i++) { res[i] = GetOneAttr(context, param, _names[i]); } return PythonTuple.MakeTuple(res); } - private static object GetOneAttr(CodeContext context, object param, object val) { + private static object? GetOneAttr(CodeContext context, object? param, object val) { if (val is not string s) { throw PythonOps.TypeError("attribute name must be string"); } int dotPos = s.IndexOf('.'); if (dotPos >= 0) { - object nextParam = GetOneAttr(context, param, s.Substring(0, dotPos)); + object? nextParam = GetOneAttr(context, param, s.Substring(0, dotPos)); return GetOneAttr(context, nextParam, s.Substring(dotPos + 1)); } return PythonOps.GetBoundAttr(context, param, s); } } + [PythonType] public sealed class itemgetter : ICodeFormattable { private readonly object?[] _items; @@ -82,7 +84,7 @@ public itemgetter([NotNone] params object?[] items) { public PythonTuple __reduce__() => PythonTuple.MakeTuple(DynamicHelpers.GetPythonType(this), PythonTuple.MakeTuple(_items)); [SpecialName] - public object Call(CodeContext/*!*/ context, object param) { + public object? Call(CodeContext/*!*/ context, object? param) { if (_items.Length == 1) { return PythonOps.GetIndex(context, param, _items[0]); } diff --git a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini index 9f8df720f..4c43cf1a4 100644 --- a/Src/IronPythonTest/Cases/CPythonCasesManifest.ini +++ b/Src/IronPythonTest/Cases/CPythonCasesManifest.ini @@ -181,9 +181,6 @@ Ignore=true Ignore=true Reason=ImportError: No module named audioop -[CPython.test_base64] # IronPython.test_base64_stdlib -Ignore=true - [CPython.test_bdb] # new in 3.6 Ignore=true diff --git a/Tests/test_base64_stdlib.py b/Tests/test_base64_stdlib.py deleted file mode 100644 index 708dd0a5b..000000000 --- a/Tests/test_base64_stdlib.py +++ /dev/null @@ -1,28 +0,0 @@ -# Licensed to the .NET Foundation under one or more agreements. -# The .NET Foundation licenses this file to you under the Apache 2.0 License. -# See the LICENSE file in the project root for more information. - -## -## Run selected tests from test_base64 from StdLib -## - -from iptest import is_ironpython, generate_suite, run_test, is_posix - -import test.test_base64 - -def load_tests(loader, standard_tests, pattern): - tests = loader.loadTestsFromModule(test.test_base64, pattern=pattern) - - if is_ironpython: - failing_tests = [] - if not is_posix: - failing_tests += [ - test.test_base64.TestMain('test_encode_from_stdin'), # https://github.com/IronLanguages/ironpython3/issues/1135 - ] - - return generate_suite(tests, failing_tests) - - else: - return tests - -run_test(__name__) diff --git a/Tests/test_io_stdlib.py b/Tests/test_io_stdlib.py index f3e66d691..a404aa65a 100644 --- a/Tests/test_io_stdlib.py +++ b/Tests/test_io_stdlib.py @@ -22,21 +22,13 @@ def load_tests(loader, standard_tests, pattern): test.test_io.CIOTest('test_TextIOBase_destructor'), # AssertionError: Lists differ: [1, 2, 3, 2] != [1, 2, 3] test.test_io.CIOTest('test_destructor'), # AssertionError: Lists differ: [2, 3, 1, 2] != [1, 2, 3] test.test_io.CIOTest('test_flush_error_on_close'), # AssertionError: OSError not raised by close - test.test_io.CIOTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning test.test_io.CIOTest('test_invalid_operations'), # OSError: can't do nonzero cur-relative seeks - test.test_io.CIOTest('test_open_handles_NUL_chars'), # ValueError: Illegal characters in path. - test.test_io.PyIOTest('test_destructor'), # AssertionError: Lists differ: [2, 3, 1, 2] != [1, 2, 3] - test.test_io.PyIOTest('test_flush_error_on_close'), # AssertionError: OSError not raised by close - test.test_io.PyIOTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning - test.test_io.PyIOTest('test_open_handles_NUL_chars'), # ValueError: Illegal characters in path. test.test_io.CBufferedReaderTest('test_args_error'), # AssertionError: "BufferedReader" does not match "__init__() takes at most 2 arguments (4 given)" test.test_io.CBufferedReaderTest('test_buffering'), # TypeError: BufferedReader() takes at least 0 arguments (2 given) test.test_io.CBufferedReaderTest('test_close_error_on_close'), # AssertionError: None is not an instance of - test.test_io.CBufferedReaderTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning test.test_io.CBufferedReaderTest('test_initialization'), # AssertionError: ValueError not raised by read test.test_io.CBufferedReaderTest('test_misbehaved_io_read'), # AssertionError: OSError not raised by read test.test_io.CBufferedReaderTest('test_nonnormalized_close_error_on_close'), # AssertionError: None is not an instance of - test.test_io.CBufferedReaderTest('test_override_destructor'), # AssertionError: Lists differ: [1, 2, 3, 2] != [1, 2, 3] test.test_io.CBufferedReaderTest('test_read_non_blocking'), # AssertionError: b'' is not None test.test_io.CBufferedReaderTest('test_read_on_closed'), # AssertionError: ValueError not raised by read1 test.test_io.CBufferedReaderTest('test_readonly_attributes'), # AssertionError: AttributeError not raised @@ -44,7 +36,6 @@ def load_tests(loader, standard_tests, pattern): test.test_io.PyBufferedReaderTest('test_nonnormalized_close_error_on_close'), # AssertionError: None is not an instance of test.test_io.PyBufferedReaderTest('test_read_on_closed'), # AssertionError: ValueError not raised by read1 test.test_io.CBufferedWriterTest('test_close_error_on_close'), # AssertionError: None is not an instance of - test.test_io.CBufferedWriterTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning test.test_io.CBufferedWriterTest('test_initialization'), # AssertionError: ValueError not raised by write test.test_io.CBufferedWriterTest('test_max_buffer_size_removal'), # AssertionError: TypeError not raised test.test_io.CBufferedWriterTest('test_nonnormalized_close_error_on_close'), # AssertionError: None is not an instance of @@ -58,7 +49,6 @@ def load_tests(loader, standard_tests, pattern): test.test_io.CBufferedRWPairTest('test_uninitialized'), # TypeError: BufferedRWPair() takes at least 2 arguments (0 given) test.test_io.PyBufferedRWPairTest('test_reader_writer_close_error_on_close'), # AssertionError: None is not an instance of test.test_io.CBufferedRandomTest('test_close_error_on_close'), # AssertionError: None is not an instance of - test.test_io.CBufferedRandomTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning test.test_io.CBufferedRandomTest('test_max_buffer_size_removal'), # AssertionError: TypeError not raised test.test_io.CBufferedRandomTest('test_nonnormalized_close_error_on_close'), # AssertionError: None is not an instance of test.test_io.CBufferedRandomTest('test_read_non_blocking'), # AssertionError: b'' is not None @@ -74,7 +64,6 @@ def load_tests(loader, standard_tests, pattern): test.test_io.CTextIOWrapperTest('test_close_error_on_close'), # AssertionError: OSError not raised test.test_io.CTextIOWrapperTest('test_encoded_writes'), # UnicodeEncodeError test.test_io.CTextIOWrapperTest('test_flush_error_on_close'), # AssertionError: OSError not raised by close - test.test_io.CTextIOWrapperTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning test.test_io.CTextIOWrapperTest('test_initialization'), # AssertionError: ValueError not raised by read test.test_io.CTextIOWrapperTest('test_non_text_encoding_codecs_are_rejected'), # AssertionError: LookupError not raised test.test_io.CTextIOWrapperTest('test_nonnormalized_close_error_on_close'), # AssertionError: NameError not raised @@ -93,12 +82,41 @@ def load_tests(loader, standard_tests, pattern): test.test_io.CMiscIOTest('test_readinto_buffer_overflow'), # IndexError: Index was outside the bounds of the array. test.test_io.CMiscIOTest('test_warn_on_dealloc'), # AssertionError: ResourceWarning not triggered test.test_io.CMiscIOTest('test_warn_on_dealloc_fd'), # AssertionError: ResourceWarning not triggered - test.test_io.PyMiscIOTest('test_io_after_close'), # AttributeError: 'FileIO' object has no attribute 'read1' test.test_io.PyMiscIOTest('test_nonblock_pipe_write_bigbuf'), # AttributeError: 'module' object has no attribute 'fcntl' test.test_io.PyMiscIOTest('test_nonblock_pipe_write_smallbuf'), # AttributeError: 'module' object has no attribute 'fcntl' - test.test_io.PyMiscIOTest('test_pickling'), # AssertionError: TypeError not raised by _dumps test.test_io.PyMiscIOTest('test_warn_on_dealloc'), # AssertionError: ResourceWarning not triggered test.test_io.PyMiscIOTest('test_warn_on_dealloc_fd'), # AssertionError: ResourceWarning not triggered + + # BufferError: memoryview: invalid buffer exported from object of type EmptyStruct + test.test_io.CIOTest('test_buffered_file_io'), + test.test_io.CIOTest('test_raw_bytes_io'), + test.test_io.CIOTest('test_raw_file_io'), + test.test_io.PyIOTest('test_buffered_file_io'), + test.test_io.PyIOTest('test_raw_bytes_io'), + test.test_io.PyIOTest('test_raw_file_io'), + test.test_io.CBufferedRWPairTest('test_readinto'), + test.test_io.PyBufferedRWPairTest('test_readinto'), + + # TODO: these are new in 3.6 + test.test_io.CIOTest('test_BufferedIOBase_readinto'), + test.test_io.CIOTest('test_buffered_readinto_mixin'), + test.test_io.CIOTest('test_next_nonsizeable'), + test.test_io.CIOTest('test_optional_abilities'), + test.test_io.PyIOTest('test_buffered_readinto_mixin'), + test.test_io.PyIOTest('test_optional_abilities'), + test.test_io.APIMismatchTest('test_RawIOBase_io_in_pyio_match'), + test.test_io.APIMismatchTest('test_RawIOBase_pyio_in_io_match'), + test.test_io.CBufferedReaderTest('test_readinto1'), + test.test_io.CBufferedReaderTest('test_readinto1_array'), + test.test_io.CBufferedReaderTest('test_readinto_array'), + test.test_io.CBufferedRandomTest('test_readinto1'), + test.test_io.CBufferedRandomTest('test_readinto1_array'), + test.test_io.CBufferedRandomTest('test_readinto_array'), + test.test_io.CTextIOWrapperTest('test_illegal_encoder'), + test.test_io.CTextIOWrapperTest('test_issue25862'), + test.test_io.CTextIOWrapperTest('test_read_byteslike'), + test.test_io.PyTextIOWrapperTest('test_illegal_encoder'), + test.test_io.PyTextIOWrapperTest('test_read_byteslike'), ] if is_mono: @@ -107,11 +125,31 @@ def load_tests(loader, standard_tests, pattern): ] skip_tests = [ + test.test_io.CBufferedReaderTest('test_override_destructor'), # StackOverflowException test.test_io.CBufferedWriterTest('test_override_destructor'), # StackOverflowException test.test_io.CBufferedRandomTest('test_override_destructor'), # StackOverflowException test.test_io.CTextIOWrapperTest('test_bufio_write_through'), # StackOverflowException test.test_io.CTextIOWrapperTest('test_override_destructor'), # StackOverflowException + # failure prevents files from closing + test.test_io.CIOTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning + test.test_io.PyIOTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning + test.test_io.CBufferedReaderTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning + test.test_io.CBufferedWriterTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning + test.test_io.CBufferedRandomTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning + test.test_io.CTextIOWrapperTest('test_garbage_collection'), # AssertionError: filter ('', ResourceWarning) did not catch any warning + test.test_io.PyIOTest('test_destructor'), # AssertionError: Lists differ: [2, 3, 1, 2] != [1, 2, 3] + + # StackOverflowException + test.test_io.CBufferedReaderTest('test_recursive_repr'), + test.test_io.PyBufferedReaderTest('test_recursive_repr'), + test.test_io.CBufferedWriterTest('test_recursive_repr'), + test.test_io.PyBufferedWriterTest('test_recursive_repr'), + test.test_io.CBufferedRandomTest('test_recursive_repr'), + test.test_io.PyBufferedRandomTest('test_recursive_repr'), + test.test_io.CTextIOWrapperTest('test_recursive_repr'), + test.test_io.PyTextIOWrapperTest('test_recursive_repr'), + # __del__ not getting called on shutdown? test.test_io.CTextIOWrapperTest('test_create_at_shutdown_with_encoding'), test.test_io.CTextIOWrapperTest('test_create_at_shutdown_without_encoding'), From 84abc6617682ca0152c91e68834b00f6695a7694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Mon, 2 Dec 2024 09:28:21 -0500 Subject: [PATCH 2/2] Disable test on Mono --- Tests/test_io_stdlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_io_stdlib.py b/Tests/test_io_stdlib.py index a404aa65a..66a2e0d52 100644 --- a/Tests/test_io_stdlib.py +++ b/Tests/test_io_stdlib.py @@ -121,7 +121,7 @@ def load_tests(loader, standard_tests, pattern): if is_mono: failing_tests += [ - test.test_io.CBufferedRandomTest('test_destructor'), # IndexError: index out of range: 0 + test.test_io.PyMiscIOTest('test_create_fail'), ] skip_tests = [