Re: Can you mock a C function using ctypes?

2022-09-15 Thread Eryk Sun
On 9/15/22, Grant Edwards wrote: > > Does the pointer have to be passed? Or can it be "poked" into a global > variable? If the library exports the function pointer as a global variable, it can be set in ctypes using the in_dll() method. Unfortunately, as far as I know, a ctypes function

Re: Can you mock a C function using ctypes?

2022-09-15 Thread Grant Edwards
On 2022-09-15, Eryk Sun wrote: > On 9/15/22, Grant Edwards wrote: >> >> Can that be done using ctypes? >> >> For example, I open a library that contains functon foo() where foo() >> calls external function bar() which is not contained in the library. >> Then, I provide a Python bar() function

Re: Can you mock a C function using ctypes?

2022-09-15 Thread Eryk Sun
On 9/15/22, Grant Edwards wrote: > > Can that be done using ctypes? > > For example, I open a library that contains functon foo() where foo() > calls external function bar() which is not contained in the library. > Then, I provide a Python bar() function that gets called by foo() when > foo() is

Can you mock a C function using ctypes?

2022-09-15 Thread Grant Edwards
I've done unit testing of C functions using ctypes, and that works nicely until you need to provide a stub/mock function to be called by the C code under test. Can that be done using ctypes? For example, I open a library that contains functon foo() where foo() calls external function bar() which