From a52ae3f597805b1ee3245f20bf21a89f404bca0a Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Wed, 18 Nov 2020 09:50:12 -0800 Subject: [PATCH 1/2] Update DLR ref --- Src/DLR | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/DLR b/Src/DLR index af4d5595d..d184affec 160000 --- a/Src/DLR +++ b/Src/DLR @@ -1 +1 @@ -Subproject commit af4d5595d593596b64cf2c0337de2fd8ae1bf47b +Subproject commit d184affecb6d623ee21cda10e5d136f2ceb7628c From 766b6026edc542453f9abbcf417e5426b3e1d923 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Wed, 18 Nov 2020 09:51:02 -0800 Subject: [PATCH 2/2] Update tests to match DLR --- Tests/interop/net/method/test_arguments.py | 37 ++++++++++++++++++---- Tests/test_dlrkwarg.py | 9 ++---- Tests/test_function.py | 14 ++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Tests/interop/net/method/test_arguments.py b/Tests/interop/net/method/test_arguments.py index 6ac49a2ff..02981c3fe 100644 --- a/Tests/interop/net/method/test_arguments.py +++ b/Tests/interop/net/method/test_arguments.py @@ -23,6 +23,8 @@ def setUp(self): self.o = VariousParameters() def test_0_1_args(self): + import System + from Merlin.Testing import Flag # public void M100() { Flag.Set(10); } f = self.o.M100 @@ -95,6 +97,9 @@ def test_0_1_args(self): self.assertRaisesMessage(TypeError, "M202() got an unexpected keyword argument 'arg'", lambda: f(**{'arg': 3}))# msg self.assertRaisesMessage(TypeError, "M202() got an unexpected keyword argument 'other'", lambda: f(**{'other': 4})) + ar_int = System.Array[System.Int32](3) + f(ar_int); Flag.Check(3) + # public void M203([ParamDictionaryAttribute] IDictionary arg) { Flag.Set(arg.Count); } f = self.o.M203 f() @@ -106,8 +111,17 @@ def test_0_1_args(self): f(**{'a':2, 'b':3}) f(a=1, **{'b':2, 'c':5}) self.assertRaisesMessage(TypeError, "M203() got multiple values for keyword argument 'a'", lambda: f(a=1, **{'a':2, 'c':5})) - self.assertRaisesMessage(TypeError, "M203() takes no arguments (3 given)", lambda: f(*(1,2,3))) + self.assertRaisesMessage(TypeError, "M203() takes no arguments (3 given)", lambda: f(*(1,2,3))) # msg: no positional arguments + dict_obj = System.Collections.Generic.Dictionary[System.Object, System.Object]() + self.assertRaisesMessage(TypeError, "M203() takes no arguments (1 given)", lambda: f(dict_obj)) # msg: no positional arguments + # public void M204(params object[] arg) + f = self.o.M204 + + ar_obj = System.Array[System.Object](3) + f(ar_obj); Flag.Check(3) + f(ar_obj, ar_obj); Flag.Check(2) + f(ar_int); Flag.Check(1) def test_optional(self): import System @@ -230,7 +244,7 @@ def test_two_args(self): # TODO: mixed f(x = 1) # check the value - #public void M351(int x, [ParamDictionary] IDictionary arg) { Flag.Set(arg); } + #public void M351(int x, [ParamDictionary] IDictionary y) { Flag.Set(y); } f = self.o.M351 self.assertRaisesMessage(TypeError, "M351() takes exactly 1 argument (0 given)", lambda: f()) f(1); self.assertEqual(Flag[object].Value1, {}) @@ -240,7 +254,7 @@ def test_two_args(self): f(x=1); self.assertEqual(Flag[object].Value1, {}) f(**{'x' : 1}); self.assertEqual(Flag[object].Value1, {}) - #public void M352([ParamDictionary] IDictionary arg, params int[] x) { Flag.Set(arg); } + #public void M352([ParamDictionary] IDictionary x, params object[] y) { Flag.Set(x); } f=self.o.M352 f(); self.assertEqual(Flag[object].Value1, {}) @@ -269,20 +283,22 @@ def test_default_values_2(self): f(1, **{'y':2}); Flag.Check(3) - # public void M320([DefaultParameterValue(40)] int y, int x) { Flag.Set(x + y); } + # public void M320([DefaultParameterValue(40)] int x, int y) { Flag.Set(x + y); } f = self.o.M320 self.assertRaisesMessage(TypeError, "M320() takes at least 1 argument (0 given)", f) f(1); Flag.Check(41) # !!! f(2, 3); Flag.Check(5) self.assertRaisesMessage(TypeError, "M320() takes at most 2 arguments (3 given)", lambda : f(1, 2, 3)) - f(x = 2); Flag.Check(42) + f(y = 2); Flag.Check(42) + f(y = 2, x = 3); Flag.Check(5) f(x = 2, y = 3); Flag.Check(5) f(*(1,)); Flag.Check(41) f(*(1, 2)); Flag.Check(3) - self.assertRaisesMessage(TypeError, "Argument for M320() given by name ('y') and position (1)", lambda : f(5, y = 6)) # !!! - f(6, x = 7); Flag.Check(13) + self.assertRaisesMessage(TypeError, "Argument for M320() given by name ('x') and position (1)", lambda : f(5, x = 6)) # !!! + self.assertRaisesMessage(TypeError, "M320() got an unexpected keyword argument 'x'", lambda : f(x = 6)) # !!! + f(6, y = 7); Flag.Check(13) # public void M330([DefaultParameterValue(50)] int x, [DefaultParameterValue(60)] int y) { Flag.Set(x + y); } f = self.o.M330 @@ -362,6 +378,13 @@ def test_3_args(self): #f(*(1, 2, 0, 1), **{'z':3, 'y':4}) # FIXME: M550() takes at least 2 arguments (6 given) => e.g. Argument for M550() given by name ('x') and position (1) #f(*(1, 2, 0, 1), **{'z':3, 'x':4}) # FIXME: M550() takes at least 2 arguments (6 given) => e.g. Argument for M550() given by name ('x') and position (1) + # public void M560(int x, [ParamDictionary] IDictionary y, params int[] z) { Flag.Set(x * 100 + y.Count * 10 + z.Length); } + f = self.o.M560 + f(2, 3, 4, a=5, b=6, c=7); Flag.Check(2 * 100 + 3 * 10 + 2) + self.assertRaisesMessage(TypeError, "Argument for M560() given by name ('x') and position (1)", lambda: f(2, 3, 4, x=4, b=6, c=7)) + f(2, 3, 4, y=5, b=6, c=7); Flag.Check(2 * 100 + 3 * 10 + 2) + f(2, 3, 4, z=5, b=6, c=7); Flag.Check(2 * 100 + 3 * 10 + 2) + def test_many_args(self): from Merlin.Testing import Flag #public void M650(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10) { } diff --git a/Tests/test_dlrkwarg.py b/Tests/test_dlrkwarg.py index 5a899753b..47f18ac23 100644 --- a/Tests/test_dlrkwarg.py +++ b/Tests/test_dlrkwarg.py @@ -74,13 +74,10 @@ def test_bad(self): self.assertRaisesMessage(TypeError, "FuncWithIRoDictGenSOKwargs() takes no arguments (1 given)", Variadics.FuncWithIRoDictGenSOKwargs, {}) - # TODO: this should not work, 'kwargs' should be a key in 'kwargs' dict passed to the builtin function + def test_keyword_arg(self): clrdict = System.Collections.Generic.Dictionary[System.String, System.Object]() - self.assertEqual(Variadics.FuncWithIRoDictGenSOKwargs(kwargs=clrdict), 0) - - # TODO: This should work - #self.assertEqual(Variadics.FuncWithIRoDictGenSOKwargs(kwargs={}), 'kwargs') - #self.assertEqual(Variadics.FuncWithIRoDictGenSOKwargs(kwargs=clrdict), 'kwargs') + self.assertEqual(Variadics.FuncWithIRoDictGenSOKwargs(kwargs=clrdict), 1) # no binding by keyword + self.assertEqual(Variadics.FuncWithIRoDictGenSOKwargs(kwargs={}), 1) def test_attribcol(self): self.assertRaisesMessage(SystemError, "Unsupported param dictionary type: System.ComponentModel.AttributeCollection", diff --git a/Tests/test_function.py b/Tests/test_function.py index 9cb755183..372e817bb 100644 --- a/Tests/test_function.py +++ b/Tests/test_function.py @@ -347,6 +347,20 @@ def foo(**kwargs): self.assertTrue(SplatTest2.FuncWithIDictGenOOKwargs(**mymapping({mystr("bla"): "bla"}))) self.assertTrue(SplatTest2.FuncWithIDictGenSOKwargs(**mymapping({mystr("bla"): "bla"}))) + def test_kwargs4(self): + """verify args/kwargs are not bindable by name or position""" + + def foo(*args, **kwargs): + return args, kwargs + + self.assertEqual(foo(), ((), {})) + self.assertEqual(foo(args=()), ((), {'args': ()})) + self.assertEqual(foo(kwargs={}), ((), {'kwargs': {}})) + self.assertEqual(foo(args=(), kwargs={}), ((), {'args': (), 'kwargs': {}})) + self.assertEqual(foo(()), (((),), {})) + self.assertEqual(foo({}), (({},), {})) + self.assertEqual(foo((), {}), (((), {}), {})) + @skipUnlessIronPython() def test_params_method_no_params(self): """call a params method w/ no params"""