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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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'), 'Gérard') self.assertEqual( tag._convert_to_python('Python Software Foundation', 'ProperName'), 'Python Software Foundation') # Invalid values self.assertRaises(XmpValueError, tag._convert_to_python(None, 'ProperName'))
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')
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'))
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.assertRaises(XmpValueError, tag._convert_to_python, 'invalid', 'MIMEType') self.assertRaises(XmpValueError, tag._convert_to_python, 'image-jpeg', 'MIMEType')
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')
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')
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.assertRaises(XmpValueError, tag._convert_to_python, 'invalid', 'Rational') self.assertRaises(XmpValueError, tag._convert_to_python, '5 / 3', 'Rational') self.assertRaises(XmpValueError, tag._convert_to_python, '5/-3', 'Rational')
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')
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.assertRaises(XmpValueError, tag._convert_to_python, 'invalid', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '11/10/1983', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '-1000', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '2009-13', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '2009-10-32', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '2009-10-30T25:12Z', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '2009-10-30T23:67Z', 'Date') self.assertRaises(XmpValueError, tag._convert_to_python, '2009-01-22T21', 'Date')
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')