Example #1
0
    def test_simscore_arg_forwarding(self):
        with patch.object(HPOTerm, 'similarity_score',
                          return_value=None) as mock_simscore:
            set1 = HPOSet([self.terms[0]])
            set2 = HPOSet([self.terms[1]])

            _ = HPOSet._sim_score(set1, set2)
            mock_simscore.assert_called_once_with(self.terms[1], '', '')
            mock_simscore.reset_mock()

            _ = HPOSet._sim_score(set1, set2, 'foo')
            mock_simscore.assert_called_once_with(self.terms[1], 'foo', '')
            mock_simscore.reset_mock()

            _ = HPOSet._sim_score(set1, set2, kind='foo')
            mock_simscore.assert_called_once_with(self.terms[1], 'foo', '')
            mock_simscore.reset_mock()

            _ = HPOSet._sim_score(set1, set2, 'foo', 'bar')
            mock_simscore.assert_called_once_with(self.terms[1], 'foo', 'bar')
            mock_simscore.reset_mock()

            _ = HPOSet._sim_score(set1, set2, kind='foo', method='bar')
            mock_simscore.assert_called_once_with(self.terms[1], 'foo', 'bar')
            mock_simscore.reset_mock()

            _ = HPOSet._sim_score(set1, set2, method='bar')
            mock_simscore.assert_called_once_with(self.terms[1], '', 'bar')
            mock_simscore.reset_mock()

            _ = HPOSet._sim_score(set1, set2, None, 'bar')
            mock_simscore.assert_called_once_with(self.terms[1], None, 'bar')
            mock_simscore.reset_mock()
Example #2
0
    def test_single_comparison_sim_score(self):
        with patch.object(HPOTerm,
                          'similarity_score',
                          side_effect=[5, 0.5, 2, 4, 2, 3, 1,
                                       1]) as mock_simscore:
            set1 = HPOSet([self.terms[0]])
            set2 = HPOSet([self.terms[1]])
            scores = HPOSet._sim_score(set1, set2)

            mock_simscore.assert_called_once_with(self.terms[1], '', '')
            self.assertEqual(mock_simscore.call_count, 1)
            self.assertEqual(list(scores.columns), [[5]])
            self.assertEqual(list(scores.rows), [[5]])
Example #3
0
    def test_empty_sim_score(self):
        with patch.object(HPOTerm,
                          'similarity_score',
                          side_effect=[1, 0.5, 2, 4, 2, 3, 1,
                                       1]) as mock_simscore:
            set1 = HPOSet([])
            set2 = HPOSet(self.terms[2:6])
            scores = HPOSet._sim_score(set1, set2, 'omim')
            self.assertEqual(scores._data, [])
            mock_simscore.assert_not_called()
            mock_simscore.reset_mock()

            set1 = HPOSet(self.terms[0:2])
            set2 = HPOSet([])
            scores = HPOSet._sim_score(set1, set2, 'omim')
            self.assertEqual(scores._data, [])
            mock_simscore.assert_not_called()
            mock_simscore.reset_mock()

            set1 = HPOSet([])
            set2 = HPOSet([])
            scores = HPOSet._sim_score(set1, set2, 'omim')
            self.assertEqual(scores._data, [])
            mock_simscore.assert_not_called()
Example #4
0
    def test_sim_score(self):
        with patch.object(HPOTerm,
                          'similarity_score',
                          side_effect=[1, 0.5, 2, 4, 2, 3, 1,
                                       1]) as mock_simscore:
            set1 = HPOSet(self.terms[0:2])
            set2 = HPOSet(self.terms[2:6])
            scores = HPOSet._sim_score(set1, set2)

            calls = [
                call(self.terms[2], '', ''),
                call(self.terms[3], '', ''),
                call(self.terms[4], '', ''),
                call(self.terms[5], '', '')
            ]
            mock_simscore.assert_has_calls(calls, any_order=True)
            self.assertEqual(mock_simscore.call_count, 8)
            self.assertEqual(list(scores.columns),
                             [[1, 2], [0.5, 3], [2, 1], [4, 1]])
            self.assertEqual(list(scores.rows), [[1, 0.5, 2, 4], [2, 3, 1, 1]])