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
884 changes: 682 additions & 202 deletions Lib/test/test_call.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions Lib/test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,9 @@ def testIteration(self):
class COtherFileTests(OtherFileTests, unittest.TestCase):
open = io.open

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

class PyOtherFileTests(OtherFileTests, unittest.TestCase):
open = staticmethod(pyio.open)
Expand Down
18 changes: 16 additions & 2 deletions Lib/test/test_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ def test_class_cause(self):
else:
self.fail("No exception raised")

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: 'classmethod' object is not callable
def test_class_cause_nonexception_result(self):
class ConstructsNone(BaseException):
@classmethod
def __new__(*args, **kwargs):
return None
try:
raise IndexError from ConstructsNone
except TypeError as e:
self.assertIn("should have returned an instance of BaseException", str(e))
except IndexError:
self.fail("Wrong kind of exception raised")
else:
self.fail("No exception raised")

def test_instance_cause(self):
cause = KeyError()
try:
Expand Down Expand Up @@ -233,8 +248,7 @@ class TestTracebackType(unittest.TestCase):
def raiser(self):
raise ValueError

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_attrs(self):
try:
self.raiser()
Expand Down
80 changes: 76 additions & 4 deletions Lib/test/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,57 @@ def bar():
self.assertEqual(foo(a=42), 50)
self.assertEqual(foo(), 25)

def testCellIsArgAndEscapes(self):
# We need to be sure that a cell passed in as an arg still
# gets wrapped in a new cell if the arg escapes into an
# inner function (closure).

def external():
value = 42
def inner():
return value
cell, = inner.__closure__
return cell
cell_ext = external()

def spam(arg):
def eggs():
return arg
return eggs

eggs = spam(cell_ext)
cell_closure, = eggs.__closure__
cell_eggs = eggs()

self.assertIs(cell_eggs, cell_ext)
self.assertIsNot(cell_eggs, cell_closure)

def testCellIsLocalAndEscapes(self):
# We need to be sure that a cell bound to a local still
# gets wrapped in a new cell if the local escapes into an
# inner function (closure).

def external():
value = 42
def inner():
return value
cell, = inner.__closure__
return cell
cell_ext = external()

def spam(arg):
cell = arg
def eggs():
return cell
return eggs

eggs = spam(cell_ext)
cell_closure, = eggs.__closure__
cell_eggs = eggs()

self.assertIs(cell_eggs, cell_ext)
self.assertIsNot(cell_eggs, cell_closure)

def testRecursion(self):

def f(x):
Expand Down Expand Up @@ -641,10 +692,7 @@ def dec(self):
self.assertEqual(c.dec(), 1)
self.assertEqual(c.dec(), 0)

# TODO: RUSTPYTHON, figure out how to communicate that `y = 9` should be
# stored as a global rather than a STORE_NAME, even when
# the `global y` is in a nested subscope
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON; figure out how to communicate that `y = 9` should be stored as a global rather than a STORE_NAME, even when the `global y` is in a nested subscope
def testGlobalInParallelNestedFunctions(self):
# A symbol table bug leaked the global statement from one
# function to other nested functions in the same block.
Expand Down Expand Up @@ -763,6 +811,30 @@ def dig(self):
gc_collect() # For PyPy or other GCs.
self.assertIsNone(ref())

def test_multiple_nesting(self):
# Regression test for https://github.com/python/cpython/issues/121863
class MultiplyNested:
def f1(self):
__arg = 1
class D:
def g(self, __arg):
return __arg
return D().g(_MultiplyNested__arg=2)

def f2(self):
__arg = 1
class D:
def g(self, __arg):
return __arg
return D().g

inst = MultiplyNested()
with self.assertRaises(TypeError):
inst.f1()

closure = inst.f2()
with self.assertRaises(TypeError):
closure(_MultiplyNested__arg=2)

