Esempio n. 1
0
 def test_setitem(self):
     self.metadata.read()
     # Set new tags
     key = 'Exif.Photo.ExposureBiasValue'
     tag = ExifTag(key, make_fraction(0, 3))
     self.metadata[key] = tag
     self.failUnless(key in self.metadata._tags['exif'])
     self.failUnlessEqual(self.metadata._tags['exif'][key], tag)
     key = 'Iptc.Application2.City'
     tag = IptcTag(key, ['Barcelona'])
     self.metadata[key] = tag
     self.failUnless(key in self.metadata._tags['iptc'])
     self.failUnlessEqual(self.metadata._tags['iptc'][key], tag)
     key = 'Xmp.dc.description'
     tag = XmpTag(key, {'x-default': 'Sunset picture.'})
     self.metadata[key] = tag
     self.failUnless(key in self.metadata._tags['xmp'])
     self.failUnlessEqual(self.metadata._tags['xmp'][key], tag)
     # Replace existing tags
     key = 'Exif.Photo.ExifVersion'
     tag = ExifTag(key, '0220')
     self.metadata[key] = tag
     self.failUnless(key in self.metadata._tags['exif'])
     self.failUnlessEqual(self.metadata._tags['exif'][key], tag)
     key = 'Iptc.Application2.Caption'
     tag = IptcTag(key, ['Sunset on Barcelona.'])
     self.metadata[key] = tag
     self.failUnless(key in self.metadata._tags['iptc'])
     self.failUnlessEqual(self.metadata._tags['iptc'][key], tag)
     key = 'Xmp.dc.subject'
     tag = XmpTag(key, ['sunset', 'Barcelona', 'beautiful', 'beach'])
     self.metadata[key] = tag
     self.failUnless(key in self.metadata._tags['xmp'])
     self.failUnlessEqual(self.metadata._tags['xmp'][key], tag)
Esempio n. 2
0
def test_setitem(metadata_ro):
    m = metadata_ro.metadata
    m.read()
    # Set new tags
    key = 'Exif.Photo.ExposureBiasValue'
    tag = ExifTag(key, make_fraction(0, 3))
    m[key] = tag
    assert key in m._tags['exif']
    assert m._tags['exif'][key] == tag
    key = 'Iptc.Application2.City'
    tag = IptcTag(key, ['Barcelona'])
    m[key] = tag
    assert key in m._tags['iptc']
    assert m._tags['iptc'][key] == tag
    key = 'Xmp.dc.description'
    tag = XmpTag(key, {'x-default': 'Sunset picture.'})
    m[key] = tag
    assert key in m._tags['xmp']
    assert m._tags['xmp'][key] == tag
    # Replace existing tags
    key = 'Exif.Photo.ExifVersion'
    tag = ExifTag(key, '0220')
    m[key] = tag
    assert key in m._tags['exif']
    assert m._tags['exif'][key] == tag
    key = 'Iptc.Application2.Caption'
    tag = IptcTag(key, ['Sunset on Barcelona.'])
    m[key] = tag
    assert key in m._tags['iptc']
    assert m._tags['iptc'][key] == tag
    key = 'Xmp.dc.subject'
    tag = XmpTag(key, ['sunset', 'Barcelona', 'beautiful', 'beach'])
    m[key] = tag
    assert key in m._tags['xmp']
    assert m._tags['xmp'][key] == tag
Esempio n. 3
0
 def test_set_value_empty(self):
     tag = XmpTag('Xmp.dc.creator')
     self.assertEqual(tag.type, 'seq ProperName')
     self.assertRaises(ValueError, setattr, tag, 'value', [])
     tag = XmpTag('Xmp.dc.title')
     self.assertEqual(tag.type, 'Lang Alt')
     self.assertRaises(ValueError, setattr, tag, 'value', {})
Esempio n. 4
0
 def test_convert_to_python_bag(self):
     # Valid values
     tag = XmpTag('Xmp.dc.subject')
     self.assertEqual(tag.type, 'bag Text')
     self.assertEqual(tag._convert_to_python('', 'Text'), u'')
     self.assertEqual(tag._convert_to_python('One value only', 'Text'),
                      u'One value only')
