Ejemplo n.º 1
0
    def test_xmpfiles_write(self):
        """According to test-xmpfiles-write.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.jpg")

        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_JPEG)

        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        xmp = exempi.files_get_new_xmp(xfptr)
        exempi.files_free(xfptr)

        with tempfile.NamedTemporaryFile(suffix=".jpg") as tfile:
            shutil.copyfile(filename, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            exempi.set_property(xmp, NS_PHOTOSHOP, "ICCProfile", "foo", 0)
            self.assertTrue(exempi.files_can_put_xmp(xfptr, xmp))
            exempi.files_put_xmp(xfptr, xmp)
            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_SAFEUPDATE)
            exempi.files_free(xfptr)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_READ)
            xmp = exempi.files_get_new_xmp(xfptr)
            the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, "ICCProfile")
            self.assertEqual("foo", the_prop)

            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.files_free(xfptr)
Ejemplo n.º 2
0
    def test_xmpfiles_write(self):
        """According to test-xmpfiles-write.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.jpg")

        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_JPEG)

        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        xmp = exempi.files_get_new_xmp(xfptr)
        exempi.files_free(xfptr)

        with tempfile.NamedTemporaryFile(suffix=".jpg") as tfile:
            shutil.copyfile(filename, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            exempi.set_property(xmp, NS_PHOTOSHOP, "ICCProfile", "foo", 0)
            self.assertTrue(exempi.files_can_put_xmp(xfptr, xmp))
            exempi.files_put_xmp(xfptr, xmp)
            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_SAFEUPDATE)
            exempi.files_free(xfptr)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_READ)
            xmp = exempi.files_get_new_xmp(xfptr)
            the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, "ICCProfile")
            self.assertEqual("foo", the_prop)

            exempi.free(xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.files_free(xfptr)
Ejemplo n.º 3
0
 def get_xmp(self, tag):
     xfptr = exempi.files_open_new(self.path, XMP_OPEN_READ)
     xmp = exempi.files_get_new_xmp(xfptr)
     the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, tag)
     exempi.free(xmp)
     exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
     exempi.files_free(xfptr)
Ejemplo n.º 4
0
 def write_xmp(self, tag, value):
     xfptr = exempi.files_open_new(self.path, XMP_OPEN_FORUPDATE)
     xmp = exempi.files_get_new_xmp(xfptr)
     if xmp is not None:
         exempi.set_property(xmp, NS_PHOTOSHOP, tag, value, 0)
         exempi.files_put_xmp(xfptr, xmp)
         exempi.free(xmp)
     exempi.files_close(xfptr, XMP_CLOSE_SAFEUPDATE)
     exempi.files_free(xfptr)
Ejemplo n.º 5
0
 def test_bgo(self):
     """Corresponds to test-bgo.cpp
     """
     filename = pkg_resources.resource_filename(__name__,
                                                "samples/fdo18635.jpg")
     xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
     xmp = exempi.files_get_new_xmp(xfptr)
     exempi.free(xmp)
     exempi.files_free(xfptr)
     self.assertTrue(True)
Ejemplo n.º 6
0
 def test_bgo(self):
     """Corresponds to test-bgo.cpp
     """
     filename = pkg_resources.resource_filename(__name__,
                                                "samples/fdo18635.jpg")
     xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
     xmp = exempi.files_get_new_xmp(xfptr)
     exempi.free(xmp)
     exempi.files_free(xfptr)
     self.assertTrue(True)
Ejemplo n.º 7
0
    def test_bad_formats(self):
        """Verify check_file_format on PDF, Adobe Illustrator, XMP."""
        # Issue 26
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.pdf")
        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_PDF)
        exempi.files_free(xfptr)

        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.ai")
        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_ILLUSTRATOR)
        exempi.files_free(xfptr)

        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.xmp")
        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_XML)
        exempi.files_free(xfptr)
Ejemplo n.º 8
0
    def test_bad_formats(self):
        """Verify check_file_format on PDF, Adobe Illustrator, XMP."""
        # Issue 26
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.pdf")
        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_PDF)
        exempi.files_free(xfptr)

        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.ai")
        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_ILLUSTRATOR)
        exempi.files_free(xfptr)

        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.xmp")
        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_XML)
        exempi.files_free(xfptr)
