Ejemplo n.º 1
0
    def test_get_localized_text(self):
        xmp = XMPMeta()
        xmp.parse_from_str(xmpcoverage.RDFCoverage, xmpmeta_wrap=True)

        prop = xmp.get_property(xmpcoverage.NS1, "SimpleProp2")
        self.assertEqual(prop, "Simple2 value")

        ltext = xmp.get_localized_text(xmpcoverage.NS1, "ArrayProp2", 'x-one',
                                       'x-one')
        self.assertEqual(ltext, "Item2.1 value")

        del xmp
Ejemplo n.º 2
0
    def test_get_localized_text(self):
        xmp = XMPMeta()
        xmp.parse_from_str(xmpcoverage.RDFCoverage, xmpmeta_wrap=True )

        prop = xmp.get_property(xmpcoverage.NS1, "SimpleProp2" )
        self.assertEqual(prop, "Simple2 value" )

        ltext = xmp.get_localized_text(xmpcoverage.NS1,
                                       "ArrayProp2", 'x-one', 'x-one' )
        self.assertEqual(ltext, "Item2.1 value" )


        del xmp
Ejemplo n.º 3
0
    def test_get_localized_text(self):
        """
        Verify that unicode string literals are properly interpreted.
        """
        xmp = XMPMeta()
        xmp.parse_from_str(xmpcoverage.RDFCoverage, xmpmeta_wrap=True)

        prop = xmp.get_property(xmpcoverage.NS1, "SimpleProp2")
        self.assertEqual(prop, u'Simple2 value')

        ltext = xmp.get_localized_text(xmpcoverage.NS1, "ArrayProp2", 'x-one',
                                       'x-one')
        self.assertEqual(ltext, u'Item2.1 value')

        del xmp
Ejemplo n.º 4
0
def test_python_xmp_validate_add(trivial):
    with trivial.open_metadata() as xmp:
        xmp['dc:creator'] = ['Bob', 'Doug']
        xmp['dc:title'] = 'Title'
        xmp['dc:publisher'] = {'Mackenzie'}

    xmp_str = str(xmp).replace('\n', '')
    assert '<rdf:Seq><rdf:li>Bob</rdf:li><rdf:li>Doug</rdf:li>' in xmp_str
    assert '<rdf:Bag><rdf:li>Mackenzie</rdf:li>' in xmp_str

    xmpmeta = XMPMeta(xmp_str=str(xmp))
    DC = XMP_NS_DC
    assert xmpmeta.does_array_item_exist(DC, 'creator', 'Bob')
    assert xmpmeta.does_array_item_exist(DC, 'creator', 'Doug')
    assert xmpmeta.get_localized_text(DC, 'title', None, 'x-default') == 'Title'
    assert xmpmeta.does_array_item_exist(DC, 'publisher', 'Mackenzie')
Ejemplo n.º 5
0
    def test_get_localized_text(self):
        """
        Verify that unicode string literals are properly interpreted.
        """
        xmp = XMPMeta()
        xmp.parse_from_str(xmpcoverage.RDFCoverage, xmpmeta_wrap=True )

        prop = xmp.get_property(xmpcoverage.NS1, "SimpleProp2" )
        self.assertEqual(prop, u'Simple2 value' )

        ltext = xmp.get_localized_text(xmpcoverage.NS1,
                                       "ArrayProp2", 'x-one', 'x-one' )
        self.assertEqual(ltext, u'Item2.1 value' )


        del xmp