Esempio n. 5
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_bag(self):
     # Valid values
     tag = XmpTag('Xmp.dc.subject')
     self.assertEqual(tag.type, 'bag Text')
     self.assertEqual(tag._convert_to_python('', 'Text'), u'')
     self.assertEqual(tag._convert_to_python('One value only', 'Text'),
                      u'One value only')
Esempio n. 6
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_propername(self):
     # Valid values
     tag = XmpTag('Xmp.photoshop.CaptionWriter')
     self.assertEqual(tag.type, 'ProperName')
     self.assertEqual(tag._convert_to_python('Gérard', 'ProperName'), u'Gérard')
     self.assertEqual(tag._convert_to_python('Python Software Foundation', 'ProperName'), u'Python Software Foundation')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, None, 'ProperName')
Esempio n. 7
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_url(self):
     # Valid values
     tag = XmpTag('Xmp.xmp.BaseURL')
     self.assertEqual(tag.type, 'URL')
     self.assertEqual(tag._convert_to_python('http://example.com', 'URL'), 'http://example.com')
     self.assertEqual(tag._convert_to_python('https://example.com', 'URL'), 'https://example.com')
     self.assertEqual(tag._convert_to_python('http://localhost:8000/resource', 'URL'),
                      'http://localhost:8000/resource')
Esempio n. 8
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_boolean(self):
     # Valid values
     tag = XmpTag('Xmp.xmpRights.Marked')
     self.assertEqual(tag.type, 'Boolean')
     self.assertEqual(tag._convert_to_string(True, 'Boolean'), 'True')
     self.assertEqual(tag._convert_to_string(False, 'Boolean'), 'False')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'Boolean')
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, None, 'Boolean')
Esempio n. 9
0
 def test_convert_to_string_bag(self):
     # Valid values
     tag = XmpTag('Xmp.dc.Subject')
     self.assertEqual(tag._convert_to_string('', 'Text'), b'')
     self.assertEqual(tag._convert_to_string('One value only', 'Text'),
                      b'One value only')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, [1, 2, 3],
                       'Text')
Esempio n. 10
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_boolean(self):
     # Valid values
     tag = XmpTag('Xmp.xmpRights.Marked')
     self.assertEqual(tag.type, 'Boolean')
     self.assertEqual(tag._convert_to_python('True', 'Boolean'), True)
     self.assertEqual(tag._convert_to_python('False', 'Boolean'), False)
     # Invalid values: not converted
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, 'invalid', 'Boolean')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, None, 'Boolean')
Esempio n. 11
0
File: xmp.py Progetto: Namejs/workr
    def test_convert_to_string_rational(self):
        # Valid values
        tag = XmpTag('Xmp.xmpDM.videoPixelAspectRatio')
        self.assertEqual(tag.type, 'Rational')
        self.assertEqual(tag._convert_to_string(make_fraction(5, 3), 'Rational'), '5/3')
        self.assertEqual(tag._convert_to_string(make_fraction(-5, 3), 'Rational'), '-5/3')

        # Invalid values
        self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'Rational')
Esempio n. 12
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_bag(self):
     # Valid values
     tag = XmpTag('Xmp.dc.subject')
     self.assertEqual(tag.type, 'bag Text')
     self.assertEqual(tag._convert_to_string(u'', 'Text'), '')
     self.assertEqual(tag._convert_to_string('One value only', 'Text'), 'One value only')
     self.assertEqual(tag._convert_to_string(u'One value only', 'Text'), 'One value only')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, [1, 2, 3], 'Text')
