import locale
from test.support import (is_resource_enabled,
requires_IEEE_754, requires_docstrings,
- check_sanitizer,
check_disallow_instantiation)
from test.support import (TestFailed,
run_with_locale, cpython_only,
- darwin_malloc_err_warning, is_emscripten,
- skip_on_s390x)
+ darwin_malloc_err_warning)
from test.support.import_helper import import_fresh_module
from test.support import threading_helper
from test.support import warnings_helper
self.assertEqual(Decimal.from_float(cls(101.1)),
Decimal.from_float(101.1))
- # Issue 41540:
- @unittest.skipIf(sys.platform.startswith("aix"),
- "AIX: default ulimit: test is flaky because of extreme over-allocation")
- @unittest.skipIf(is_emscripten, "Test is unstable on Emscripten")
- @unittest.skipIf(check_sanitizer(address=True, memory=True),
- "ASAN/MSAN sanitizer defaults to crashing "
- "instead of returning NULL for malloc failure.")
- # gh-114331: The test allocates 784 271 641 GiB and mimalloc does not fail
- # to allocate it when using mimalloc on s390x.
- @skip_on_s390x
- def test_maxcontext_exact_arith(self):
-
- # Make sure that exact operations do not raise MemoryError due
- # to huge intermediate values when the context precision is very
- # large.
-
- # The following functions fill the available precision and are
- # therefore not suitable for large precisions (by design of the
- # specification).
- MaxContextSkip = ['logical_invert', 'next_minus', 'next_plus',
- 'logical_and', 'logical_or', 'logical_xor',
- 'next_toward', 'rotate', 'shift']
-
- Decimal = C.Decimal
- Context = C.Context
- localcontext = C.localcontext
-
- # Here only some functions that are likely candidates for triggering a
- # MemoryError are tested. deccheck.py has an exhaustive test.
- maxcontext = Context(prec=C.MAX_PREC, Emin=C.MIN_EMIN, Emax=C.MAX_EMAX)
- with localcontext(maxcontext):
- self.assertEqual(Decimal(0).exp(), 1)
- self.assertEqual(Decimal(1).ln(), 0)
- self.assertEqual(Decimal(1).log10(), 0)
- self.assertEqual(Decimal(10**2).log10(), 2)
- self.assertEqual(Decimal(10**223).log10(), 223)
- self.assertEqual(Decimal(10**19).logb(), 19)
- self.assertEqual(Decimal(4).sqrt(), 2)
- self.assertEqual(Decimal("40E9").sqrt(), Decimal('2.0E+5'))
- self.assertEqual(divmod(Decimal(10), 3), (3, 1))
- self.assertEqual(Decimal(10) // 3, 3)
- self.assertEqual(Decimal(4) / 2, 2)
- self.assertEqual(Decimal(400) ** -1, Decimal('0.0025'))
-
def test_c_immutable_types(self):
SignalDict = type(C.Context().flags)
SignalDictMixin = SignalDict.__bases__[0]
from test.support.script_helper import (
assert_python_ok, assert_python_failure, run_python_until_end)
from test.support import (
- import_helper, is_apple, os_helper, skip_if_sanitizer, threading_helper, warnings_helper,
- skip_on_s390x
+ import_helper, is_apple, os_helper, threading_helper, warnings_helper,
)
from test.support.os_helper import FakePath
class CBufferedReaderTest(BufferedReaderTest, SizeofTest):
tp = io.BufferedReader
- @skip_if_sanitizer(memory=True, address=True, thread=True,
- reason="sanitizer defaults to crashing "
- "instead of returning NULL for malloc failure.")
- # gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
- # (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
- @skip_on_s390x
- def test_constructor(self):
- BufferedReaderTest.test_constructor(self)
- # The allocation can succeed on 32-bit builds, e.g. with more
- # than 2 GiB RAM and a 64-bit kernel.
- if sys.maxsize > 0x7FFFFFFF:
- rawio = self.MockRawIO()
- bufio = self.tp(rawio)
- self.assertRaises((OverflowError, MemoryError, ValueError),
- bufio.__init__, rawio, sys.maxsize)
-
def test_initialization(self):
rawio = self.MockRawIO([b"abc"])
bufio = self.tp(rawio)
class CBufferedWriterTest(BufferedWriterTest, SizeofTest):
tp = io.BufferedWriter
- @skip_if_sanitizer(memory=True, address=True, thread=True,
- reason="sanitizer defaults to crashing "
- "instead of returning NULL for malloc failure.")
- # gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
- # (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
- @skip_on_s390x
- def test_constructor(self):
- BufferedWriterTest.test_constructor(self)
- # The allocation can succeed on 32-bit builds, e.g. with more
- # than 2 GiB RAM and a 64-bit kernel.
- if sys.maxsize > 0x7FFFFFFF:
- rawio = self.MockRawIO()
- bufio = self.tp(rawio)
- self.assertRaises((OverflowError, MemoryError, ValueError),
- bufio.__init__, rawio, sys.maxsize)
-
def test_initialization(self):
rawio = self.MockRawIO()
bufio = self.tp(rawio)
class CBufferedRandomTest(BufferedRandomTest, SizeofTest):
tp = io.BufferedRandom
- @skip_if_sanitizer(memory=True, address=True, thread=True,
- reason="sanitizer defaults to crashing "
- "instead of returning NULL for malloc failure.")
- # gh-117755: The test allocates 9 223 372 036 854 775 807 bytes
- # (0x7fffffffffffffff) and mimalloc fails with a division by zero on s390x.
- @skip_on_s390x
- def test_constructor(self):
- BufferedRandomTest.test_constructor(self)
- # The allocation can succeed on 32-bit builds, e.g. with more
- # than 2 GiB RAM and a 64-bit kernel.
- if sys.maxsize > 0x7FFFFFFF:
- rawio = self.MockRawIO()
- bufio = self.tp(rawio)
- self.assertRaises((OverflowError, MemoryError, ValueError),
- bufio.__init__, rawio, sys.maxsize)
-
def test_garbage_collection(self):
CBufferedReaderTest.test_garbage_collection(self)
CBufferedWriterTest.test_garbage_collection(self)