Ejemplo n.º 9
0
    def test_tiff_leak(self):
        """Corresponds to test-tiff-leak.cpp"""
        orig_file = pkg_resources.resource_filename(__name__,
                                                    "samples/BlueSquare.tif")

        with tempfile.NamedTemporaryFile(suffix='.tif') as tfile:
            shutil.copyfile(orig_file, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            xmp = exempi.files_get_new_xmp(xfptr)
            exempi.set_localized_text(xmp, NS_DC, "description", "en", "en-US",
                                      "foo", 0)
            exempi.files_put_xmp(xfptr, xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.free(xmp)
            exempi.files_free(xfptr)
        self.assertTrue(True)
Ejemplo n.º 10
0
    def test_tiff_leak(self):
        """Corresponds to test-tiff-leak.cpp"""
        orig_file = pkg_resources.resource_filename(__name__,
                                                    "samples/BlueSquare.tif")

        with tempfile.NamedTemporaryFile(suffix='.tif') as tfile:
            shutil.copyfile(orig_file, tfile.name)

            xfptr = exempi.files_open_new(tfile.name, XMP_OPEN_FORUPDATE)

            xmp = exempi.files_get_new_xmp(xfptr)
            exempi.set_localized_text(xmp, NS_DC, "description", "en", "en-US",
                                      "foo", 0)
            exempi.files_put_xmp(xfptr, xmp)
            exempi.files_close(xfptr, XMP_CLOSE_NOOPTION)
            exempi.free(xmp)
            exempi.files_free(xfptr)
        self.assertTrue(True)
    def test_xmp_files(self):
        """Corresponds to test_xmp_files.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/BlueSquare.jpg")

        xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
        fmt = exempi.files_check_file_format(filename)
        self.assertEqual(fmt, libxmp.consts.XMP_FT_JPEG)

        file_path, options, file_format, flags = exempi.files_get_file_info(xfptr)
        self.assertEqual(options, XMP_OPEN_READ)
        self.assertEqual(file_format, libxmp.consts.XMP_FT_JPEG)
        self.assertEqual(flags, 0x27f)  # 0x27f?
        self.assertEqual(filename, file_path)

        xmp = exempi.files_get_xmp(xfptr)
        the_prop, _ = exempi.get_property(xmp, NS_PHOTOSHOP, "ICCProfile")
        self.assertEqual(the_prop, "sRGB IEC61966-2.1")
        exempi.files_free(xfptr)
 def test_formats(self):
     """Verify that check_file_format function works as expected."""
     pairs = { 'avi':  libxmp.consts.XMP_FT_AVI,
               'eps':  libxmp.consts.XMP_FT_EPS,
               'gif':  libxmp.consts.XMP_FT_GIF,
               'indd': libxmp.consts.XMP_FT_INDESIGN,
               'jpg':  libxmp.consts.XMP_FT_JPEG,
               'mov':  libxmp.consts.XMP_FT_MOV,
               'mp3':  libxmp.consts.XMP_FT_MP3,
               'png':  libxmp.consts.XMP_FT_PNG,
               'psd':  libxmp.consts.XMP_FT_PHOTOSHOP,
               'tif':  libxmp.consts.XMP_FT_TIFF,
               'wav':  libxmp.consts.XMP_FT_WAV,
               }
     for suffix, expected_format in pairs.items():
         relpath = os.path.join('samples', 'BlueSquare' + '.' + suffix)
         filename = pkg_resources.resource_filename(__name__, relpath)
         xfptr = exempi.files_open_new(filename, XMP_OPEN_READ)
         actual_format = exempi.files_check_file_format(filename)
         self.assertEqual(actual_format, expected_format)
         exempi.files_free(xfptr)
Ejemplo n.º 13
0
 def test_file_not_there_open_new(self):
     """
     The library does not catch comfortably, so we perform our own check.
     """
     with self.assertRaises(IOError):
         xfptr = exempi.files_open_new('notthere.xmp', XMP_OPEN_READ)
Ejemplo n.º 14
0
 def test_file_not_there_open_new(self):
     """
     The library does not catch comfortably, so we perform our own check.
     """
     with self.assertRaises(IOError):
         xfptr = exempi.files_open_new('notthere.xmp', XMP_OPEN_READ)