예제 #1
0
    def test_get_positive_adjudication_relevancy_no_cache_has_results(self):
        """
        Test that we can get positive adjudication relevancy scores correctly
        from a not-cached state.
        """
        iqrs = IqrSession()

        d0 = DescriptorMemoryElement('', 0).set_vector([0])
        d1 = DescriptorMemoryElement('', 1).set_vector([1])
        d2 = DescriptorMemoryElement('', 2).set_vector([2])
        d3 = DescriptorMemoryElement('', 3).set_vector([3])

        # Simulate a populated contributing adjudication state (there must be
        # some positives for a simulated post-refine state to be valid).
        iqrs.rank_contrib_pos = {d1, d3}
        iqrs.rank_contrib_neg = {d0}

        # Simulate post-refine results map.
        iqrs.results = {
            d0: 0.1,
            d1: 0.8,
            d2: 0.2,
            d3: 0.4,
        }

        # Cache is initially empty
        assert iqrs._ordered_pos is None

        # Test that the appropriate sorting actually occurs.
        with mock.patch('smqtk.iqr.iqr_session.sorted',
                        side_effect=sorted) as m_sorted:
            actual1 = iqrs.get_positive_adjudication_relevancy()
            m_sorted.assert_called_once()

        expected = [(d1, 0.8), (d3, 0.4)]
        assert actual1 == expected

        # Calling the method a second time should not result in a ``sorted``
        # operation due to caching.
        with mock.patch('smqtk.iqr.iqr_session.sorted',
                        side_effect=sorted) as m_sorted:
            actual2 = iqrs.get_positive_adjudication_relevancy()
            m_sorted.assert_not_called()

        assert actual2 == expected
        # Both returns should be shallow copies, thus not the same list
        # instances.
        assert id(actual1) != id(actual2)
예제 #2
0
 def test_get_positive_adjudication_relevancy_no_cache_no_results(self):
     """
     Test that ``get_positive_adjudication_relevancy`` returns None when in a
     pre-refine state when there are no positive adjudications.
     """
     iqrs = IqrSession()
     assert iqrs.get_positive_adjudication_relevancy() == []
예제 #3
0
    def test_get_positive_adjudication_relevancy_has_cache(self):
        """
        Test that a shallow copy of the cached list is returned if there is a
        cache.
        """
        iqrs = IqrSession()

        iqrs._ordered_pos = ['simulation', 'cache']
        actual = iqrs.get_positive_adjudication_relevancy()
        assert actual == ['simulation', 'cache']
        assert id(actual) != id(iqrs._ordered_pos)
예제 #4
0
 def test_ordered_results_has_cache(self):
     """
     Test that a shallow copy of the cached list is returned when there is
     a cache.
     """
     iqrs = IqrSession()
     # Simulate there being a cache
     iqrs._ordered_pos = ['simulated', 'cache']
     actual = iqrs.get_positive_adjudication_relevancy()
     assert actual == iqrs._ordered_pos
     assert id(actual) != id(iqrs._ordered_pos)