summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_tasks.py3
-rw-r--r--Lib/test/test_cmath.py51
-rw-r--r--Lib/test/test_contextlib.py8
-rw-r--r--Lib/test/test_urlparse.py41
-rw-r--r--Lib/test/test_with.py6
5 files changed, 95 insertions, 14 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py
index 6541df75e0..251192acee 100644
--- a/Lib/test/test_asyncio/test_tasks.py
+++ b/Lib/test/test_asyncio/test_tasks.py
@@ -1715,7 +1715,8 @@ class TaskTests(test_utils.TestCase):
self.assertTrue(m_log.error.called)
message = m_log.error.call_args[0][0]
func_filename, func_lineno = test_utils.get_function_source(coro_noop)
- regex = (r'^<CoroWrapper %s\(\) .* at %s:%s, .*> '
+
+ regex = (r'^<CoroWrapper %s\(?\)? .* at %s:%s, .*> '
r'was never yielded from\n'
r'Coroutine object created at \(most recent call last\):\n'
r'.*\n'
diff --git a/Lib/test/test_cmath.py b/Lib/test/test_cmath.py
index 4db6b2b991..68bf16e51a 100644
--- a/Lib/test/test_cmath.py
+++ b/Lib/test/test_cmath.py
@@ -1,4 +1,4 @@
-from test.support import run_unittest, requires_IEEE_754
+from test.support import run_unittest, requires_IEEE_754, cpython_only
from test.test_math import parse_testfile, test_file
import unittest
import cmath, math
@@ -381,17 +381,48 @@ class CMathTests(unittest.TestCase):
self.rAssertAlmostEqual(expected.imag, actual.imag,
msg=error_message)
- def assertCISEqual(self, a, b):
- eps = 1E-7
- if abs(a[0] - b[0]) > eps or abs(a[1] - b[1]) > eps:
- self.fail((a ,b))
+ def check_polar(self, func):
+ def check(arg, expected):
+ got = func(arg)
+ for e, g in zip(expected, got):
+ self.rAssertAlmostEqual(e, g)
+ check(0, (0., 0.))
+ check(1, (1., 0.))
+ check(-1, (1., pi))
+ check(1j, (1., pi / 2))
+ check(-3j, (3., -pi / 2))
+ inf = float('inf')
+ check(complex(inf, 0), (inf, 0.))
+ check(complex(-inf, 0), (inf, pi))
+ check(complex(3, inf), (inf, pi / 2))
+ check(complex(5, -inf), (inf, -pi / 2))
+ check(complex(inf, inf), (inf, pi / 4))
+ check(complex(inf, -inf), (inf, -pi / 4))
+ check(complex(-inf, inf), (inf, 3 * pi / 4))
+ check(complex(-inf, -inf), (inf, -3 * pi / 4))
+ nan = float('nan')
+ check(complex(nan, 0), (nan, nan))
+ check(complex(0, nan), (nan, nan))
+ check(complex(nan, nan), (nan, nan))
+ check(complex(inf, nan), (inf, nan))
+ check(complex(-inf, nan), (inf, nan))
+ check(complex(nan, inf), (inf, nan))
+ check(complex(nan, -inf), (inf, nan))
def test_polar(self):
- self.assertCISEqual(polar(0), (0., 0.))
- self.assertCISEqual(polar(1.), (1., 0.))
- self.assertCISEqual(polar(-1.), (1., pi))
- self.assertCISEqual(polar(1j), (1., pi/2))
- self.assertCISEqual(polar(-1j), (1., -pi/2))
+ self.check_polar(polar)
+
+ @cpython_only
+ def test_polar_errno(self):
+ # Issue #24489: check a previously set C errno doesn't disturb polar()
+ from _testcapi import set_errno
+ def polar_with_errno_set(z):
+ set_errno(11)
+ try:
+ return polar(z)
+ finally:
+ set_errno(0)
+ self.check_polar(polar_with_errno_set)
def test_phase(self):
self.assertAlmostEqual(phase(0), 0.)
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 39cc776dbc..8f849ae560 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -111,6 +111,14 @@ class ContextManagerTestCase(unittest.TestCase):
baz = self._create_contextmanager_attribs()(None)
self.assertEqual(baz.__doc__, "Whee!")
+ def test_keywords(self):
+ # Ensure no keyword arguments are inhibited
+ @contextmanager
+ def woohoo(self, func, args, kwds):
+ yield (self, func, args, kwds)
+ with woohoo(self=11, func=22, args=33, kwds=44) as target:
+ self.assertEqual(target, (11, 22, 33, 44))
+
class ClosingTestCase(unittest.TestCase):
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index ad9820bf23..1775ef3353 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -663,6 +663,47 @@ class UrlParseTestCase(unittest.TestCase):
self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff?query"),
(b'x-newscheme', b'foo.com', b'/stuff', b'', b'query', b''))
+ def test_default_scheme(self):
+ # Exercise the scheme parameter of urlparse() and urlsplit()
+ for func in (urllib.parse.urlparse, urllib.parse.urlsplit):
+ with self.subTest(function=func):
+ result = func("http://example.net/", "ftp")
+ self.assertEqual(result.scheme, "http")
+ result = func(b"http://example.net/", b"ftp")
+ self.assertEqual(result.scheme, b"http")
+ self.assertEqual(func("path", "ftp").scheme, "ftp")
+ self.assertEqual(func("path", scheme="ftp").scheme, "ftp")
+ self.assertEqual(func(b"path", scheme=b"ftp").scheme, b"ftp")
+ self.assertEqual(func("path").scheme, "")
+ self.assertEqual(func(b"path").scheme, b"")
+ self.assertEqual(func(b"path", "").scheme, b"")
+
+ def test_parse_fragments(self):
+ # Exercise the allow_fragments parameter of urlparse() and urlsplit()
+ tests = (
+ ("http:#frag", "path"),
+ ("//example.net#frag", "path"),
+ ("index.html#frag", "path"),
+ (";a=b#frag", "params"),
+ ("?a=b#frag", "query"),
+ ("#frag", "path"),
+ )
+ for url, attr in tests:
+ for func in (urllib.parse.urlparse, urllib.parse.urlsplit):
+ if attr == "params" and func is urllib.parse.urlsplit:
+ attr = "path"
+ with self.subTest(url=url, function=func):
+ result = func(url, allow_fragments=False)
+ self.assertEqual(result.fragment, "")
+ self.assertTrue(getattr(result, attr).endswith("#frag"))
+ self.assertEqual(func(url, "", False).fragment, "")
+
+ result = func(url, allow_fragments=True)
+ self.assertEqual(result.fragment, "frag")
+ self.assertFalse(getattr(result, attr).endswith("frag"))
+ self.assertEqual(func(url, "", True).fragment, "frag")
+ self.assertEqual(func(url).fragment, "frag")
+
def test_mixed_types_rejected(self):
# Several functions that process either strings or ASCII encoded bytes
# accept multiple arguments. Check they reject mixed type input
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index 7068a80970..cbaafcf923 100644
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -12,8 +12,8 @@ from test.support import run_unittest
class MockContextManager(_GeneratorContextManager):
- def __init__(self, func, *args, **kwds):
- super().__init__(func, *args, **kwds)
+ def __init__(self, *args):
+ super().__init__(*args)
self.enter_called = False
self.exit_called = False
self.exit_args = None
@@ -31,7 +31,7 @@ class MockContextManager(_GeneratorContextManager):
def mock_contextmanager(func):
def helper(*args, **kwds):
- return MockContextManager(func, *args, **kwds)
+ return MockContextManager(func, args, kwds)
return helper