Esempio n. 13
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_integer(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.SaveID')
     self.assertEqual(tag.type, 'Integer')
     self.assertEqual(tag._convert_to_string(123, 'Integer'), '123')
     self.assertEqual(tag._convert_to_string(-57, 'Integer'), '-57')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'Integer')
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, 3.14, 'Integer')
Esempio n. 14
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_text(self):
     # Valid values
     tag = XmpTag('Xmp.dc.source')
     self.assertEqual(tag.type, 'Text')
     self.assertEqual(tag._convert_to_python('Some text.', 'Text'), u'Some text.')
     self.assertEqual(tag._convert_to_python('Some text with exotic chàräctérʐ.', 'Text'),
                      u'Some text with exotic chàräctérʐ.')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, None, 'Text')
Esempio n. 15
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_mimetype(self):
     # Valid values
     tag = XmpTag('Xmp.dc.format')
     self.assertEqual(tag.type, 'MIMEType')
     self.assertEqual(tag._convert_to_string(('image', 'jpeg'), 'MIMEType'), 'image/jpeg')
     self.assertEqual(tag._convert_to_string(('video', 'ogg'), 'MIMEType'), 'video/ogg')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'MIMEType')
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, ('image',), 'MIMEType')
Esempio n. 16
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_uri(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.DocumentID')
     self.assertEqual(tag.type, 'URI')
     self.assertEqual(tag._convert_to_python('http://example.com', 'URI'), 'http://example.com')
     self.assertEqual(tag._convert_to_python('https://example.com', 'URI'), 'https://example.com')
     self.assertEqual(tag._convert_to_python('http://localhost:8000/resource', 'URI'),
                      'http://localhost:8000/resource')
     self.assertEqual(tag._convert_to_python('uuid:9A3B7F52214211DAB6308A7391270C13', 'URI'),
                      'uuid:9A3B7F52214211DAB6308A7391270C13')
Esempio n. 17
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_url(self):
     # Valid values
     tag = XmpTag('Xmp.xmp.BaseURL')
     self.assertEqual(tag.type, 'URL')
     self.assertEqual(tag._convert_to_string('http://example.com', 'URL'), 'http://example.com')
     self.assertEqual(tag._convert_to_string(u'http://example.com', 'URL'), 'http://example.com')
     self.assertEqual(tag._convert_to_string('https://example.com', 'URL'), 'https://example.com')
     self.assertEqual(tag._convert_to_string('http://localhost:8000/resource', 'URL'),
                      'http://localhost:8000/resource')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, None, 'URL')
Esempio n. 18
0
 def _set_xmp_tag(self, key, tag_or_value):
     # Set an XMP tag. If the tag already exists, its value is overwritten.
     if isinstance(tag_or_value, XmpTag):
         tag = tag_or_value
     else:
         # As a handy shortcut, accept direct value assignment.
         tag = XmpTag(key, tag_or_value)
     tag._set_owner(self)
     self._tags['xmp'][tag.key] = tag
     if tag.key not in self.xmp_keys:
         self._keys['xmp'].append(tag.key)
Esempio n. 19
0
 def _set_xmp_tag(self, key, tag_or_value):
     # Set an XMP tag. If the tag already exists, its value is overwritten.
     if isinstance(tag_or_value, XmpTag):
         tag = tag_or_value
     else:
         # As a handy shortcut, accept direct value assignment.
         tag = XmpTag(key, tag_or_value)
     tag._set_owner(self)
     self._tags['xmp'][tag.key] = tag
     if tag.key not in self.xmp_keys:
         self._keys['xmp'].append(tag.key)
Esempio n. 20
0
 def test_convert_to_python_boolean(self):
     # Valid values
     tag = XmpTag('Xmp.xmpRights.Marked')
     self.assertEqual(tag.type, 'Boolean')
     self.assertEqual(tag._convert_to_python('True', 'Boolean'), True)
     self.assertEqual(tag._convert_to_python('False', 'Boolean'), False)
     # Invalid values: not converted
     self.assertRaises(XmpValueError, tag._convert_to_python, 'invalid',
                       'Boolean')
     self.assertRaises(XmpValueError, tag._convert_to_python, None,
                       'Boolean')
