Skip to content

Commit 05be248

Browse files
committed
unittests for *args and **kwargs in test function definition
1 parent 7af3920 commit 05be248

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/test_test_function_definition.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ def my_fun(x, y = 4, z = ('a', 'b'), *args, **kwargs):
743743
self.SCT_CHECK_ONE = "Ex().check_function_def('my_fun').check_args(1)"
744744
self.SCT_CHECK_Y = "Ex().check_function_def('my_fun').check_args('y')"
745745
self.SCT_CHECK_X = "Ex().check_function_def('my_fun').check_args('x')"
746+
self.SCT_CHECK_ARGS = "Ex().check_function_def('my_fun').check_args('*args')"
747+
self.SCT_CHECK_KWARGS = "Ex().check_function_def('my_fun').check_args('**kwargs')"
746748

747749
def when_code_is_sol(self):
748750
self.data['DC_CODE'] = self.data['DC_SOLUTION']
@@ -782,6 +784,30 @@ def test_fail_kw_not_default(self):
782784
self.data['DC_SCT'] = self.SCT_CHECK_X + ".is_default()"
783785
self.assertFalse(self.when_replace('x, y = 4', 'x = 2, y = 4'))
784786

787+
def test_fail_star_args_undef(self):
788+
self.data['DC_CODE'] = """def my_fun(x, y = 4, z = ('a', 'b'), args=2, **kwargs): pass"""
789+
self.data['DC_SCT'] = self.SCT_CHECK_ARGS
790+
sct_payload = helper.run(self.data)
791+
self.assertFalse(sct_payload['correct'])
792+
793+
def test_fail_star_args_name(self):
794+
self.data['DC_CODE'] = """def my_fun(x, y = 4, z = ('a', 'b'), *wrongargsname, **kwargs): pass"""
795+
self.data['DC_SCT'] = self.SCT_CHECK_ARGS + '.has_equal_name()'
796+
sct_payload = helper.run(self.data)
797+
self.assertFalse(sct_payload['correct'])
798+
799+
def test_fail_kwargs_undef(self):
800+
self.data['DC_CODE'] = """def my_fun(x, y = 4, z = ('a', 'b'), args=2, kwargs=2): pass"""
801+
self.data['DC_SCT'] = self.SCT_CHECK_KWARGS
802+
sct_payload = helper.run(self.data)
803+
self.assertFalse(sct_payload['correct'])
804+
805+
def test_fail_kwargs_name(self):
806+
self.data['DC_CODE'] = """def my_fun(x, y = 4, z = ('a', 'b'), *args, **wrongkwargsname): pass"""
807+
self.data['DC_SCT'] = self.SCT_CHECK_KWARGS + '.has_equal_name()'
808+
sct_payload = helper.run(self.data)
809+
self.assertFalse(sct_payload['correct'])
810+
785811
def test_pass_equal_value(self):
786812
self.data['DC_SCT'] = self.SCT_CHECK_Y + ".has_equal_value('unequal values')"
787813
self.assertTrue(self.when_code_is_sol())
@@ -811,6 +837,7 @@ def test_fail_multi(self):
811837
self.data['DC_SCT'] = self.MULTI_SCT
812838
self.assertFalse(self.when_replace('x', 'x2'))
813839

840+
814841
class TestLambdaFunctionSpec2(TestFunctionSpec2):
815842
def setUp(self):
816843
super().setUp()

0 commit comments

Comments
 (0)