Example #1
0
def test_composite_attribute_all_missing():
    media_info = cast(
        MediaInfoList,
        [{
            "track_type": "test_type",
        }],
    )

    attribute1 = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute1",
    )

    attribute2 = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute2",
    )

    composite = CompositeAttribute(attributes=[attribute1, attribute2],
                                   preferences=[],
                                   title="Composite Test")

    with pytest.raises(MissingAttributeError):
        composite.get_preference(media_info)
Example #2
0
def test_composite_attribute_one_missing():
    media_info = cast(
        MediaInfoList,
        [{
            "track_type": "test_type",
            "test_attribute2": "test",
        }],
    )

    attribute1 = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute1",
    )

    attribute2 = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute2",
    )

    composite = CompositeAttribute(attributes=[attribute1, attribute2],
                                   preferences=[],
                                   title="Composite Test")

    preference = composite.get_preference(media_info)
    assert preference.title == "test"
Example #3
0
def test_composite_attribute_concat_existing_preference():
    media_info = cast(
        MediaInfoList,
        [{
            "track_type": "test_type",
            "test_attribute1": "good",
            "test_attribute2": "test",
        }],
    )

    attribute1 = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute1",
    )

    attribute2 = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute2",
    )

    existing_preference = SinglePreference(pattern="goodtest",
                                           title="GoodTest")

    composite = CompositeAttribute(attributes=[attribute1, attribute2],
                                   preferences=[existing_preference],
                                   title="Composite Test")

    preference = composite.get_preference(media_info)
    assert preference == existing_preference
Example #4
0
def test_attribute_get_preferences():
    attribute = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute",
    )
    assert attribute.get_preferences() == []
Example #5
0
def test_attribute_get_missing_type():
    media_info = cast(
        MediaInfoList,
        [{
            "track_type": "test_type",
            "test_attribute": "test_value",
        }],
    )
    attribute = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="missing_type",
        track_attribute="test_attribute",
    )
    assert attribute.get_value(media_info) is None
Example #6
0
def test_attribute_get_preference_create_default():
    media_info = cast(
        MediaInfoList,
        [{
            "track_type": "test_type",
            "test_attribute": "test",
        }],
    )

    attribute = SingleAttribute(
        preferences=[],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute",
    )

    preference = attribute.get_preference(media_info)
    assert preference.get_title() == "test"
Example #7
0
def test_attribute_get_preference_find_existing():
    media_info = cast(
        MediaInfoList,
        [{
            "track_type": "test_type",
            "test_attribute": "test",
        }],
    )

    existing_preference = SinglePreference(pattern="test", title="Test")

    attribute = SingleAttribute(
        preferences=[existing_preference],
        title="Test Title",
        track_type="test_type",
        track_attribute="test_attribute",
    )

    preference = attribute.get_preference(media_info)
    assert preference == existing_preference