if __name__ == '__main__':
unittest.main()
3 changes: 1 addition & 2 deletions Lib/test/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ def test_deepcopy(self):
self.assertIsNot(s.stop, c.stop)
self.assertIsNot(s.step, c.step)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_cycle(self):
class myobj(): pass
o = myobj()
Expand Down
15 changes: 5 additions & 10 deletions Lib/test/test_string_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def test_eval_str_incomplete(self):
self.assertRaises(SyntaxError, eval, r""" '\U000000' """)
self.assertRaises(SyntaxError, eval, r""" '\U0000000' """)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_eval_str_invalid_escape(self):
for b in range(1, 128):
if b in b"""\n\r"'01234567NU\\abfnrtuvx""":
Expand Down Expand Up @@ -145,8 +144,7 @@ def test_eval_str_invalid_escape(self):
self.assertRegex(str(w[0].message), 'invalid escape sequence')
self.assertEqual(w[0].filename, '<string>')

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_eval_str_invalid_octal_escape(self):
for i in range(0o400, 0o1000):
with self.assertWarns(SyntaxWarning):
Expand All @@ -172,8 +170,7 @@ def test_eval_str_invalid_octal_escape(self):
self.assertEqual(exc.lineno, 2)
self.assertEqual(exc.offset, 1)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_invalid_escape_locations_with_offset(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('error', category=SyntaxWarning)
Expand Down Expand Up @@ -223,8 +220,7 @@ def test_eval_bytes_incomplete(self):
self.assertRaises(SyntaxError, eval, r""" b'\x' """)
self.assertRaises(SyntaxError, eval, r""" b'\x0' """)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_eval_bytes_invalid_escape(self):
for b in range(1, 128):
if b in b"""\n\r"'01234567\\abfnrtvx""":
Expand All @@ -250,8 +246,7 @@ def test_eval_bytes_invalid_escape(self):
self.assertEqual(exc.filename, '<string>')
self.assertEqual(exc.lineno, 2)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_eval_bytes_invalid_octal_escape(self):
for i in range(0o400, 0o1000):
with self.assertWarns(SyntaxWarning):
Expand Down
17 changes: 6 additions & 11 deletions Lib/test/test_strtod.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_short_halfway_cases(self):
digits *= 5
exponent -= 1

@unittest.skip("TODO: RUSTPYTHON, fails on debug mode, flaky in release mode")
@unittest.skip('TODO: RUSTPYTHON; fails on debug mode, flaky in release mode')
def test_halfway_cases(self):
# test halfway cases for the round-half-to-even rule
for i in range(100 * TEST_SIZE):
Expand All @@ -173,8 +173,7 @@ def test_halfway_cases(self):
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_boundaries(self):
# boundaries expressed as triples (n, e, u), where
# n*10**e is an approximation to the boundary value and
Expand All @@ -195,8 +194,7 @@ def test_boundaries(self):
u *= 10
e -= 1

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_underflow_boundary(self):
# test values close to 2**-1075, the underflow boundary; similar
# to boundary_tests, except that the random error doesn't scale
Expand All @@ -208,8 +206,7 @@ def test_underflow_boundary(self):
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bigcomp(self):
for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50:
dig10 = 10**ndigs
Expand All @@ -219,8 +216,7 @@ def test_bigcomp(self):
s = '{}e{}'.format(digits, exponent)
self.check_strtod(s)

# TODO: RUSTPYTHON, Incorrectly rounded str->float conversion for -07e-321
@unittest.skip("TODO: RUSTPYTHON; flaky test")
@unittest.skip('TODO: RUSTPYTHON; flaky test')
def test_parsing(self):
# make '0' more likely to be chosen than other digits
digits = '000000123456789'
Expand Down Expand Up @@ -288,8 +284,7 @@ def negative_exp(n):
self.assertEqual(float(negative_exp(20000)), 1.0)
self.assertEqual(float(negative_exp(30000)), 1.0)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_particular(self):
# inputs that produced crashes or incorrectly rounded results with
# previous versions of dtoa.c, for various reasons
Expand Down
29 changes: 1 addition & 28 deletions Lib/test/test_sundry.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
"""Do a minimal test of all the modules that aren't otherwise tested."""
import importlib
import platform
import sys
from test import support
from test.support import import_helper
from test.support import warnings_helper
import unittest

class TestUntestedModules(unittest.TestCase):
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
def test_untested_modules_can_be_imported(self):
untested = ('encodings',)
with warnings_helper.check_warnings(quiet=True):
Expand All @@ -21,31 +18,6 @@ def test_untested_modules_can_be_imported(self):
self.fail('{} has tests even though test_sundry claims '
'otherwise'.format(name))

import distutils.bcppcompiler
import distutils.ccompiler
import distutils.cygwinccompiler
import distutils.filelist
import distutils.text_file
import distutils.unixccompiler

import distutils.command.bdist_dumb
if sys.platform.startswith('win') and not platform.win32_is_iot():
import distutils.command.bdist_msi
import distutils.command.bdist
import distutils.command.bdist_rpm
import distutils.command.build_clib
import distutils.command.build_ext
import distutils.command.build
import distutils.command.clean
import distutils.command.config
import distutils.command.install_data
import distutils.command.install_egg_info
import distutils.command.install_headers
import distutils.command.install_lib
import distutils.command.register
import distutils.command.sdist
import distutils.command.upload

import html.entities

try:
Expand All @@ -54,5 +26,6 @@ def test_untested_modules_can_be_imported(self):
if support.verbose:
print("skipping tty")


if __name__ == "__main__":
unittest.main()
Loading
Loading