How to use the mock.mock function in mock

To help you get started, we’ve selected a few mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github faaez / capiq-python / tests / unit / test_capiq_client_gdsg.py View on Github external
    @mock.patch('capiq_client.requests.post', side_effect=mocked_gdsg_data_requests_post)
    def test_gdsg_data(self, mocked_post):
        ciq_client = CapIQClient()
        return_value = ciq_client.gdsg(["TRIP"], ["IQ_CLOSEPRICE"], ["close_price"], properties=[{}])
        self.assertEqual(return_value, {'TRIP:': {'close_price': '46.80'}})
github bokeh / bokeh / tests / unit / bokeh / plotting / test_helpers.py View on Github external
def test__glyph_receives_renderer_arg(arg, values):
    for value in values:
        with mock.patch('bokeh.plotting.helpers.GlyphRenderer', autospec=True) as gr_mock:
            fn = bph._glyph_function(Marker)
            fn(Figure(), x=0, y=0, **{arg: value})
            _, kwargs = gr_mock.call_args
            assert arg in kwargs and kwargs[arg] == value
github openattic / openattic / backend / tests.py View on Github external
def test_timeout_auto_set(self):
        with mock.patch('requests.Session.request') as mock_request:
            rest_client = RestClient('localhost', 8000)
            rest_client.session.request('GET', '/test')
            mock_request.assert_called_with('GET', '/test', timeout=45)
github openattic / openattic / backend / grafana / tests.py View on Github external
def test_hiding_of_dashboard_selection(self, request_method, settings):
        request = mock.Mock()
        request.META = {}
        request.GET.copy.return_value = 42

        response = mock.Mock()
        response.content = ''
        response.headers = {}
        response.status_code = 200
        request_method.return_value = response

        for path in ('ceph-osd', 'ceph-pools', 'ceph-rbd', 'node-statistics',
                     'ceph-object-gateway-users'):
            r = get_grafana_api_response(request, path)
            r.content = re.sub(r'\s', '', r.content)
            self.assertContains(r, '<style>.navbar-section-wrapper{display:none}</style>')

        r = get_grafana_api_response(request, 'bar')
github SwagLyrics / SwagLyrics-For-Spotify / tests / test_spotify.py View on Github external
def test_that_artist_function_returns_None_when_error(self, mock):
		"""
		test that test artist function returns None when the get_info_windows function will return an error
		"""
		x = artist()
		self.assertEqual(x, None)

	@patch('swaglyrics.spotify.get_info_windows', side_effect=ValueError)
	def test_that_song_function_returns_None_when_error(self, mock):
		"""
		test that test song function returns None when the get_info_windows function will return an error
		"""
		x = song()
		self.assertEqual(x, None)

@mock.patch('platform.system', return_value='Darwin')
class DarwinTests(unittest.TestCase):
	"""
	Unit tests for macOS
	"""

	def setup(self, mock_os):
		pass

	@patch('swaglyrics.spotify.get_info_mac')
	def test_that_artist_function_calls_get_info(self, mock, mock_os):
		"""
		test that test artist function calls get_info_mac function
		"""
		x = artist()
		self.assertTrue(mock.called)
github corochann / chainer_sklearn / tests / chainer_tests / links_tests / sklearn_tests / test_sklearn_wrapper_classifier.py View on Github external
def check_call(self):
        xp = self.link.xp

        y = chainer.Variable(xp.random.uniform(
            -1, 1, (5, 7)).astype(numpy.float32))
        self.link.predictor = mock.MagicMock(return_value=y)

        x = chainer.Variable(xp.asarray(self.x))
        t = chainer.Variable(xp.asarray(self.t))
        if self.x_num == 1:
            loss = self.link(x, t)
            self.link.predictor.assert_called_with(x)
        elif self.x_num == 2:
            x_ = chainer.Variable(xp.asarray(self.x.copy()))
            loss = self.link(x, x_, t)
            self.link.predictor.assert_called_with(x, x_)

        self.assertTrue(hasattr(self.link, 'y'))
        self.assertIsNotNone(self.link.y)

        self.assertTrue(hasattr(self.link, 'loss'))
        xp.testing.assert_allclose(self.link.loss.data, loss.data)
github algosec / algosec-python / tests / test_api_clients / test_fire_flow.py View on Github external
    @mock.patch('algosec.api_clients.fire_flow.FireFlowAPIClient._get_soap_client')
    def test_initiate_client(self, mock_get_soap_client, mocker, fireflow_client):
        client = fireflow_client._initiate_client()

        # Assert that the soap client was created properly
        assert client == fireflow_client._get_soap_client.return_value
        fireflow_client._get_soap_client.assert_called_once_with(
            'https://testing.algosec.com/WebServices/FireFlow.wsdl',
            location='https://testing.algosec.com/WebServices/WSDispatcher.pl',
        )

        # Assert that the soap client was logged in and the session id was saved
        assert client.service.authenticate.call_args == mocker.call(
            username=fireflow_client.user,
            password=fireflow_client.password,
        )
        assert fireflow_client._session_id == client.service.authenticate.return_value.sessionId
github CCExtractor / sample-platform / tests / TestLogConfiguration.py View on Github external
log_config = LogConfiguration(folder, filename, debug)

                        mock_sh().setLevel.assert_called_once_with(
                            result_level)
                        mock_sh().setFormatter.assert_called_once_with(
                            mock_formatter())
                        mock_fh.assert_called_once_with(joined_path,
                                                        maxBytes=1024 * 1024,
                                                        backupCount=20)
                        mock_fh().setLevel.assert_called_once_with(
                            logging.DEBUG)
                        mock_fh().setFormatter.assert_called_once_with(
                            mock_formatter())
                        mock_formatter.assert_has_calls([
                            mock.call(console_format),
                            mock.call(file_format)
                        ])
                        mock_join.assert_called_once_with(folder, 'logs',
                                                          '%s.log' % filename)

                        self.assertEqual(log_config._consoleLogger, mock_sh())
                        self.assertEqual(log_config.console_logger, mock_sh())
                        self.assertEqual(log_config._fileLogger, mock_fh())
                        self.assertEqual(log_config.file_logger, mock_fh())

                        return log_config
github RTIP / artip / src / unittest / python / analyser_tests / r_flagger_tests.py View on Github external
    @mock.patch('config.GLOBAL_CONFIGS', update_polarizations(None, ['RR']))
    def setUp(self):
        self.mocked_ms = Mock(name="ms")
        self.dispersed_phase_set = Mock(name='dispersed_phase_set', spec=PhaseSet)
        self.non_dispersed_phase_set = Mock(name='non_dispersed_phase_set', spec=PhaseSet)
        self.dispersed_phase_set.is_dispersed.return_value = True
        self.non_dispersed_phase_set.is_dispersed.return_value = False
github faaez / capiq-python / tests / unit / test_capiq_client_gdsp.py View on Github external
    @mock.patch('capiq_client.requests.post', side_effect=mocked_gdsp_data_requests_post)
    def test_gdsp_data(self, mocked_post):
        ciq_client = CapIQClient()
        return_value = ciq_client.gdsp(["TRIP"], ["IQ_CLOSEPRICE"], ["close_price"], [{}])
        self.assertEqual(return_value, {'TRIP:': {'close_price': '46.80'}})