示例#1
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_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)
示例#3
0
    def test_exempi_core(self):
        """According to test-exempi-core.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")
        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()
        xmp = exempi.new_empty()
        exempi.parse(xmp, strbuffer)
        self.assertTrue(exempi.has_property(xmp, NS_TIFF, 'Make'))
        self.assertFalse(exempi.has_property(xmp, NS_TIFF, 'Foo'))

        prop, mask = exempi.get_property(xmp, NS_TIFF, 'Make')
        self.assertEqual(prop, "Canon")

        exempi.set_property(xmp, NS_TIFF, "Make", "Leica", 0)
        prop, mask = exempi.get_property(xmp, NS_TIFF, 'Make')
        self.assertEqual(prop, "Leica")

        # Retrieves xml:lang attribute value of 1st rights element
        prop, mask = exempi.get_property(xmp, NS_DC, "rights[1]/?xml:lang")
        self.assertTrue(mask & XMP_PROP_IS_QUALIFIER)

        prop, mask = exempi.get_property(xmp, NS_DC, "rights[1]")
        self.assertTrue(mask & XMP_PROP_HAS_QUALIFIERS)

        item, mask, actual_lang = exempi.get_localized_text(
            xmp, NS_DC, "rights", None, "x-default")
        self.assertEqual(item, "2006, Hubert Figuiere")
        self.assertEqual(actual_lang, "x-default")

        exempi.set_localized_text(xmp, NS_DC, "rights", "en", "en-CA",
                                  "Foo bar", 0)

        # Ask for a US alternative.
        item, mask, actual_lang = exempi.get_localized_text(
            xmp, NS_DC, "rights", "en", "en-US")
        # And we only got the "en-CA" as the only "en"
        self.assertNotEqual(actual_lang, "en-US")
        self.assertEqual(actual_lang, "en-CA")
        # Check its value
        self.assertEqual(item, "Foo bar")

        # Remove the property x-default.
        exempi.delete_localized_text(xmp, NS_DC, "rights", "en", "en-CA")
        self.assertFalse(exempi.has_property(xmp, NS_DC, "rights[1]"))
        self.assertFalse(exempi.has_property(xmp, NS_DC, "rights[1]"))

        exempi.set_array_item(xmp, NS_DC, "creator", 2, "foo", 0)
        the_prop, bits = exempi.get_array_item(xmp, NS_DC, "creator", 2)
        self.assertTrue((bits & XMP_PROP_COMPOSITE_MASK) == 0)

        exempi.append_array_item(xmp, NS_DC, "creator", 0, "bar", 0)
        the_prop, bits = exempi.get_array_item(xmp, NS_DC, "creator", 3)
        self.assertTrue((bits & XMP_PROP_COMPOSITE_MASK) == 0)
        self.assertEqual(the_prop, "bar")

        exempi.delete_property(xmp, NS_DC, "creator[3]")
        self.assertFalse(exempi.has_property(xmp, NS_DC, "creator[3]"))

        the_prop, _ = exempi.get_property(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop, "2006-12-07T23:20:43-05:00")

        # When the time information is read back, it is UTC.
        the_prop, _ = exempi.get_property_date(xmp, NS_EXIF,
                                               "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2006)
        self.assertEqual(the_prop.minute, 20)
        self.assertEqual(the_prop.tzinfo, pytz.utc)

        the_prop, _ = exempi.get_property(xmp, NS_XAP, "Rating")
        self.assertEqual(the_prop, "3")

        # testing float get set
        the_prop, _ = exempi.get_property_float(xmp, NS_CAMERA_RAW_SETTINGS,
                                                "SharpenRadius")
        self.assertEqual(the_prop, 1.0)
        exempi.set_property_float(xmp, NS_CAMERA_RAW_SETTINGS, "SharpenRadius",
                                  2.5, 0)
        the_prop, _ = exempi.get_property_float(xmp, NS_CAMERA_RAW_SETTINGS,
                                                "SharpenRadius")
        self.assertEqual(the_prop, 2.5)

        # testing bool get set
        the_prop, _ = exempi.get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS,
                                               "AlreadyApplied")
        self.assertFalse(the_prop)
        exempi.set_property_bool(xmp, NS_CAMERA_RAW_SETTINGS, "AlreadyApplied",
                                 True, 0)
        the_prop, _ = exempi.get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS,
                                               "AlreadyApplied")
        self.assertTrue(the_prop)

        # testing int get set
        the_prop, _ = exempi.get_property_int32(xmp, NS_EXIF, "MeteringMode")
        self.assertEqual(the_prop, 5)
        exempi.set_property_int32(xmp, NS_EXIF, "MeteringMode", 10, 0)
        the_prop, _ = exempi.get_property_int64(xmp, NS_EXIF, "MeteringMode")
        self.assertEqual(the_prop, 10)
        exempi.set_property_int64(xmp, NS_EXIF, "MeteringMode", 32, 0)
        the_prop, _ = exempi.get_property_int32(xmp, NS_EXIF, "MeteringMode")
        self.assertEqual(the_prop, 32)

        exempi.free(xmp)
        self.assertTrue(True)
    def test_exempi_core(self):
        """According to test-exempi-core.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")
        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()
        xmp = exempi.new_empty()
        exempi.parse(xmp, strbuffer)
        self.assertTrue(exempi.has_property(xmp, NS_TIFF, 'Make'))
        self.assertFalse(exempi.has_property(xmp, NS_TIFF, 'Foo'))

        prop, mask = exempi.get_property(xmp, NS_TIFF, 'Make')
        self.assertEqual(prop, "Canon")

        exempi.set_property(xmp, NS_TIFF, "Make", "Leica", 0)
        prop, mask = exempi.get_property(xmp, NS_TIFF, 'Make')
        self.assertEqual(prop, "Leica")

        # Retrieves xml:lang attribute value of 1st rights element
        prop, mask = exempi.get_property(xmp, NS_DC, "rights[1]/?xml:lang")
        self.assertTrue(mask & XMP_PROP_IS_QUALIFIER)

        prop, mask = exempi.get_property(xmp, NS_DC, "rights[1]")
        self.assertTrue(mask & XMP_PROP_HAS_QUALIFIERS)

        item, mask, actual_lang = exempi.get_localized_text(xmp, NS_DC,
                                                            "rights",
                                                            None, "x-default")
        self.assertEqual(item, "2006, Hubert Figuiere")
        self.assertEqual(actual_lang, "x-default")

        exempi.set_localized_text(xmp, NS_DC, "rights",
                                  "en", "en-CA", "Foo bar", 0)

        # Ask for a US alternative.
        item, mask, actual_lang = exempi.get_localized_text(xmp, NS_DC,
                                                            "rights",
                                                            "en", "en-US")
        # And we only got the "en-CA" as the only "en"
        self.assertNotEqual(actual_lang, "en-US")
        self.assertEqual(actual_lang, "en-CA")
        # Check its value
        self.assertEqual(item, "Foo bar")

        # Remove the property x-default.
        exempi.delete_localized_text(xmp, NS_DC, "rights", "en", "en-CA")
        self.assertFalse(exempi.has_property(xmp, NS_DC, "rights[1]"))
        self.assertFalse(exempi.has_property(xmp, NS_DC, "rights[1]"))

        exempi.set_array_item(xmp, NS_DC, "creator", 2, "foo", 0)
        the_prop, bits = exempi.get_array_item(xmp, NS_DC, "creator", 2)
        self.assertTrue((bits & XMP_PROP_COMPOSITE_MASK) == 0)

        exempi.append_array_item(xmp, NS_DC, "creator", 0, "bar", 0)
        the_prop, bits = exempi.get_array_item(xmp, NS_DC, "creator", 3)
        self.assertTrue((bits & XMP_PROP_COMPOSITE_MASK) == 0)
        self.assertEqual(the_prop, "bar")

        exempi.delete_property(xmp, NS_DC, "creator[3]")
        self.assertFalse(exempi.has_property(xmp, NS_DC, "creator[3]"))

        the_prop, _ = exempi.get_property(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop, "2006-12-07T23:20:43-05:00")

        # When the time information is read back, it is UTC.
        the_prop, _ = exempi.get_property_date(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2006)
        self.assertEqual(the_prop.minute, 20)
        self.assertEqual(the_prop.tzinfo, pytz.utc)

        the_prop, _ = exempi.get_property(xmp, NS_XAP, "Rating")
        self.assertEqual(the_prop, "3")

        # testing float get set
        the_prop, _ = exempi.get_property_float(xmp,
                                                NS_CAMERA_RAW_SETTINGS,
                                                "SharpenRadius")
        self.assertEqual(the_prop, 1.0)
        exempi.set_property_float(xmp, NS_CAMERA_RAW_SETTINGS,
                                  "SharpenRadius", 2.5, 0)
        the_prop, _ = exempi.get_property_float(xmp, NS_CAMERA_RAW_SETTINGS,
                                                "SharpenRadius")
        self.assertEqual(the_prop, 2.5)

        # testing bool get set
        the_prop, _ = exempi.get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS,
                                               "AlreadyApplied")
        self.assertFalse(the_prop)
        exempi.set_property_bool(xmp, NS_CAMERA_RAW_SETTINGS,
                                 "AlreadyApplied", True, 0)
        the_prop, _ = exempi.get_property_bool(xmp, NS_CAMERA_RAW_SETTINGS,
                                               "AlreadyApplied")
        self.assertTrue(the_prop)


        # testing int get set
        the_prop, _ = exempi.get_property_int32(xmp, NS_EXIF, "MeteringMode")
        self.assertEqual(the_prop, 5)
        exempi.set_property_int32(xmp, NS_EXIF, "MeteringMode", 10, 0)
        the_prop, _ = exempi.get_property_int64(xmp, NS_EXIF, "MeteringMode")
        self.assertEqual(the_prop, 10)
        exempi.set_property_int64(xmp, NS_EXIF, "MeteringMode", 32, 0)
        the_prop, _ = exempi.get_property_int32(xmp, NS_EXIF, "MeteringMode")
        self.assertEqual(the_prop, 32)


        exempi.free(xmp)
        self.assertTrue(True)