示例#1
0
def test_construction():
    """
    Test that normal construction sets the correct attributes
    """
    expected_uuid = 0
    m = mock.MagicMock(spec_set=DetectionElement)
    # noinspection PyCallByClass
    DetectionElement.__init__(m, expected_uuid)
    assert m._uuid == expected_uuid
示例#2
0
def test_from_config_override_mdTrue(m_confFromConfig):
    """
    Test that ``from_config`` appropriately passes runtime-provided UUID value.
    """
    given_conf = {}
    expected_uuid = 'test uuid'
    expected_conf = {'uuid': expected_uuid}

    DetectionElement.from_config(given_conf, expected_uuid, merge_default=True)
    m_confFromConfig.assert_called_once_with(expected_conf,
                                             merge_default=False)
示例#3
0
def test_from_config_uuid_preseed_mdTrue(m_confFromConfig):
    """
    Test that UUID provided at runtime prevails over any UUID provided
    through the config.
    """
    given_conf = {
        "uuid": "should not get through",
    }
    expected_uuid = "actually expected UUID"
    expected_conf = {'uuid': expected_uuid}

    DetectionElement.from_config(given_conf, expected_uuid, merge_default=True)
    m_confFromConfig.assert_called_once_with(expected_conf,
                                             merge_default=False)
示例#4
0
def test_setstate():
    """
    Test that __setstate__ base implementation sets the correct instance
    attributes.
    """
    expected_uuid = 'expected_uuid'
    expected_state = {'_uuid': expected_uuid}

    # Mock an instance of DetectionElement
    m = mock.MagicMock(spec_set=DetectionElement)

    # noinspection PyCallByClass
    # - for testing purposes.
    DetectionElement.__setstate__(m, expected_state)
    assert m._uuid == expected_uuid
示例#5
0
def test_get_default_config_override():
    """
    Test override of get_default_config s.t. ``uuid`` is not present in the
    result dict.
    """
    default = DetectionElement.get_default_config()
    assert 'uuid' not in default
    def from_config(cls, config_dict, merge_default=True):
        # Override from Configurable
        if merge_default:
            config_dict = merge_dict(cls.get_default_config(), config_dict)

        elem_type, elem_conf = cls_conf_from_config_dict(
            config_dict, DetectionElement.get_impls())
        return DetectionElementFactory(elem_type, elem_conf)
示例#7
0
def test_getstate():
    """
    Test that expected "state" representation is returned from __getstate__.
    """
    expected_uuid = 'expected-uuid'
    expected_state = {'_uuid': expected_uuid}

    # Mock an instance of DetectionElement with expected uuid attribute set.
    m = mock.MagicMock(spec_set=DetectionElement)
    m._uuid = expected_uuid

    actual_state = DetectionElement.__getstate__(m)
    assert actual_state == expected_state
 def get_default_config(cls):
     # Override from Configurable
     return make_default_config(DetectionElement.get_impls())