I am currently working on a project that uses python and Chat-GPT to generate C# files. These files get then built in a .NET project and the resulting dll imported back into python using the clr module.
I then want to test if the built code is working correctly. So I import the Telerik Just Mock dll and tried to arrange mocks for an interface that is used in one of the generated files/classes. This is where the problem arises, because the Mock.Arrange doesn’t map correctly to the interface property or method.
Basic Interface that should be mocked:
namespace Interfaces
{
public interface ITestInterface
{
double Progress { get; set; }
void Message(string text);
}
}
My python code looks like this:
from pythonnet import load
load("netfx")
import clr
from pathlib import Path
import os
... setup for paths ...
#The Just Mock Reference
clr.AddReference(str(just_mock_lib / "Telerik.JustMock.dll"))
#The Reference to the Interface that gets used in the generated file
clr.AddReference(interface_reference)
#The dll with the generated files (probably doesnt matter for this example)
clr.AddReference(dll_file)
from Telerik.JustMock import Mock
from Interfaces import ITestInterface
testMock = Mock.Create[ITestInterface]()
Mock.Arrange(lambda: testMock.Progress).Returns(0.5)
(proceed to insert the mock object into a class instance of the generated code)
The last line is where the error occurs (No method matches given arguments for Mock.Arrange: (<class ‘function’>)). I tried different variations but it somehow needs to mimick the arrangement like it is done with C#:
Mock.Arrange(() => testMock.Progress).Returns(0.5);
So my question is, is this the right way or even possible? Would be nice if someone could point me into the right direction.
As for Telerik Just Mock no profiler should be needed for mocking Interfaces.
Documentation for Python.NET:
https://pythonnet.github.io/pythonnet/python.html
I tried different variants of the Mock.Arrange(lambda: testMock.Progress).Returns(0.5)
line that all led to the same error.
I expected the line to execute normally and to check if the mock works with this line: print(testMock.Value)
>> 0.5
dou is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.