Ejemplo n.º 1
0
    def test_write_new_date_property(self):
        """
        TODO:  fill in the doc string
        """
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = exempi.new_empty()
        self.assertFalse(exempi.get_error())

        exempi.parse(xmp, strbuffer)
        self.assertFalse(exempi.get_error())

        the_dt = datetime.datetime(2005, 12, 25, 12, 42, 42)

        exempi.set_property_date(xmp, NS_EXIF, "DateTimeOriginal", the_dt, 0)
        the_prop, _ = exempi.get_property(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual("2005-12-25T12:42:42", the_prop)

        the_prop, _ = exempi.get_property_date(xmp, NS_EXIF,
                                               "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2005)
        self.assertEqual(the_prop.minute, 42)
        self.assertEqual(
            the_prop,
            datetime.datetime(2005, 12, 25, 12, 42, 42, tzinfo=pytz.utc))

        exempi.free(xmp)
Ejemplo n.º 2
0
    def test_write_new_date_property(self):
        """
        TODO:  fill in the doc string
        """
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = exempi.new_empty()
        self.assertFalse(exempi.get_error())

        exempi.parse(xmp, strbuffer)
        self.assertFalse(exempi.get_error())

        the_dt = datetime.datetime(2005, 12, 25, 12, 42, 42)

        exempi.set_property_date(xmp, NS_EXIF, "DateTimeOriginal", the_dt, 0)
        the_prop, _ = exempi.get_property(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual("2005-12-25T12:42:42", the_prop)

        the_prop, _ = exempi.get_property_date(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2005)
        self.assertEqual(the_prop.minute, 42)
        self.assertEqual(the_prop, datetime.datetime(2005, 12, 25, 12, 42, 42,
                                   tzinfo=pytz.utc))

        exempi.free(xmp)
Ejemplo n.º 3
0
    def test_write_new_property(self):
        """Corresponds to test-write-new-property.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = exempi.new_empty()
        self.assertFalse(exempi.get_error())

        exempi.parse(xmp, strbuffer)
        self.assertFalse(exempi.get_error())

        reg_prefix = exempi.register_namespace(NS_CC, "cc")
        self.assertEqual("cc:", reg_prefix)

        reg_prefix = exempi.prefix_namespace_uri("cc")
        self.assertEqual(NS_CC, reg_prefix)

        reg_prefix = exempi.namespace_prefix(NS_CC)
        self.assertEqual("cc:", reg_prefix)

        exempi.set_property(xmp, NS_CC, "License", "Foo", 0)
        the_prop, _ = exempi.get_property(xmp, NS_CC, "License")
        self.assertEqual(the_prop, "Foo")

        the_dt = datetime.datetime(2005, 12, 25, 12, 42, 42, tzinfo=pytz.utc)
        exempi.set_property_date(xmp, NS_EXIF, "DateTimeOriginal", the_dt, 0)
        the_prop, _ = exempi.get_property(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual("2005-12-25T12:42:42", the_prop)

        the_prop, _ = exempi.get_property_date(xmp, NS_EXIF,
                                               "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2005)
        self.assertEqual(the_prop.minute, 42)
        self.assertEqual(the_prop.tzinfo, pytz.utc)

        exempi.free(xmp)
Ejemplo n.º 4
0
    def test_write_new_property(self):
        """Corresponds to test-write-new-property.cpp"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")

        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = exempi.new_empty()
        self.assertFalse(exempi.get_error())

        exempi.parse(xmp, strbuffer)
        self.assertFalse(exempi.get_error())

        reg_prefix = exempi.register_namespace(NS_CC, "cc")
        self.assertEqual("cc:", reg_prefix)

        reg_prefix = exempi.prefix_namespace_uri("cc")
        self.assertEqual(NS_CC, reg_prefix)

        reg_prefix = exempi.namespace_prefix(NS_CC)
        self.assertEqual("cc:", reg_prefix)

        exempi.set_property(xmp, NS_CC, "License", "Foo", 0)
        the_prop, _ = exempi.get_property(xmp, NS_CC, "License")
        self.assertEqual(the_prop, "Foo")

        the_dt = datetime.datetime(2005, 12, 25, 12, 42, 42, tzinfo=pytz.utc)
        exempi.set_property_date(xmp, NS_EXIF, "DateTimeOriginal", the_dt, 0)
        the_prop, _ = exempi.get_property(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual("2005-12-25T12:42:42", the_prop)

        the_prop, _ = exempi.get_property_date(xmp, NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2005)
        self.assertEqual(the_prop.minute, 42)
        self.assertEqual(the_prop.tzinfo, pytz.utc)

        exempi.free(xmp)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)