Ejemplo n.º 6
0
    def test_exempi_core(self):
        """Corresponds to test_exempi.TestExempi.test_exempi_core"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")
        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = XMPMeta()
        xmp.parse_from_str(strbuffer)

        self.assertTrue(xmp.does_property_exist(NS_TIFF, 'Make'))
        self.assertFalse(xmp.does_property_exist(NS_TIFF, 'Foo'))

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

        xmp.set_property(NS_TIFF, 'Make', 'Leica')
        prop = xmp.get_property(NS_TIFF, 'Make')
        self.assertEqual(prop, 'Leica')

        # Some tests correspond to option masks not currently returned via
        # this interface.
        item = xmp.get_localized_text(NS_DC, 'rights', None, 'x-default')
        self.assertEqual(item, "2006, Hubert Figuiere")

        xmp.set_localized_text(NS_DC, 'rights', 'en', 'en-CA', 'Foo bar')
        item = xmp.get_localized_text(NS_DC, 'rights', 'en', 'en-US')

        # Can't look at the actual lang, unlike the original test.
        self.assertEqual(item, 'Foo bar')

        xmp.delete_localized_text(NS_DC, 'rights', 'en', 'en-CA')
        self.assertFalse(xmp.does_property_exist(NS_DC, "rights[1]"))

        xmp.set_array_item(NS_DC, "creator", 2, "foo")
        xmp.append_array_item(NS_DC, "creator", "bar")

        prop = xmp.get_array_item(NS_DC, "creator", 3)
        self.assertEqual(prop, "bar")

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

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

        the_prop = xmp.get_property_datetime(NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2006) 
        self.assertEqual(the_prop.minute, 20)
        self.assertEqual(the_prop.tzinfo, pytz.utc)

        prop = xmp.get_property(NS_XAP, "Rating")
        self.assertEqual(prop, "3")

        prop = xmp.get_property_float(NS_CAMERA_RAW_SETTINGS, "SharpenRadius")
        self.assertEqual(prop, 1.0)

        xmp.set_property_float(NS_CAMERA_RAW_SETTINGS, "SharpenRadius", 2.5)
        prop = xmp.get_property_float(NS_CAMERA_RAW_SETTINGS, "SharpenRadius")
        self.assertEqual(prop, 2.5)

        prop = xmp.get_property_bool(NS_CAMERA_RAW_SETTINGS, "AlreadyApplied")
        self.assertFalse(prop)
        xmp.set_property_bool(NS_CAMERA_RAW_SETTINGS, "AlreadyApplied", True)
        prop = xmp.get_property_bool(NS_CAMERA_RAW_SETTINGS, "AlreadyApplied")
        self.assertTrue(prop)

        prop = xmp.get_property_int(NS_EXIF, "MeteringMode")
        self.assertEqual(prop, 5)
        xmp.set_property_int(NS_EXIF, "MeteringMode", 10)
        prop = xmp.get_property_long(NS_EXIF, "MeteringMode")
        self.assertEqual(prop, 10)
        xmp.set_property_long(NS_EXIF, "MeteringMode", 32)
        prop = xmp.get_property_int(NS_EXIF, "MeteringMode")
        self.assertEqual(prop, 32)
Ejemplo n.º 7
0
    def test_exempi_core(self):
        """Corresponds to test_exempi.TestExempi.test_exempi_core"""
        filename = pkg_resources.resource_filename(__name__,
                                                   "samples/test1.xmp")
        with open(filename, 'r') as fptr:
            strbuffer = fptr.read()

        xmp = XMPMeta()
        xmp.parse_from_str(strbuffer)

        self.assertTrue(xmp.does_property_exist(NS_TIFF, 'Make'))
        self.assertFalse(xmp.does_property_exist(NS_TIFF, 'Foo'))

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

        xmp.set_property(NS_TIFF, 'Make', 'Leica')
        prop = xmp.get_property(NS_TIFF, 'Make')
        self.assertEqual(prop, 'Leica')

        # Some tests correspond to option masks not currently returned via
        # this interface.
        item = xmp.get_localized_text(NS_DC, 'rights', None, 'x-default')
        self.assertEqual(item, "2006, Hubert Figuiere")

        xmp.set_localized_text(NS_DC, 'rights', 'en', 'en-CA', 'Foo bar')
        item = xmp.get_localized_text(NS_DC, 'rights', 'en', 'en-US')

        # Can't look at the actual lang, unlike the original test.
        self.assertEqual(item, 'Foo bar')

        xmp.delete_localized_text(NS_DC, 'rights', 'en', 'en-CA')
        self.assertFalse(xmp.does_property_exist(NS_DC, "rights[1]"))

        xmp.set_array_item(NS_DC, "creator", 2, "foo")
        xmp.append_array_item(NS_DC, "creator", "bar")

        prop = xmp.get_array_item(NS_DC, "creator", 3)
        self.assertEqual(prop, "bar")

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

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

        the_prop = xmp.get_property_datetime(NS_EXIF, "DateTimeOriginal")
        self.assertEqual(the_prop.year, 2006)
        self.assertEqual(the_prop.minute, 20)
        self.assertEqual(the_prop.tzinfo, pytz.utc)

        prop = xmp.get_property(NS_XAP, "Rating")
        self.assertEqual(prop, "3")

        prop = xmp.get_property_float(NS_CAMERA_RAW_SETTINGS, "SharpenRadius")
        self.assertEqual(prop, 1.0)

        xmp.set_property_float(NS_CAMERA_RAW_SETTINGS, "SharpenRadius", 2.5)
        prop = xmp.get_property_float(NS_CAMERA_RAW_SETTINGS, "SharpenRadius")
        self.assertEqual(prop, 2.5)

        prop = xmp.get_property_bool(NS_CAMERA_RAW_SETTINGS, "AlreadyApplied")
        self.assertFalse(prop)
        xmp.set_property_bool(NS_CAMERA_RAW_SETTINGS, "AlreadyApplied", True)
        prop = xmp.get_property_bool(NS_CAMERA_RAW_SETTINGS, "AlreadyApplied")
        self.assertTrue(prop)

        prop = xmp.get_property_int(NS_EXIF, "MeteringMode")
        self.assertEqual(prop, 5)
        xmp.set_property_int(NS_EXIF, "MeteringMode", 10)
        prop = xmp.get_property_long(NS_EXIF, "MeteringMode")
        self.assertEqual(prop, 10)
        xmp.set_property_long(NS_EXIF, "MeteringMode", 32)
        prop = xmp.get_property_int(NS_EXIF, "MeteringMode")
        self.assertEqual(prop, 32)