monkeypatching

Pickling monkey-patched Keras model for use in PySpark

旧城冷巷雨未停 提交于 2020-08-21 19:50:35
问题 The overall goal of what I am trying to achieve is sending a Keras model to each spark worker so that I can use the model within a UDF applied to a column of a DataFrame. To do this, the Keras model will need to be picklable. It seems like a lot of people have had success at pickling keras models by monkey patching the Model class as shown by the link below: http://zachmoshe.com/2017/04/03/pickling-keras-models.html However, I have not seen any example of how to do this in tandem with Spark.

How to use monkeypatch in a “setup” method for unit tests using pytest?

守給你的承諾、 提交于 2020-07-18 05:08:50
问题 I am attempting to mock out a utility class (In this case the python logger utility) in a unit test. While I know how to do it using monkeypatch on a per test level, I was hoping I could simply do it as part of the setup/globally in some way. Here is what I am hoping I can do (but I am getting errors): import logging ... def setup(self, monkeypatch): class fake_logger(level): def __init__(self, val): pass def setLevel(self, level): # Do something def mock_logger(level): return fake_logger

How to mock a decorated function

╄→尐↘猪︶ㄣ 提交于 2020-07-14 18:22:30
问题 For testing reasons, I need to be able to mock the inner/original function of a decorated one which is used somewhere else: In mydecorator.py: def my_decorator(f): def wrapped_f(): print "decorated" f() return wrapped_f @my_decorator def function_to_be_mocked(): print 'original' def function_to_be_mocked_undecorated(): print 'original' def run_decorated(): function_to_be_mocked() def run_undecorated(): decorated_funtion = my_decorator(function_to_be_mocked_undecorated) decorated_funtion() As

How to mock a decorated function

倖福魔咒の 提交于 2020-07-14 18:20:15
问题 For testing reasons, I need to be able to mock the inner/original function of a decorated one which is used somewhere else: In mydecorator.py: def my_decorator(f): def wrapped_f(): print "decorated" f() return wrapped_f @my_decorator def function_to_be_mocked(): print 'original' def function_to_be_mocked_undecorated(): print 'original' def run_decorated(): function_to_be_mocked() def run_undecorated(): decorated_funtion = my_decorator(function_to_be_mocked_undecorated) decorated_funtion() As

How to mock a decorated function

孤街浪徒 提交于 2020-07-14 18:19:36
问题 For testing reasons, I need to be able to mock the inner/original function of a decorated one which is used somewhere else: In mydecorator.py: def my_decorator(f): def wrapped_f(): print "decorated" f() return wrapped_f @my_decorator def function_to_be_mocked(): print 'original' def function_to_be_mocked_undecorated(): print 'original' def run_decorated(): function_to_be_mocked() def run_undecorated(): decorated_funtion = my_decorator(function_to_be_mocked_undecorated) decorated_funtion() As

Where to put code when monkey patching

喜欢而已 提交于 2020-05-26 12:23:45
问题 Everything I read about monkey patching says to do something like this: class String def foo #your special code end end But I can't find any instructions on where to put this code. In a rails app, can I just put this any crazy place I want? In a Module? A Model? Do I need to include something in the file where I define my monkeypatch? Do I need to include my monkeypatch everywhere where I want to use it? 回答1: There is no set rule on this. Technically you can open it (the class; and add your

Where to put code when monkey patching

谁说胖子不能爱 提交于 2020-05-26 12:23:31
问题 Everything I read about monkey patching says to do something like this: class String def foo #your special code end end But I can't find any instructions on where to put this code. In a rails app, can I just put this any crazy place I want? In a Module? A Model? Do I need to include something in the file where I define my monkeypatch? Do I need to include my monkeypatch everywhere where I want to use it? 回答1: There is no set rule on this. Technically you can open it (the class; and add your

Where to put code when monkey patching

北城余情 提交于 2020-05-26 12:23:03
问题 Everything I read about monkey patching says to do something like this: class String def foo #your special code end end But I can't find any instructions on where to put this code. In a rails app, can I just put this any crazy place I want? In a Module? A Model? Do I need to include something in the file where I define my monkeypatch? Do I need to include my monkeypatch everywhere where I want to use it? 回答1: There is no set rule on this. Technically you can open it (the class; and add your