From b7a3c7ea18fa49d2977ed142e559e96f6ae6af55 Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Mon, 18 Apr 2016 12:56:47 -0700 Subject: [PATCH 1/3] Add object overload test --- src/testing/methodtest.cs | 15 +++++++++++++++ src/tests/test_method.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/testing/methodtest.cs b/src/testing/methodtest.cs index 7634c4839..76546f0d3 100644 --- a/src/testing/methodtest.cs +++ b/src/testing/methodtest.cs @@ -116,6 +116,21 @@ public static int[] TestOverloadedParams(int v, int[] args) return args; } + public static string TestOverloadedNoObject(int i) + { + return "Got int"; + } + + public static string TestOverloadedObject(int i) + { + return "Got int"; + } + + public static string TestOverloadedObject(object o) + { + return "Got object"; + } + public static bool TestStringOutParams(string s, out string s1) { s1 = "output string"; diff --git a/src/tests/test_method.py b/src/tests/test_method.py index e29986969..41171df82 100644 --- a/src/tests/test_method.py +++ b/src/tests/test_method.py @@ -769,3 +769,25 @@ def test_wrong_overload(): res = System.Math.Max(System.Double(50.5), 50.1) assert res == 50.5 assert type(res) == float + + +def test_no_object_in_param(): + """Test that fix for #203 doesn't break behavior w/ no object overload""" + + res = MethodTest.TestOverloadedNoObject(5) + assert res == "Got int" + + with pytest.raises(TypeError): + MethodTest.TestOverloadedNoObject("test") + + +@pytest.mark.xfail(reason="Needs fixing. #203") +def test_object_in_param(): + """Test regression introduced by #151 in which Object method overloads + aren't being used. See #203 for issue.""" + + res = MethodTest.TestOverloadedObject(5) + assert res == "Got int" + + res = MethodTest.TestOverloadedObject("test") + assert res == "Got object" From 2cabc9f623dac83d83f0798102510670299fbbaf Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Sun, 22 May 2016 12:19:10 -0700 Subject: [PATCH 2/3] Add object type to methodbind --- src/runtime/methodbinder.cs | 2 +- src/tests/test_method.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/runtime/methodbinder.cs b/src/runtime/methodbinder.cs index b3df8448f..f0c58f34f 100644 --- a/src/runtime/methodbinder.cs +++ b/src/runtime/methodbinder.cs @@ -375,7 +375,7 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth if (clrtype != null) { var typematch = false; - if (pi[n].ParameterType != clrtype) + if ((pi[n].ParameterType != typeof(object)) && (pi[n].ParameterType != clrtype)) { IntPtr pytype = Converter.GetPythonTypeByAlias(pi[n].ParameterType); pyoptype = Runtime.PyObject_Type(op); diff --git a/src/tests/test_method.py b/src/tests/test_method.py index 41171df82..2c59fedac 100644 --- a/src/tests/test_method.py +++ b/src/tests/test_method.py @@ -781,7 +781,6 @@ def test_no_object_in_param(): MethodTest.TestOverloadedNoObject("test") -@pytest.mark.xfail(reason="Needs fixing. #203") def test_object_in_param(): """Test regression introduced by #151 in which Object method overloads aren't being used. See #203 for issue.""" From 4071aa3c37ac45bb6fe40d23558f68922f9b7f3e Mon Sep 17 00:00:00 2001 From: Victor Uriarte Date: Tue, 14 Feb 2017 23:26:49 -0700 Subject: [PATCH 3/3] Add more object overload method tests --- src/testing/methodtest.cs | 50 +++++++++++++++++++++++++++++++++++++++ src/tests/test_method.py | 29 +++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src/testing/methodtest.cs b/src/testing/methodtest.cs index 76546f0d3..e76348ab4 100644 --- a/src/testing/methodtest.cs +++ b/src/testing/methodtest.cs @@ -131,6 +131,56 @@ public static string TestOverloadedObject(object o) return "Got object"; } + public static string TestOverloadedObjectTwo(int a, int b) + { + return "Got int-int"; + } + + public static string TestOverloadedObjectTwo(string a, string b) + { + return "Got string-string"; + } + + public static string TestOverloadedObjectTwo(string a, int b) + { + return "Got string-int"; + } + + public static string TestOverloadedObjectTwo(string a, object b) + { + return "Got string-object"; + } + + public static string TestOverloadedObjectTwo(int a, object b) + { + return "Got int-object"; + } + + public static string TestOverloadedObjectTwo(object a, int b) + { + return "Got object-int"; + } + + public static string TestOverloadedObjectTwo(object a, object b) + { + return "Got object-object"; + } + + public static string TestOverloadedObjectTwo(int a, string b) + { + return "Got int-string"; + } + + public static string TestOverloadedObjectThree(object a, int b) + { + return "Got object-int"; + } + + public static string TestOverloadedObjectThree(int a, object b) + { + return "Got int-object"; + } + public static bool TestStringOutParams(string s, out string s1) { s1 = "output string"; diff --git a/src/tests/test_method.py b/src/tests/test_method.py index 2c59fedac..12c8cb13e 100644 --- a/src/tests/test_method.py +++ b/src/tests/test_method.py @@ -790,3 +790,32 @@ def test_object_in_param(): res = MethodTest.TestOverloadedObject("test") assert res == "Got object" + + +def test_object_in_multiparam(): + """Test method with object multiparams behaves""" + + res = MethodTest.TestOverloadedObjectTwo(5, 5) + assert res == "Got int-int" + + res = MethodTest.TestOverloadedObjectTwo(5, "foo") + assert res == "Got int-string" + + res = MethodTest.TestOverloadedObjectTwo("foo", 7.24) + assert res == "Got string-object" + + res = MethodTest.TestOverloadedObjectTwo("foo", "bar") + assert res == "Got string-string" + + res = MethodTest.TestOverloadedObjectTwo("foo", 5) + assert res == "Got string-int" + + res = MethodTest.TestOverloadedObjectTwo(7.24, 7.24) + assert res == "Got object-object" + + +def test_object_in_multiparam_exception(): + """Test method with object multiparams behaves""" + + with pytest.raises(TypeError): + MethodTest.TestOverloadedObjectThree("foo", "bar")