def test_test_event_in_facts_relations_test_events_right_to_left_order_fail( # noqa self, test_events_exist_in_facts_relations_mock, test_events_happened_min_relation_times_mock, test_events_right_to_left_order_mock, test_events_same_max_focus_distance_mock): first_vent = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) test_events_exist_in_facts_relations_mock.side_effect = [ False, False, True ] test_events_happened_min_relation_times_mock.side_effect = [True] test_events_right_to_left_order_mock.side_effect = [False] found, relation_key = test_event_in_facts_relations( facts_relations, first_vent, second_event, min_relation_appearance=1, max_focus=35) test_events_right_to_left_order_mock.assert_has_calls([ call( ANY, ANY, { 'first_fact_sample_position': u'-1427048810', 'facts_order': u'True', 'second_fact_sample_position': u'-1427049110', 'facts_distance': u'25' }) ]) # noqa test_events_same_max_focus_distance_mock.assert_has_calls([])
def test_test_event_in_facts_relations_success(self): first_vent = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) found, relation_key = test_event_in_facts_relations( facts_relations, first_vent, second_event, min_relation_appearance=1, max_focus=35) self.assertEqual((found, relation_key), (True, "-1427048810_-1427049110_25_True"))
def test_event_initial_match_is_min_required_percentage_fail(self): first_event = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) second_event.is_sample_attribute_up = MagicMock() second_event.is_sample_attribute_up.side_effect = False match = event_initial_match(facts_relations=None, first_event=first_event, second_event=second_event, min_relation_appearance=None, max_focus=None, min_required_correlation_percentage=80.0) self.assertFalse(second_event.is_sample_attribute_up.called) self.assertFalse(match)
def test_event_initial_match_is_min_required_percentage_success(self): first_event = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) second_event.is_sample_attribute_up = MagicMock() second_event.is_sample_attribute_up.return_value = False match = event_initial_match(facts_relations=None, first_event=first_event, second_event=second_event, min_relation_appearance=None, max_focus=None, min_required_correlation_percentage=45.0) self.assertTrue(second_event.is_sample_attribute_up.called) self.assertFalse(match)
def test_is_first_event_match_min_required_trade_not_registered(self): new_event_dict = event_dict.copy() new_event_dict.update({"correlation": 0.45}) new_event_dict_another = event_dict.copy() new_event_dict_another.update({"correlation": 0.55}) expected_trades = [{ "first_event": dict_to_event(new_event_dict), "second_event_found": False }, { "first_event": dict_to_event(new_event_dict_another), "second_event_found": False }] self.assertTrue( is_first_event_match(expected_trades, self.event_55_percent, 10))
def test_event_initial_match_test_event_in_facts_relations_fail( self, test_event_in_facts_relations_mock, buy_mock): test_event_in_facts_relations_mock.return_value = (False, "some_key") first_event = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) second_event.is_sample_attribute_up = MagicMock() second_event.is_sample_attribute_up.return_value = True match = event_initial_match( facts_relations="fact_relations", first_event=first_event, second_event=second_event, min_relation_appearance="min_relation_appearance", max_focus="max_focus", min_required_correlation_percentage=45.0) self.assertFalse(buy_mock.called) self.assertFalse(match)
def test_prepare_second_event_matches_tasks_no_trade_ready( self, process_second_event_s_mock): new_event_dict = event_dict.copy() new_event_dict.update({"correlation": 0.45}) new_event_dict_another = event_dict.copy() new_event_dict_another.update({"correlation": 0.55}) second_event_dict = event_dict.copy() second_event_dict.update({"correlation": 0.25}) expected_trades = [{ "first_event": dict_to_event(new_event_dict), "second_event_found": True }, { "first_event": dict_to_event(new_event_dict_another), "second_event_found": True }] result = prepare_second_event_matches_tasks(expected_trades, second_event_dict) self.assertFalse(process_second_event_s_mock.called) self.assertEqual(result, [])
def test_test_event_in_facts_relations_test_events_happened_min_relation_times_fail( # noqa self, test_events_exist_in_facts_relations_mock, test_events_happened_min_relation_times_mock, test_events_right_to_left_order_mock): first_vent = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) test_events_exist_in_facts_relations_mock.side_effect = [ False, False, True ] test_events_happened_min_relation_times_mock.side_effect = [False] found, relation_key = test_event_in_facts_relations( facts_relations, first_vent, second_event, min_relation_appearance=1, max_focus=35) test_events_happened_min_relation_times_mock.assert_has_calls( [call(3, 1)]) test_events_right_to_left_order_mock.assert_has_calls([])
def test_test_event_in_facts_relations_sample_events_exist_in_facts_relations_success( # noqa self, test_events_exist_in_facts_relations_mock, test_events_happened_min_relation_times_mock): first_vent = dict_to_event(first_event_dict) second_event = dict_to_event(second_event_dict) test_events_exist_in_facts_relations_mock.side_effect = [ False, False, True ] found, relation_key = test_event_in_facts_relations( facts_relations, first_vent, second_event, min_relation_appearance=1, max_focus=35) expected_calls = [ call( ANY, ANY, { 'first_fact_sample_position': u'+1426794410', 'facts_order': u'True', 'second_fact_sample_position': u'+1426795010', 'facts_distance': u'25' }), # noqa call( ANY, ANY, { 'first_fact_sample_position': u'+1427048810', 'facts_order': u'True', 'second_fact_sample_position': u'+1427049110', 'facts_distance': u'25' }), # noqa call( ANY, ANY, { 'first_fact_sample_position': u'-1427048810', 'facts_order': u'True', 'second_fact_sample_position': u'-1427049110', 'facts_distance': u'25' }) ] # noqa test_events_exist_in_facts_relations_mock.assert_has_calls( expected_calls) test_events_happened_min_relation_times_mock.assert_has_calls( [call(3, 1)])
def test_prepare_second_event_matches_tasks_one_trade_ready( self, process_second_event_s_mock): new_event_dict = event_dict.copy() new_event_dict.update({"correlation": 0.45}) new_event_dict_another = event_dict.copy() new_event_dict_another.update({"correlation": 0.55}) second_event_dict = event_dict.copy() second_event_dict.update({"correlation": 0.25}) expected_trades = [{ "first_event": dict_to_event(new_event_dict), "second_event_found": True }, { "first_event": dict_to_event(new_event_dict_another), "second_event_found": False }] process_second_event_s_mock.return_value = "Something" result = prepare_second_event_matches_tasks(expected_trades, second_event_dict) process_second_event_s_mock.assert_called_once_with( new_event_dict_another, second_event_dict) self.assertEqual(result, ["Something"])
def test_test_event_in_facts_relations_max_focus( self, get_fact_relation_key_dict_mock): first_vent = second_event = dict_to_event(event_dict) test_event_in_facts_relations(facts_relations, first_vent, second_event, min_relation_appearance=1, max_focus=35) self.assertEqual([ get_fact_relation_key_dict_mock.mock_calls[0], get_fact_relation_key_dict_mock.mock_calls[3], get_fact_relation_key_dict_mock.mock_calls[6] ], [ call(u'+1426794410_+1426795010_25_True'), call(u'+1427048810_+1427049110_25_True'), call(u'-1427048810_-1427049110_25_True') ]) self.assertEqual(len(get_fact_relation_key_dict_mock.mock_calls), 9)
def setUp(self): self.event_dict_55_percent = event_dict.copy() self.event_dict_55_percent.update({"percentage": 55}) self.event_55_percent = dict_to_event(self.event_dict_55_percent)