def test_get_negative_adjudication_relevancy_no_cache_has_results(self): """ Test that we can get negative 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} iqrs.rank_contrib_neg = {d0, d2} # 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_neg 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_negative_adjudication_relevancy() m_sorted.assert_called_once() expected = [(d2, 0.2), (d0, 0.1)] 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_negative_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)
def test_get_negative_adjudication_relevancy_no_cache_no_results(self): """ Test that ``get_negative_adjudication_relevancy`` returns None when in a pre-refine state when there are no negative adjudications. """ iqrs = IqrSession() assert iqrs.get_negative_adjudication_relevancy() == []
def test_get_negative_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_neg = ['simulation', 'cache'] actual = iqrs.get_negative_adjudication_relevancy() assert actual == ['simulation', 'cache'] assert id(actual) != id(iqrs._ordered_neg)