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
def test_tags_3(temp_file): from osxmetadata import OSXMetaData, Tag from osxmetadata.constants import kMDItemUserTags attribute = kMDItemUserTags # update tags meta = OSXMetaData(temp_file) tagset = [Tag("Test"), Tag("Green")] meta.set_attribute(attribute, tagset) tags = meta.get_attribute(attribute) assert tags == tagset meta.update_attribute(attribute, [Tag("Foo")]) tags = meta.get_attribute(attribute) assert tags == [Tag("Test"), Tag("Green"), Tag("Foo")] meta.remove_attribute(attribute, Tag("Foo")) tags = meta.get_attribute(attribute) assert tags == [Tag("Test"), Tag("Green")] meta.update_attribute(attribute, [Tag("Foo")]) tags = meta.get_attribute(attribute) assert tags == [Tag("Test"), Tag("Green"), Tag("Foo")] meta.clear_attribute(attribute) tags = meta.get_attribute(attribute) assert len(tags) == 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")
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 = True meta.set_attribute(attribute, expected) got = meta.get_attribute(attribute) assert expected == got meta.set_attribute(attribute, not expected) assert not meta.get_attribute(attribute) meta.clear_attribute(attribute) assert meta.get_attribute(attribute) is 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, "") assert not 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")
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 = datetime.datetime(2021, 7, 8) meta.set_attribute(attribute, expected) got = meta.get_attribute(attribute) assert expected == got meta.clear_attribute(attribute) assert meta.get_attribute(attribute) == None # test setting empty string meta.set_attribute(attribute, "") assert meta.get_attribute(attribute) is None 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")