Skip to content

Commit

Permalink
Merge branch 'main' into 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier committed Dec 27, 2024
2 parents f610b3d + e160000 commit edd3504
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
16 changes: 9 additions & 7 deletions Tests/modules/system_related/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ def test_strerror(self):
elif is_osx:
self.assertEqual(os.strerror(40), "Message too long")


def test_open_abplus(self):
# equivalent to open(self.temp_file, "ab+"), see also test_file.test_open_abplus
fd = os.open(self.temp_file, os.O_APPEND | os.O_CREAT | os.O_RDWR)
try:
f = open(fd, mode="ab+", closefd=False)
f.write(b"abc")
f.seek(0)
self.assertEqual(f.read(2), b"ab")
f.write(b"def")
self.assertEqual(f.read(2), b"")
f.seek(0)
self.assertEqual(f.read(6), b"abcdef")
f.raw.write(b"abcxxxx")
f.raw.seek(0)
self.assertEqual(f.raw.read(2), b"ab")
f.raw.seek(0, 2)
f.raw.write(b"def")
self.assertEqual(f.raw.read(2), b"")
f.raw.seek(0)
self.assertEqual(f.raw.read(), b"abcxxxxdef")
f.close()
finally:
os.close(fd)
Expand Down
6 changes: 4 additions & 2 deletions Tests/test_dict_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ def load_tests(loader, standard_tests, pattern):
test.test_dict.DictTest('test_oob_indexing_dictiter_iternextitem'),
test.test_dict.DictTest('test_setdefault_atomic'),
]

skip_tests = []
if is_mono:
failing_tests += [
skip_tests += [
test.test_dict.DictTest('test_container_iterator'), # https://github.com/IronLanguages/ironpython3/issues/544
]

return generate_suite(tests, failing_tests)
return generate_suite(tests, failing_tests, skip_tests)

else:
return tests
Expand Down
15 changes: 8 additions & 7 deletions Tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,14 +845,15 @@ def test_open_wbplus(self):
f.seek(0)
self.assertEqual(f.read(), b"abdez")


def test_open_abplus(self):
with open(self.temp_file, "ab+") as f:
f.write(b"abc")
f.seek(0)
self.assertEqual(f.read(2), b"ab")
f.write(b"def")
self.assertEqual(f.read(2), b"")
f.seek(0)
self.assertEqual(f.read(6), b"abcdef")
f.raw.write(b"abc")
f.raw.seek(0)
self.assertEqual(f.raw.read(2), b"ab")
f.raw.write(b"def")
self.assertEqual(f.raw.read(2), b"")
f.raw.seek(0)
self.assertEqual(f.raw.read(6), b"abcdef")

run_test(__name__)
39 changes: 32 additions & 7 deletions Tests/test_strformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,27 @@ class bad2(object):
def __format__(self, *args):
return 42

self.assertRaisesMessage(TypeError, "bad.__format__ must return a str, not NoneType" if is_cli else "__format__ must return a str, not NoneType", '{0}'.format, bad())
self.assertRaisesMessage(TypeError, "bad2.__format__ must return a str, not int" if is_cli else "__format__ must return a str, not int", '{0}'.format, bad2())
if is_cli:
self.assertRaisesMessage(TypeError, "bad.__format__ must return a str, not NoneType", '{0}'.format, bad())
self.assertRaisesMessage(TypeError, "bad2.__format__ must return a str, not int", '{0}'.format, bad2())
elif sys.version_info >= (3, 5):
self.assertRaisesMessage(TypeError, "__format__ must return a str, not NoneType", '{0}'.format, bad())
self.assertRaisesMessage(TypeError, "__format__ must return a str, not int", '{0}'.format, bad2())
else:
self.assertRaisesMessage(TypeError, "__format__ method did not return string", '{0}'.format, bad())
self.assertRaisesMessage(TypeError, "__format__ method did not return string", '{0}'.format, bad2())

self.assertRaisesMessage(ValueError, "Unknown conversion specifier x", '{0!x}'.format, 'abc')

self.assertRaisesMessage(TypeError, "bad.__format__ must return a str, not NoneType" if is_cli else "__format__ must return a str, not NoneType", format, bad())
self.assertRaisesMessage(TypeError, "bad2.__format__ must return a str, not int" if is_cli else "__format__ must return a str, not int", format, bad2())
if is_cli:
self.assertRaisesMessage(TypeError, "bad.__format__ must return a str, not NoneType", format, bad())
self.assertRaisesMessage(TypeError, "bad2.__format__ must return a str, not int", format, bad2())
elif sys.version_info >= (3, 5):
self.assertRaisesMessage(TypeError, "__format__ must return a str, not NoneType", format, bad())
self.assertRaisesMessage(TypeError, "__format__ must return a str, not int", format, bad2())
else:
self.assertRaisesMessage(TypeError, "__format__ method did not return string", format, bad())
self.assertRaisesMessage(TypeError, "__format__ method did not return string", format, bad2())

def test_object__format__(self):
self.assertEqual(object.__format__("aaa", ""), "aaa")
Expand Down Expand Up @@ -281,7 +295,10 @@ def test_str___format___errors(self):
if char == ',':
errors.append(('10' + char, "Cannot specify ',' with 's'."))
elif char == '_':
errors.append(('10' + char, "Cannot specify '_' with 's'."))
if is_cli or sys.version_info >= (3, 6):
errors.append(('10' + char, "Cannot specify '_' with 's'."))
else:
errors.append(('10' + char, "Unknown format code '_' for object of type 'str'"))
elif 0x20 < x < 0x80:
errors.append(('10' + char, "Unknown format code '%s' for object of type 'str'" % char))
else:
Expand Down Expand Up @@ -570,7 +587,10 @@ def test_float___format__(self):
def test_float___format___errors(self):
errors = []

okChars = set(['\0', '%', 'E', 'F', 'G', 'e', 'f', 'g', 'n', ',', '_'] + [chr(x) for x in range(ord('0'), ord('9') + 1)])
okChars = set(['\0', '%', 'E', 'F', 'G', 'e', 'f', 'g', 'n', ','] + [chr(x) for x in range(ord('0'), ord('9') + 1)])
if is_cli or sys.version_info >= (3, 6):
okChars.add('_')

# verify the okChars are actually ok
for char in okChars:
2.0.__format__('10' + char)
Expand Down Expand Up @@ -911,6 +931,9 @@ def test_int___format__(self):
]

for value, spec, result in tests_thousands:
if not is_cli and sys.version_info < (3, 6) and "_" in spec:
continue

assert "d" not in spec
self.assertEqual(value.__format__(spec), result)
self.assertEqual(big(value).__format__(spec), result)
Expand Down Expand Up @@ -965,7 +988,9 @@ def test_int___format___errors(self):
else:
errors.append((OverflowError, sys.maxsize + 1, 'c', "Python int too large to convert to C long"))

okChars = set(['%', 'E', 'F', 'G', 'X', 'x', 'b', 'c', 'd', 'o', 'e', 'f', 'g', 'n', ',', '_'] + [chr(x) for x in range(ord('0'), ord('9') + 1)])
okChars = set(['%', 'E', 'F', 'G', 'X', 'x', 'b', 'c', 'd', 'o', 'e', 'f', 'g', 'n', ','] + [chr(x) for x in range(ord('0'), ord('9') + 1)])
if is_cli or sys.version_info >= (3, 6):
okChars.add('_')

# verify the okChars are actually ok
for char in okChars:
Expand Down

0 comments on commit edd3504

Please sign in to comment.