def test_set_empty_input(self): """ Test that calling ``set_classification`` with an empty dictionary raises a ValueError. """ # Mock element instance #: :type: ClassificationElement e = mock.MagicMock(spec_set=ClassificationElement) with pytest.raises(ValueError, match=r"No classification labels/values given\."): ClassificationElement.set_classification(e, {})
def test_set_no_input(self): """ Test that calling ``set_classification`` with default arguments raises a ValueError. """ # Mock element instance #: :type: ClassificationElement e = mock.MagicMock(spec_set=ClassificationElement) with pytest.raises(ValueError, match="No classification labels/values " "given\."): ClassificationElement.set_classification(e)
def test_set_kwargs(self): """ Test that passing a keyword arguments to ``set_classification`` returns the appropriately normalized dictionary. """ # Mock element instance #: :type: ClassificationElement e = mock.MagicMock(spec_set=ClassificationElement) expected_v = {'a': 1, 'b': 0} actual_v = ClassificationElement.set_classification(e, a=1, b=0) assert actual_v == expected_v
def test_set_input_dict(self): """ Test that passing a dictionary to ``set_classification`` returns the appropriately normalized dictionary. """ # Mock element instance #: :type: ClassificationElement e = mock.MagicMock(spec_set=ClassificationElement) expected_v = {1: 0, 2: 1} actual_v = ClassificationElement.set_classification(e, expected_v) assert actual_v == expected_v
def test_set_mixed(self): """ Test that passing mixed dictionary and keyword arguments to ``set_classification`` returns the appropriately normalize dictionary. """ # Mock element instance #: :type: ClassificationElement e = mock.MagicMock(spec_set=ClassificationElement) expected_v = {'a': .25, 1: .25, 'b': .25, 'd': .25} actual_v = ClassificationElement.set_classification(e, { 'a': .25, 1: .25 }, b=.25, d=.25) assert actual_v == expected_v
def test_set_nonstandard(self): """ Test that setting a set of label/confidence pairs where the confidence sums to greater than 1.0 is acceptable and returns the appropriately normalized dictionary. Many classifiers output 1-sum confidence values, but not all (e.g. CNN final layers like AlexNet). """ # Mock element instance #: :type: ClassificationElement e = mock.MagicMock(spec_set=ClassificationElement) expected_v = {'a': 1, 1: 1, 'b': 1, 'd': 1} actual_v = ClassificationElement.set_classification(e, { 'a': 1, 1: 1 }, b=1, d=1) assert actual_v == expected_v