On 17 Jul, 2005, at 9:58, Lior Kesos wrote:
Another option for mocking would be a class that would inherit from
cgi and then overload the functions you want to manipulate.
meaning :
class mycgi(cgi):
def get_params(self):
doMyOwnMagic()
You can't subclass a module.
>>> import cgi
>>> class MockCGI(cgi):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: function takes at most 2 arguments (3 given)
To replace a module, you need to replace the module in sys.modules, but
if you need to change only few functions, simply replace them:
>>> import cgi
>>> def mock_get_params(): return 'mocked pararms'
...
>>> cgi.get_params = mock_get_params
>>> cgi.get_params()
'mocked pararms'
Best Regards,
Nir Soffer