Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new_callable=mock.PropertyMock)
@mock.patch.object(
jaeger_exporter.JaegerExporter,
'collector',
new_callable=mock.PropertyMock)
@mock.patch.object(jaeger_exporter.JaegerExporter, 'translate_to_jaeger')
def test_emit_succeeded(self, translate_mock, collector_mock, agent_mock):
collector = collector_mock.return_value = MockTransport()
agent = agent_mock.return_value = MockTransport()
exporter = jaeger_exporter.JaegerExporter()
translate_mock.return_value = {'test': 'mock'}
exporter.emit([])
self.assertTrue(agent.export_called)
self.assertTrue(collector.export_called)
collector_mock.return_value = None
agent = agent_mock.return_value = MockTransport()
def test_read_values_float(self, mock_dat):
img2_data = self.img1_data[2:,1:,:]
# mocks
df = [self.img1_data.astype(float).flatten().ravel().tolist(),
img2_data.astype(float).flatten().ravel().tolist()]
mock_dat.return_value.ParseFromString.return_value = ""
type(mock_dat.return_value).data = PropertyMock(return_value='')
type(mock_dat.return_value).float_data = PropertyMock(side_effect=df)
type(mock_dat.return_value).channels = PropertyMock(side_effect=[4, 2])
type(mock_dat.return_value).height = PropertyMock(side_effect=[2, 1])
type(mock_dat.return_value).width = PropertyMock(side_effect=[3, 3])
v = r.read_values(self.path_lmdb, float)
assert_equal(len(v), 2, "Unexpected no. of elements.")
x, _ = v[0]
for ch in range(4):
for row in range(2):
for col in range(3):
assert_equal(x[ch, row, col], self.img1_data[ch, row, col])
x, _ = v[1]
for ch in range(2):
def test_read_values(self, mock_dat):
img2_data = self.img1_data[2:, 1:, :]
# mocks
df = [self.img1_data.astype(float).flatten().ravel().tolist(),
img2_data.astype(float).flatten().ravel().tolist()]
mock_dat.return_value.ParseFromString.return_value = ""
type(mock_dat.return_value).data = PropertyMock(return_value='')
type(mock_dat.return_value).float_data = PropertyMock(side_effect=df)
type(mock_dat.return_value).channels = PropertyMock(side_effect=[4, 2])
type(mock_dat.return_value).height = PropertyMock(side_effect=[2, 1])
type(mock_dat.return_value).width = PropertyMock(side_effect=[3, 3])
v = r.read_values(self.path_lmdb)
assert_equal(len(v), 2, "Unexpected no. of elements.")
x, _ = v[0]
for ch in range(4):
for row in range(2):
for col in range(3):
assert_equal(x[ch, row, col], self.img1_data[ch, row, col])
x, _ = v[1]
def test_losing_name_is_away(self):
expected_name = 'Away Name'
fake_winner = PropertyMock(return_value=HOME)
fake_away_name = PropertyMock(return_value=MockName(expected_name))
type(self.boxscore).winner = fake_winner
type(self.boxscore)._away_name = fake_away_name
assert self.boxscore.losing_name == expected_name
def test_trace_plugin__auto_db__psycopg2(
mock_send_report, mock_connect, handler_with_trace_auto_db_psycopg2, mock_context
):
mock_connect.return_value.dsn = "postgres://username:password@localhost:5432/foobar"
type(mock_connect.return_value.cursor.return_value).query = mock.PropertyMock(
side_effect=[
"INSERT INTO test (num, data) VALUES (%s, %s)",
"SELECT * FROM test",
]
)
iopipe, handler = handler_with_trace_auto_db_psycopg2
assert len(iopipe.config["plugins"]) == 1
handler({}, mock_context)
assert len(iopipe.report.performance_entries) == 0
db_traces = iopipe.report.db_trace_entries
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
patch('src.restore.async_batch_restore_service.BigQuery').start()
patch.object(Configuration, 'backup_project_id', return_value='source_project_id', new_callable=PropertyMock).start()
patch.object(Configuration, 'restoration_project_id', return_value='target_proj', new_callable=PropertyMock).start()
ndb.get_context().clear_cache()
def test_get_select_hosts(self):
host_1 = mock.Mock()
host_1_name_property = mock.PropertyMock(return_value='test_host')
type(host_1).name = host_1_name_property
host_1.summary = 'expected_summary'
host_1._moId = 1
host_2 = mock.Mock()
host_2_name_property = mock.PropertyMock(return_value='test_host_2')
type(host_2).name = host_2_name_property
host_2.summary = 'expected_summary_2'
host_2._moId = 2
host_3 = mock.Mock()
host_3_name_property = mock.PropertyMock(return_value='test_host_3')
type(host_3).name = host_3_name_property
host_3.summary = 'expected_summary_3'
host_3._moId = 3
host_4 = mock.Mock()
host_4_name_property = mock.PropertyMock(return_value='test_host_4')
type(host_4).name = host_4_name_property
host_4.summary = 'expected_summary_4'
host_4._moId = 4
def test_watch_new_folder(self):
with mock.patch("os.listdir", autospec=True) as mock_os_list, mock.patch(
"paasta_tools.deployd.watchers.YelpSoaEventHandler.bounce_service",
autospec=True,
) as mock_bounce_service:
mock_os_list.return_value = ["some.file", "some_other.file"]
mock_event = mock.Mock(maskname="MAJORAS", pathname="/some/path")
self.handler.watch_new_folder(mock_event)
assert not self.mock_filewatcher.wm.add_watch.called
mock_event = mock.Mock(maskname="IN_CREATE|IN_ISDIR", pathname="/foo")
name = mock.PropertyMock(return_value="universe")
type(mock_event).name = name
self.handler.watch_new_folder(mock_event)
assert self.mock_filewatcher.wm.add_watch.called
assert not mock_bounce_service.called
mock_os_list.return_value = ["some.file", "marathon-cluster.yaml"]
self.handler.watch_new_folder(mock_event)
assert self.mock_filewatcher.wm.add_watch.called
mock_bounce_service.assert_called_with(self.handler, "universe")
mock_os_list.side_effect = OSError
mock_bounce_service.reset_mock()
self.handler.watch_new_folder(mock_event)
assert self.mock_filewatcher.wm.add_watch.called
assert not mock_bounce_service.called
def test_do_rpc():
utils.RPCClient.configure("host_mock", "port_mock")
assert utils.RPCClient.hostname == "host_mock"
assert utils.RPCClient.port == "port_mock"
response_mock = mock.PropertyMock(spec=requests.Response)
response_mock.text = '{"result": "result_mock"}'
requests.request = mock.PropertyMock(return_value=response_mock)
q = queue.Queue()
utils.RPCClient._do_rpc(
"method_mock",
params={"param_mock_1": "value_mock_1", "param_mock_2": "value_mock_2"},
queue=q,
)
assert q.get() == "result_mock"
self.setup_admin_login(sess)
data = {
'api_verb': 'GET',
'testing': False,
'api_url': '{ddi}/groups',
'api_token': 'test_token',
'api_id': str(api_id),
'ddi': '766030',
'data_center': 'dfw'
}
with mock.patch('requests.get') as patched_get:
type(patched_get.return_value).content = mock.PropertyMock(
return_value=''
)
type(patched_get.return_value).status_code = mock.PropertyMock(
return_value=401
)
type(patched_get.return_value).headers = mock.PropertyMock(
return_value=(
'{"via": "1.1 Repose (Repose/2.12)",'
'"x-response-id": "a10adb69-4d9f-4457-'
'bda4-e2429f334895",'
'"transfer-encoding": "chunked",'
'"server": "Jetty(8.0.y.z-SNAPSHOT)",'
'"date": "Tue, 18 Mar 2014 19:52:26 GMT",'
'"content-type": "application/json"}'
)
)
response = c.post(
'/big_data/api_call/process',
data=json.dumps(data),