Esempio n. 21
0
 def test_set_value_incorrect_type(self):
     # Expecting a list of values
     tag = XmpTag('Xmp.dc.publisher')
     self.assertEqual(tag.type, 'bag ProperName')
     self.assertRaises(TypeError, setattr, tag, 'value', None)
     self.assertRaises(TypeError, setattr, tag, 'value', 'bleh')
     # Expecting a dictionary mapping language codes to values
     tag = XmpTag('Xmp.dc.description')
     self.assertEqual(tag.type, 'Lang Alt')
     self.assertRaises(TypeError, setattr, tag, 'value', None)
     self.assertRaises(TypeError, setattr, tag, 'value', ['bleh'])
Esempio n. 22
0
 def test_convert_to_string_integer(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.SaveID')
     self.assertEqual(tag.type, 'Integer')
     self.assertEqual(tag._convert_to_string(123, 'Integer'), '123')
     self.assertEqual(tag._convert_to_string(-57, 'Integer'), '-57')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, 'invalid',
                       'Integer')
     self.assertRaises(XmpValueError, tag._convert_to_string, 3.14,
                       'Integer')
Esempio n. 23
0
 def test_convert_to_string_text(self):
     # Valid values
     tag = XmpTag('Xmp.dc.Source')
     self.assertEqual(tag._convert_to_string('Some text', 'Text'),
                      b'Some text')
     self.assertEqual(
         tag._convert_to_string('Some text with exotic chàräctérʐ.',
                                'Text'),
         b'Some text with exotic ch\xc3\xa0r\xc3\xa4ct\xc3\xa9r\xca\x90.')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, None, 'Text')
Esempio n. 24
0
def test_set_value():
    tag = XmpTag('Xmp.xmp.ModifyDate', DT(2005,
                                          9,
                                          7,
                                          15,
                                          9,
                                          51,
                                          tz=('-', 7, 0)))
    old_value = tag.value
    tag.value = DT(2009, 4, 22, 8, 30, 27)
    assert tag.value != old_value
Esempio n. 25
0
 def test_convert_to_python_url(self):
     # Valid values
     tag = XmpTag('Xmp.xmp.BaseURL')
     self.assertEqual(tag.type, 'URL')
     self.assertEqual(tag._convert_to_python('http://example.com', 'URL'),
                      'http://example.com')
     self.assertEqual(tag._convert_to_python('https://example.com', 'URL'),
                      'https://example.com')
     self.assertEqual(
         tag._convert_to_python('http://localhost:8000/resource', 'URL'),
         'http://localhost:8000/resource')
Esempio n. 26
0
 def test_convert_to_string_url(self):
     # Valid values
     tag = XmpTag('Xmp.xmp.BaseURL')
     self.assertEqual(tag.type, 'URL')
     self.assertEqual(tag._convert_to_string('http://example.com', 'URL'),
                      b'http://example.com')
     self.assertEqual(
         tag._convert_to_string('http://localhost:8000/resource', 'URL'),
         b'http://localhost:8000/resource')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, None, 'URL')
Esempio n. 27
0
 def test_convert_to_string_boolean(self):
     # Valid values
     tag = XmpTag('Xmp.xmpRights.Marked')
     self.assertEqual(tag.type, 'Boolean')
     self.assertEqual(tag._convert_to_string(True, 'Boolean'), 'True')
     self.assertEqual(tag._convert_to_string(False, 'Boolean'), 'False')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, 'invalid',
                       'Boolean')
     self.assertRaises(XmpValueError, tag._convert_to_string, None,
                       'Boolean')
Esempio n. 28
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_integer(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.SaveID')
     self.assertEqual(tag.type, 'Integer')
     self.assertEqual(tag._convert_to_python('23', 'Integer'), 23)
     self.assertEqual(tag._convert_to_python('+5628', 'Integer'), 5628)
     self.assertEqual(tag._convert_to_python('-4', 'Integer'), -4)
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, 'abc', 'Integer')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '5,64', 'Integer')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '47.0001', 'Integer')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '1E3', 'Integer')
Esempio n. 29
0
 def test_convert_to_string_propername(self):
     # Valid values
     tag = XmpTag('Xmp.photoshop.CaptionWriter')
     self.assertEqual(tag.type, 'ProperName')
     self.assertEqual(tag._convert_to_string('Gérard', 'ProperName'),
                      b'G\xc3\xa9rard')
     self.assertEqual(
         tag._convert_to_string('Python Software Foundation', 'ProperName'),
         b'Python Software Foundation')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, None,
                       'ProperName')
Esempio n. 30
0
 def test_convert_to_python_text(self):
     # Valid values
     tag = XmpTag('Xmp.dc.source')
     self.assertEqual(tag.type, 'Text')
     self.assertEqual(tag._convert_to_python('Some text.', 'Text'),
                      'Some text.')
     self.assertEqual(
         tag._convert_to_python(
             b'Some text with exotic ch\xc3\xa0r\xc3\xa4ct\xc3\xa9r\xca\x90.',
             'Text'), 'Some text with exotic chàräctérʐ.')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_python(None, 'Text'))
Esempio n. 31
0
 def test_convert_to_python_propername(self):
     # Valid values
     tag = XmpTag('Xmp.photoshop.CaptionWriter')
     self.assertEqual(tag.type, 'ProperName')
     self.assertEqual(tag._convert_to_python('Gérard', 'ProperName'),
                      u'Gérard')
     self.assertEqual(
         tag._convert_to_python('Python Software Foundation', 'ProperName'),
         u'Python Software Foundation')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, None,
                           'ProperName')
Esempio n. 32
0
 def test_convert_to_string_bag(self):
     # Valid values
     tag = XmpTag('Xmp.dc.subject')
     self.assertEqual(tag.type, 'bag Text')
     self.assertEqual(tag._convert_to_string(u'', 'Text'), '')
     self.assertEqual(tag._convert_to_string('One value only', 'Text'),
                      'One value only')
     self.assertEqual(tag._convert_to_string(u'One value only', 'Text'),
                      'One value only')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, [1, 2, 3],
                           'Text')
Esempio n. 33
0
    def test_convert_to_string_rational(self):
        # Valid values
        tag = XmpTag('Xmp.xmpDM.videoPixelAspectRatio')
        self.assertEqual(tag.type, 'Rational')
        self.assertEqual(
            tag._convert_to_string(make_fraction(5, 3), 'Rational'), '5/3')
        self.assertEqual(
            tag._convert_to_string(make_fraction(-5, 3), 'Rational'), '-5/3')

        # Invalid values
        self.assertRaises(XmpValueError, tag._convert_to_string, 'invalid',
                          'Rational')
Esempio n. 34
0
 def test_convert_to_python_text(self):
     # Valid values
     tag = XmpTag('Xmp.dc.source')
     self.assertEqual(tag.type, 'Text')
     self.assertEqual(tag._convert_to_python('Some text.', 'Text'),
                      u'Some text.')
     self.assertEqual(
         tag._convert_to_python('Some text with exotic chàräctérʐ.',
                                'Text'),
         u'Some text with exotic chàräctérʐ.')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, None,
                           'Text')
Esempio n. 35
0
 def test_convert_to_string_date_with_real_timezones(self):
     if pytz is None:
         # Poor man’s test skipping. Starting with Python 2.7, decorators are
         # available to implement this in a cleaner fashion
         # (http://docs.python.org/library/unittest.html#unittest-skipping).
         print 'Install python-tz to run this test. Skipping.'
         return
     tag = XmpTag('Xmp.xmp.CreateDate')
     self.assertEqual(tag.type, 'Date')
     t = pytz.timezone('UTC').localize(datetime.datetime(2011, 2, 2, 10, 52, 4))
     self.assertEqual(tag._convert_to_string(t, 'Date'), '2011-02-02T10:52:04Z')
     t = pytz.timezone('CET').localize(datetime.datetime(2011, 2, 2, 10, 52, 4))
     self.assertEqual(tag._convert_to_string(t, 'Date'), '2011-02-02T10:52:04+01:00')
Esempio n. 36
0
 def test_convert_to_python_mimetype(self):
     # Valid values
     tag = XmpTag('Xmp.dc.format')
     self.assertEqual(tag.type, 'MIMEType')
     self.assertEqual(tag._convert_to_python('image/jpeg', 'MIMEType'),
                      ('image', 'jpeg'))
     self.assertEqual(tag._convert_to_python('video/ogg', 'MIMEType'),
                      ('video', 'ogg'))
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, 'invalid',
                           'MIMEType')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python,
                           'image-jpeg', 'MIMEType')
Esempio n. 37
0
 def test_convert_to_string_mimetype(self):
     # Valid values
     tag = XmpTag('Xmp.dc.format')
     self.assertEqual(tag.type, 'MIMEType')
     self.assertEqual(tag._convert_to_string(('image', 'jpeg'), 'MIMEType'),
                      'image/jpeg')
     self.assertEqual(tag._convert_to_string(('video', 'ogg'), 'MIMEType'),
                      'video/ogg')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, 'invalid',
                       'MIMEType')
     self.assertRaises(XmpValueError, tag._convert_to_string, ('image', ),
                       'MIMEType')
Esempio n. 38
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_uri(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.DocumentID')
     self.assertEqual(tag.type, 'URI')
     self.assertEqual(tag._convert_to_string('http://example.com', 'URI'), 'http://example.com')
     self.assertEqual(tag._convert_to_string(u'http://example.com', 'URI'), 'http://example.com')
     self.assertEqual(tag._convert_to_string('https://example.com', 'URI'), 'https://example.com')
     self.assertEqual(tag._convert_to_string('http://localhost:8000/resource', 'URI'),
                      'http://localhost:8000/resource')
     self.assertEqual(tag._convert_to_string('uuid:9A3B7F52214211DAB6308A7391270C13', 'URI'),
                      'uuid:9A3B7F52214211DAB6308A7391270C13')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, None, 'URI')
Esempio n. 39
0
 def test_convert_to_string_uri(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.DocumentID')
     self.assertEqual(tag.type, 'URI')
     self.assertEqual(tag._convert_to_string('http://example.com', 'URI'),
                      b'http://example.com')
     self.assertEqual(
         tag._convert_to_string('http://localhost:8000/resource', 'URI'),
         b'http://localhost:8000/resource')
     self.assertEqual(
         tag._convert_to_string('uuid:9A3B7F52214211DAB6308A7391270C13',
                                'URI'),
         b'uuid:9A3B7F52214211DAB6308A7391270C13')
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_string, None, 'URI')
Esempio n. 40
0
    def test_convert_to_python_rational(self):
        # Valid values
        tag = XmpTag('Xmp.xmpDM.videoPixelAspectRatio')
        self.assertEqual(tag.type, 'Rational')
        self.assertEqual(tag._convert_to_python('5/3', 'Rational'),
                         make_fraction(5, 3))
        self.assertEqual(tag._convert_to_python('-5/3', 'Rational'),
                         make_fraction(-5, 3))

        # Invalid values
        self.failUnlessRaises(XmpValueError, tag._convert_to_python, 'invalid',
                              'Rational')
        self.failUnlessRaises(XmpValueError, tag._convert_to_python, '5 / 3',
                              'Rational')
        self.failUnlessRaises(XmpValueError, tag._convert_to_python, '5/-3',
                              'Rational')
Esempio n. 41
0
 def test_convert_to_python_integer(self):
     # Valid values
     tag = XmpTag('Xmp.xmpMM.SaveID')
     self.assertEqual(tag.type, 'Integer')
     self.assertEqual(tag._convert_to_python('23', 'Integer'), 23)
     self.assertEqual(tag._convert_to_python('+5628', 'Integer'), 5628)
     self.assertEqual(tag._convert_to_python('-4', 'Integer'), -4)
     # Invalid values
     self.assertRaises(XmpValueError, tag._convert_to_python, 'abc',
                       'Integer')
     self.assertRaises(XmpValueError, tag._convert_to_python, '5,64',
                       'Integer')
     self.assertRaises(XmpValueError, tag._convert_to_python, '47.0001',
                       'Integer')
     self.assertRaises(XmpValueError, tag._convert_to_python, '1E3',
                       'Integer')
Esempio n. 42
0
 def test_convert_to_string_date_with_real_timezones(self):
     if pytz is None:
         # Poor man’s test skipping. Starting with Python 2.7, decorators are
         # available to implement this in a cleaner fashion
         # (http://docs.python.org/library/unittest.html#unittest-skipping).
         print 'Install python-tz to run this test. Skipping.'
         return
     tag = XmpTag('Xmp.xmp.CreateDate')
     self.assertEqual(tag.type, 'Date')
     t = pytz.timezone('UTC').localize(
         datetime.datetime(2011, 2, 2, 10, 52, 4))
     self.assertEqual(tag._convert_to_string(t, 'Date'),
                      '2011-02-02T10:52:04Z')
     t = pytz.timezone('CET').localize(
         datetime.datetime(2011, 2, 2, 10, 52, 4))
     self.assertEqual(tag._convert_to_string(t, 'Date'),
                      '2011-02-02T10:52:04+01:00')
Esempio n. 43
0
def test_set_xmp_tag_overwrite(metadata_ro):
    m = metadata_ro.metadata
    m.read()
    assert m._tags['xmp'] == {}
    # Overwrite an existing tag
    tag = XmpTag('Xmp.dc.format', ('image', 'png'))
    m._set_xmp_tag(tag.key, tag)
    assert m._tags['xmp'] == {tag.key: tag}
    assert tag.key in m._image._xmpKeys()
    assert m._image._getXmpTag(tag.key)._getTextValue() == tag.raw_value
Esempio n. 44
0
 def _get_xmp_tag(self, key):
     # Return the XMP tag for the given key.
     # Throw a KeyError if the tag doesn't exist.
     try:
         return self._tags['xmp'][key]
     except KeyError:
         _tag = self._image._getXmpTag(key)
         tag = XmpTag._from_existing_tag(_tag)
         self._tags['xmp'][key] = tag
         return tag
Esempio n. 45
0
 def _get_xmp_tag(self, key):
     # Return the XMP tag for the given key.
     # Throw a KeyError if the tag doesn't exist.
     try:
         return self._tags['xmp'][key]
     except KeyError:
         _tag = self._image._getXmpTag(key)
         tag = XmpTag._from_existing_tag(_tag)
         self._tags['xmp'][key] = tag
         return tag
Esempio n. 46
0
 def test_set_value(self):
     tag = XmpTag(
         'Xmp.xmp.ModifyDate',
         datetime.datetime(2005,
                           9,
                           7,
                           15,
                           9,
                           51,
                           tzinfo=FixedOffset('-', 7, 0)))
     old_value = tag.value
     tag.value = datetime.datetime(2009,
                                   4,
                                   22,
                                   8,
                                   30,
                                   27,
                                   tzinfo=FixedOffset())
     self.failIfEqual(tag.value, old_value)
Esempio n. 47
0
 def test_set_xmp_tag_overwrite(self):
     self.metadata.read()
     self.assertEqual(self.metadata._tags['xmp'], {})
     # Overwrite an existing tag
     tag = XmpTag('Xmp.dc.format', ('image', 'png'))
     self.metadata._set_xmp_tag(tag.key, tag)
     self.assertEqual(self.metadata._tags['xmp'], {tag.key: tag})
     self.assert_(tag.key in self.metadata._image._xmpKeys())
     self.assertEqual(
         self.metadata._image._getXmpTag(tag.key)._getTextValue(),
         tag.raw_value)
