diff --git a/Tests/modules/system_related/test_os.py b/Tests/modules/system_related/test_os.py index d27c6dece..1f77237d6 100644 --- a/Tests/modules/system_related/test_os.py +++ b/Tests/modules/system_related/test_os.py @@ -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) diff --git a/Tests/test_dict_stdlib.py b/Tests/test_dict_stdlib.py index d5bc81f13..46b1fdf94 100644 --- a/Tests/test_dict_stdlib.py +++ b/Tests/test_dict_stdlib.py @@ -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 diff --git a/Tests/test_file.py b/Tests/test_file.py index 964cf5498..4c44994af 100644 --- a/Tests/test_file.py +++ b/Tests/test_file.py @@ -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__) diff --git a/Tests/test_strformat.py b/Tests/test_strformat.py index e3f64f01e..1a7a4c5bd 100644 --- a/Tests/test_strformat.py +++ b/Tests/test_strformat.py @@ -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") @@ -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: @@ -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) @@ -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) @@ -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: