예제 #1
0
def test_list_attribute(temp_file, attribute):
    """test set_attribute, get_attribute, etc for list items"""
    from osxmetadata import OSXMetaData

    meta = OSXMetaData(temp_file)
    expected = ["Foo"]
    meta.set_attribute(attribute, expected)
    got = meta.get_attribute(attribute)
    assert expected == got

    expected += ["Bar"]
    meta.append_attribute(attribute, ["Bar"])
    assert meta.get_attribute(attribute) == expected

    expected.remove("Bar")
    meta.remove_attribute(attribute, "Bar")
    assert meta.get_attribute(attribute) == expected

    with pytest.raises(ValueError):
        meta.remove_attribute(attribute, "Bar")

    expected += ["Flooz"]
    meta.update_attribute(attribute, ["Flooz"])
    assert meta.get_attribute(attribute) == expected

    meta.discard_attribute(attribute, "foo")
    assert meta.get_attribute(attribute) == expected

    meta.clear_attribute(attribute)
    assert meta.get_attribute(attribute) is None

    expected = ["Foo"]
    meta.set_attribute(attribute, expected)
    got = meta.get_attribute(attribute)
    assert expected == got
예제 #2
0
def test_str_attribute(temp_file, attribute):
    """test set_attribute, get_attribute, etc"""
    from osxmetadata import OSXMetaData
    from osxmetadata.constants import _FINDER_COMMENT_NAMES

    meta = OSXMetaData(temp_file)
    expected = 2
    meta.set_attribute(attribute, expected)
    got = meta.get_attribute(attribute)
    assert expected == got

    expected += 1
    meta.append_attribute(attribute, 1)
    assert meta.get_attribute(attribute) == expected

    meta.clear_attribute(attribute)
    assert meta.get_attribute(attribute) is None

    with pytest.raises(TypeError):
        meta.set_attribute(attribute, "")

    with pytest.raises(TypeError):
        meta.update_attribute(attribute, "foo")

    with pytest.raises(TypeError):
        meta.discard_attribute(attribute, "foo")

    with pytest.raises(TypeError):
        meta.remove_attribute(attribute, "foo")
예제 #3
0
    def add_meta_info(self, path_to_image):
        # obj to manipulate the metadata
        if path_to_image is not None:
            meta = OSXMetaData(path_to_image)

            # set description
            meta.append_attribute(
                'findercomment',
                '{}\n{}\n{}\n{}\n{}'.format(self.title, self.author,
                                            self.score,
                                            'www.reddit.com' + self.permalink,
                                            self.url))
def test_str_attribute(temp_file, attribute):
    """ test set_attribute, get_attribute, etc """
    from osxmetadata import OSXMetaData
    from osxmetadata.constants import _FINDER_COMMENT_NAMES

    meta = OSXMetaData(temp_file)
    expected = "Foo"
    meta.set_attribute(attribute, expected)
    got = meta.get_attribute(attribute)
    assert expected == got

    expected += " Bar"
    meta.append_attribute(attribute, " Bar")
    assert meta.get_attribute(attribute) == expected

    meta.clear_attribute(attribute)
    assert meta.get_attribute(attribute) == None

    # test setting empty string
    # setting finder comment to empty string clears it
    # but other fields get set to empty string
    # this mirrors the way finder comments work in mdls
    meta.set_attribute(attribute, "")
    if attribute in _FINDER_COMMENT_NAMES:
        assert meta.get_attribute(attribute) == None
    else:
        assert meta.get_attribute(attribute) == ""

    with pytest.raises(AttributeError):
        meta.update_attribute(attribute, "foo")

    with pytest.raises(TypeError):
        meta.discard_attribute(attribute, "foo")

    with pytest.raises(TypeError):
        meta.remove_attribute(attribute, "foo")