Skip to content

Commit 51add1a

Browse files
committed
Review (part 3): add more tests
1 parent b213f62 commit 51add1a

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

Lib/test/test_clinic.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,6 +4088,49 @@ def test_depr_multi(self):
40884088
check("a", b="b", c="c", d="d", e="e", f="f", g="g")
40894089
self.assertRaises(TypeError, fn, a="a", b="b", c="c", d="d", e="e", f="f", g="g")
40904090

4091+
def test_lone_kwds(self):
4092+
with self.assertRaises(TypeError):
4093+
ac_tester.lone_kwds(1, 2)
4094+
self.assertEqual(ac_tester.lone_kwds(), ({},))
4095+
self.assertEqual(ac_tester.lone_kwds(y='y'), ({'y': 'y'},))
4096+
kwds = {'y': 'y', 'z': 'z'}
4097+
self.assertEqual(ac_tester.lone_kwds(y='y', z='z'), (kwds,))
4098+
self.assertEqual(ac_tester.lone_kwds(**kwds), (kwds,))
4099+
4100+
def test_kwds_with_pos_only(self):
4101+
with self.assertRaises(TypeError):
4102+
ac_tester.kwds_with_pos_only()
4103+
with self.assertRaises(TypeError):
4104+
ac_tester.kwds_with_pos_only(y='y')
4105+
with self.assertRaises(TypeError):
4106+
ac_tester.kwds_with_pos_only(1, y='y')
4107+
self.assertEqual(ac_tester.kwds_with_pos_only(1, 2), (1, 2, {}))
4108+
self.assertEqual(ac_tester.kwds_with_pos_only(1, 2, y='y'), (1, 2, {'y': 'y'}))
4109+
kwds = {'y': 'y', 'z': 'z'}
4110+
self.assertEqual(ac_tester.kwds_with_pos_only(1, 2, y='y', z='z'), (1, 2, kwds))
4111+
self.assertEqual(ac_tester.kwds_with_pos_only(1, 2, **kwds), (1, 2, kwds))
4112+
4113+
def test_kwds_with_stararg(self):
4114+
self.assertEqual(ac_tester.kwds_with_stararg(), ((), {}))
4115+
self.assertEqual(ac_tester.kwds_with_stararg(1, 2), ((1, 2), {}))
4116+
self.assertEqual(ac_tester.kwds_with_stararg(y='y'), ((), {'y': 'y'}))
4117+
args = (1, 2)
4118+
kwds = {'y': 'y', 'z': 'z'}
4119+
self.assertEqual(ac_tester.kwds_with_stararg(1, 2, y='y', z='z'), (args, kwds))
4120+
self.assertEqual(ac_tester.kwds_with_stararg(*args, **kwds), (args, kwds))
4121+
4122+
def test_kwds_with_pos_only_and_stararg(self):
4123+
with self.assertRaises(TypeError):
4124+
ac_tester.kwds_with_pos_only_and_stararg()
4125+
with self.assertRaises(TypeError):
4126+
ac_tester.kwds_with_pos_only_and_stararg(y='y')
4127+
self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2), (1, 2, (), {}))
4128+
self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2, y='y'), (1, 2, (), {'y': 'y'}))
4129+
args = ('lobster', 'thermidor')
4130+
kwds = {'y': 'y', 'z': 'z'}
4131+
self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2, 'lobster', 'thermidor', y='y', z='z'), (1, 2, args, kwds))
4132+
self.assertEqual(ac_tester.kwds_with_pos_only_and_stararg(1, 2, *args, **kwds), (1, 2, args, kwds))
4133+
40914134

40924135
class LimitedCAPIOutputTests(unittest.TestCase):
40934136

Modules/_testclinic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ static PyObject *
23362336
lone_kwds_impl(PyObject *module, PyObject *kwds)
23372337
/*[clinic end generated code: output=572549c687a0432e input=6ef338b913ecae17]*/
23382338
{
2339-
Py_RETURN_NONE;
2339+
return pack_arguments_newref(1, kwds);
23402340
}
23412341

23422342

@@ -2353,7 +2353,7 @@ kwds_with_pos_only_impl(PyObject *module, PyObject *a, PyObject *b,
23532353
PyObject *kwds)
23542354
/*[clinic end generated code: output=573096d3a7efcce5 input=da081a5d9ae8878a]*/
23552355
{
2356-
Py_RETURN_NONE;
2356+
return pack_arguments_newref(3, a, b, kwds);
23572357
}
23582358

23592359

@@ -2367,7 +2367,7 @@ static PyObject *
23672367
kwds_with_stararg_impl(PyObject *module, PyObject *args, PyObject *kwds)
23682368
/*[clinic end generated code: output=d4b0064626a25208 input=1be404572d685859]*/
23692369
{
2370-
Py_RETURN_NONE;
2370+
return pack_arguments_newref(2, args, kwds);
23712371
}
23722372

23732373

@@ -2386,7 +2386,7 @@ kwds_with_pos_only_and_stararg_impl(PyObject *module, PyObject *a,
23862386
PyObject *kwds)
23872387
/*[clinic end generated code: output=af7df7640c792246 input=2fe330c7981f0829]*/
23882388
{
2389-
Py_RETURN_NONE;
2389+
return pack_arguments_newref(4, a, b, args, kwds);
23902390
}
23912391

23922392

0 commit comments

Comments
 (0)