Esempio n. 48
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_python_date(self):
     # Valid values
     tag = XmpTag('Xmp.xmp.CreateDate')
     self.assertEqual(tag.type, 'Date')
     self.assertEqual(tag._convert_to_python('1999', 'Date'),
                      datetime.date(1999, 1, 1))
     self.assertEqual(tag._convert_to_python('1999-10', 'Date'),
                      datetime.date(1999, 10, 1))
     self.assertEqual(tag._convert_to_python('1999-10-13', 'Date'),
                      datetime.date(1999, 10, 13))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03Z', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, tzinfo=FixedOffset()),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03+06:00', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, tzinfo=FixedOffset('+', 6, 0)),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03-06:00', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, tzinfo=FixedOffset('-', 6, 0)),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03:54Z', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, 54, tzinfo=FixedOffset()),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03:54+06:00', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, 54, tzinfo=FixedOffset('+', 6, 0)),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03:54-06:00', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, 54, tzinfo=FixedOffset('-', 6, 0)),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03:54.721Z', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, 54, 721000, tzinfo=FixedOffset()),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03:54.721+06:00', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, 54, 721000, tzinfo=FixedOffset('+', 6, 0)),
                      datetime.timedelta(0))
     self.assertEqual(tag._convert_to_python('1999-10-13T05:03:54.721-06:00', 'Date') - \
                      datetime.datetime(1999, 10, 13, 5, 3, 54, 721000, tzinfo=FixedOffset('-', 6, 0)),
                      datetime.timedelta(0))
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, 'invalid', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '11/10/1983', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '-1000', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '2009-13', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '2009-10-32', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '2009-10-30T25:12Z', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '2009-10-30T23:67Z', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_python, '2009-01-22T21', 'Date')
Esempio n. 49
0
 def test_set_value_basestring_for_langalt(self):
     tag = XmpTag('Xmp.dc.description')
     self.failUnlessEqual(tag.type, 'Lang Alt')
     tag.value = 'bleh'
     self.failUnlessEqual(tag.value, {'x-default': 'bleh'})
Esempio n. 50
0
File: xmp.py Progetto: Namejs/workr
 def test_convert_to_string_date(self):
     # Valid values
     tag = XmpTag('Xmp.xmp.CreateDate')
     self.assertEqual(tag.type, 'Date')
     self.assertEqual(tag._convert_to_string(datetime.date(2009, 2, 4), 'Date'),
                      '2009-02-04')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13), 'Date'),
                      '1999-10-13')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, tzinfo=FixedOffset()), 'Date'),
                      '1999-10-13T05:03Z')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, tzinfo=FixedOffset('+', 5, 30)), 'Date'),
                      '1999-10-13T05:03+05:30')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, tzinfo=FixedOffset('-', 11, 30)), 'Date'),
                      '1999-10-13T05:03-11:30')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, 27, tzinfo=FixedOffset()), 'Date'),
                      '1999-10-13T05:03:27Z')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, 27, tzinfo=FixedOffset('+', 5, 30)), 'Date'),
                      '1999-10-13T05:03:27+05:30')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, 27, tzinfo=FixedOffset('-', 11, 30)), 'Date'),
                      '1999-10-13T05:03:27-11:30')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, 27, 124300, tzinfo=FixedOffset()), 'Date'),
                      '1999-10-13T05:03:27.1243Z')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, 27, 124300, tzinfo=FixedOffset('+', 5, 30)), 'Date'),
                      '1999-10-13T05:03:27.1243+05:30')
     self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13, 5, 3, 27, 124300, tzinfo=FixedOffset('-', 11, 30)), 'Date'),
                      '1999-10-13T05:03:27.1243-11:30')
     # Invalid values
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, 'invalid', 'Date')
     self.failUnlessRaises(XmpValueError, tag._convert_to_string, None, 'Date')
Esempio n. 51
0
File: xmp.py Progetto: Namejs/workr
 def test_set_value(self):
     tag = XmpTag('Xmp.xmp.ModifyDate', datetime.datetime(2005, 9, 7, 15, 9, 51, tzinfo=FixedOffset('-', 7, 0)))
     old_value = tag.value
     tag.value = datetime.datetime(2009, 4, 22, 8, 30, 27, tzinfo=FixedOffset())
     self.failIfEqual(tag.value, old_value)