def create_not_plugin(name, can_parse_command_string): plugin = mock() plugin.canParseCommandString = mock(return_value = can_parse_command_string) plugin.updateSettings = mock() plugin.name = name plugin.processCommandString = mock(return_value = 'modified cmd string') return plugin
def create_not_plugin(name, can_parse_command_string): plugin = mock() plugin.canParseCommandString = mock(return_value=can_parse_command_string) plugin.updateSettings = mock() plugin.name = name plugin.processCommandString = mock(return_value='modified cmd string') return plugin
def create_not_plugin_manager(): not_plugin_manager = mock() self.plugin1 = create_not_plugin('plugin1', True) self.plugin2 = create_not_plugin('plugin2', False) self.plugin3 = create_not_plugin('plugin3', False) self.plugin4 = create_not_plugin('plugin4', False) not_plugin_manager.getPlugins = mock(return_value={'plugin1': self.plugin1, 'plugin2': self.plugin2, 'plugin3': self.plugin3, 'plugin4': self.plugin4}) return not_plugin_manager
def create_not_plugin_manager(): not_plugin_manager = mock() self.plugin1 = create_not_plugin('plugin1', True) self.plugin2 = create_not_plugin('plugin2', False) self.plugin3 = create_not_plugin('plugin3', False) self.plugin4 = create_not_plugin('plugin4', False) not_plugin_manager.getPlugins = mock(return_value = {'plugin1' : self.plugin1, 'plugin2' : self.plugin2, 'plugin3' : self.plugin3, 'plugin4' : self.plugin4}) return not_plugin_manager
def setup_module(): global mock_request global response mock_request = patch.start() mock_request = mock_request() mock_request = mock_request.request mock_request.return_value = response = mock()
def mock_request(cookies=None, args=None): request = mock() if cookies == None: cookies = {} request.cookies = cookies if args == None: args = {} request.args = args return request
def __init__(self): super(KialiUser, self).__init__() self.utils = mock() self.identifier = random.getrandbits(128) self.influxClient = self.utils.get_influxClient() self.min_wait = self.utils.get_minWait() self.max_wait = self.utils.get_maxWait() self.utils.create_database() locust.events.request_success += self.hook_request_success locust.events.request_failure += self.hook_request_fail locust.events.quitting += self.hook_locust_quit
def test_should_buy_not_remove_the_product_in_the_store_if_there_are_not_enough_items( self): # Creating the mock object store: Store = mock() # Stubbing when(store).are_there_enough_products("Bread", 15).thenReturn(False) # Execute purchase_order: PurchaseOrder = PurchaseOrder("Bread", 15) purchase_order.buy(store) # Verify verify(store, times=0).remove_products("Bread", 15)
def test_shouldBuyWorkIfThereAreProductsTheFirstTimeButNotTheSeconeOne( self): # Creating the mock object store: Store = mock() # Stubbing when(store).are_there_enough_products("Bread", 15).thenReturn(True, False) # Execute purchase_order: PurchaseOrder = PurchaseOrder("Bread", 15) purchase_order.buy(store) purchase_order.buy(store) # Verify verify(store, times=2).are_there_enough_products("Bread", 15) verify(store, times=1).remove_products("Bread", 15)
def on_pubmsg(self, c, e): global chat_db self.log_message(e) print(e.source + ' - ' + e.arguments[0]) #message = e.arguments[0] usr = e.tags[3]['value'] cmd = e.arguments[0].lower().split(' ')[0][1:] cmdargs = e.arguments[0].split(' ')[1:] if e.tags[3]['value'] in ['Nightbot', 'jnzl']: msg = 'hi im ' + e.tags[3]['value'] + ' and ' + e.arguments[ 0].lower() mocked_msg = mock(msg) self.post_message(mocked_msg) elif e.arguments[0][:1] == '!': print('Received command: ' + cmd) self.do_user_command(e, cmd, cmdargs, usr) elif e.arguments[0][:1] == '#': if e.tags[7]['value'] == 1 or e.tags[13]['value'] == 'mod': print('Received Mod command: ' + cmd) self.do_mod_command(e, cmd, cmdargs, usr) else: print('Ignored Mod command from a user') self.post_message('/me #Locals Only, Bro. No Kooks!') sleep(2) self.post_message( "Commands with '#' are for Mods, Have a siick vid instead - https://www.youtube.com/watch?v=PK28Kaj-X-4" ) elif e.arguments[0].lower().split(' ')[0] in [ 'rephl3xwhut', 'kappa', 'kappapride', 'gachibass' ]: cmd = e.arguments[0].lower().split(' ')[0] print('Received "other" command: ' + cmd) self.do_user_command(e, cmd, cmdargs, usr) else: pass
def check_api_graph(self): utils = mock() additionalParams = {'duration': '1m'} global response_json, response_code, number_of_services response_code = None response_json = None number_of_services = None url = utils.get_graph_url(namespace="all", hostname=self.locust.host, params=additionalParams) try: with self.client.get(url=url, headers=utils.get_headers(), catch_response=True) \ as response: response_json = json.loads(response.content) response_code = response.status_code number_of_services = self.count_valid_services( response_json.get('elements').get('nodes')) except ValueError: response.failure("Something Wrong happened")
def unsupervised_layer(self, layer): from yadll.layers import AutoEncoder return AutoEncoder(incoming=layer, nb_units=25, hyperparameters=mock())
def __new__(cls): return mock.mock(spec=cls)
from mock import mock,Mock #https://stackoverflow.com/questions/16162015/mocking-python-function-based-on-input-arguments #very good examples mock = MagicMock(side_effect=[4, 5, 6]) print mock() print mock() print mock() mock = Mock(side_effect=Exception('Boom!')) print mock()
def setupWP(mock): m = mock() mock.reset_mock() return m
def create_not_mappers_manager(): not_mappers_manager = mock()
def mock_render(): return mock(side_effect=render)
def mock_unicode_string(s): unicode_string = mock() unicode_string.encode = mock(return_value=s) return unicode_string
def winning_door_is_chosen(context): context.rng = mock(return_value=0) context.play.place_car(rng=context.rng)
def mock_response(): response = mock() response.set_cookie = mock() return response
def named_layer(self): from yadll.layers import Layer return Layer(mock(), name='layer_name')
def player_picks_a_random_door(context): context.rng = mock(return_value=0) context.play.pick_random(rng=context.rng)
def car_is_placed_behind_door(context, door): context.rng = mock(return_value=door) context.play.pick_random(rng=context.rng)
def layer(self): from yadll.layers import Layer return Layer(mock())
def mock_datetime(now=None): if not isinstance(now, datetime): now = datetime.now() dt = mock() dt.now = mock(return_value=now) return dt