def test_finder_comments(temp_file): from osxmetadata import OSXMetaData meta = OSXMetaData(temp_file) fc = "This is my new comment" meta.findercomment = fc assert meta.findercomment == fc meta.findercomment += ", foo" fc += ", foo" assert meta.findercomment == fc # set finder comment to "" results in null string but not deleted meta.findercomment = "" assert meta.findercomment == "" meta.findercomment = "foo" assert meta.findercomment == "foo" # set finder comment to None deletes it meta.findercomment = None assert meta.findercomment == None # can we set findercomment after is was set to None? meta.findercomment = "bar" assert meta.findercomment == "bar"
def test_finder_comments(temp_file): from osxmetadata import OSXMetaData meta = OSXMetaData(temp_file) fc = "This is my new comment" meta.findercomment = fc assert meta.findercomment == fc meta.findercomment += ", foo" fc += ", foo" assert meta.findercomment == fc # set finder comment to "" deletes it as this mirrors Finder and mdls meta.findercomment = "" assert meta.findercomment is None meta.findercomment = "foo" assert meta.findercomment == "foo" # set finder comment to None deletes it meta.findercomment = None assert meta.findercomment is None # can we set findercomment after is was set to None? meta.findercomment = "bar" assert meta.findercomment == "bar"
def test_cli_verbose_short_opts(temp_file): from osxmetadata import OSXMetaData, Tag from osxmetadata.__main__ import cli TESTDIR = None source_file = NamedTemporaryFile(dir=TESTDIR) source_filename = source_file.name meta_source = OSXMetaData(source_filename) meta_source.tags = [Tag("bar")] meta_source.keywords = ["foo"] meta_source.findercomment = "Bar" meta_source.comment = "Foo" runner = CliRunner() result = runner.invoke( cli, [ "-X", "-s", "keywords", "test", "-l", "-g", "keywords", "-c", "keywords", "-r", "keywords", "test", "-u", "keywords", "foo", "-m", "keywords", "tags", "-V", "-B", "-f", source_filename, temp_file, ], ) assert result.exit_code == 0 output = result.output assert "Processing file" in output assert "No metadata to wipe from" in output assert "Copying attributes from" in output assert "Copying com.apple.metadata:_kMDItemUserTags" in output assert "Copying com.apple.metadata:kMDItemComment" in output assert "Copying com.apple.metadata:kMDItemKeywords" in output assert "Copying com.apple.metadata:kMDItemFinderComment" in output assert "Clearing keywords" in output assert "Setting keywords=test" in output assert "Updating keywords=foo" in output assert "Removing keywords" in output assert "Mirroring keywords tags" in output assert "Backing up attribute data" in output source_file.close()
def test_cli_copy_from(temp_file): # test copy from source file from osxmetadata import OSXMetaData, Tag from osxmetadata.__main__ import cli TESTDIR = None source_file = NamedTemporaryFile(dir=TESTDIR) source_filename = source_file.name meta_source = OSXMetaData(source_filename) meta_source.tags = [Tag("bar")] meta_source.keywords = ["foo"] meta_source.findercomment = "Bar" meta_source.comment = "Foo" runner = CliRunner() result = runner.invoke(cli, ["--copyfrom", source_filename, temp_file]) assert result.exit_code == 0 meta = OSXMetaData(temp_file) assert meta.tags == [Tag("bar")] assert meta.keywords == ["foo"] assert meta.findercomment == "Bar" assert meta.comment == "Foo" source_file.close()