diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-03-01 12:58:06 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-03-01 12:58:06 +0100 |
commit | a0f07cc77ff4f09a0025e1f5b4131b5f8a2d55fc (patch) | |
tree | 1bb46feb9818405777964dc0d6016d9823469b6e /unittest | |
parent | 4eff232bdf26b4d57641f7fac18f9a6b7e9b6fa0 (diff) | |
download | pyexiv2-a0f07cc77ff4f09a0025e1f5b4131b5f8a2d55fc.tar.gz |
EXIF Ascii (including datetimes) two-ways conversion.
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/exif.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/unittest/exif.py b/unittest/exif.py index d46f138..72fb089 100644 --- a/unittest/exif.py +++ b/unittest/exif.py @@ -26,10 +26,46 @@ import unittest from pyexiv2 import ExifTag, ExifValueError +import datetime class TestExifTag(unittest.TestCase): + def test_convert_to_python_ascii(self): + xtype = 'Ascii' + # Valid values: datetimes + self.assertEqual(ExifTag._convert_to_python('2009-03-01 12:46:51', xtype), + datetime.datetime(2009, 03, 01, 12, 46, 51)) + self.assertEqual(ExifTag._convert_to_python('2009:03:01 12:46:51', xtype), + datetime.datetime(2009, 03, 01, 12, 46, 51)) + self.assertEqual(ExifTag._convert_to_python('2009-03-01T12:46:51Z', xtype), + datetime.datetime(2009, 03, 01, 12, 46, 51)) + # Valid values: strings + self.assertEqual(ExifTag._convert_to_python('Some text.', xtype), u'Some text.') + self.assertEqual(ExifTag._convert_to_python('Some text with exotic chàräctérʐ.', xtype), + u'Some text with exotic chàräctérʐ.') + # Invalid values: datetimes + self.assertEqual(ExifTag._convert_to_python('2009-13-01 12:46:51', xtype), + u'2009-13-01 12:46:51') + self.assertEqual(ExifTag._convert_to_python('2009-12-01', xtype), + u'2009-12-01') + + def test_convert_to_string_ascii(self): + xtype = 'Ascii' + # Valid values: datetimes + self.assertEqual(ExifTag._convert_to_string(datetime.datetime(2009, 03, 01, 12, 54, 28), xtype), + '2009-03-01 12:54:28') + self.assertEqual(ExifTag._convert_to_string(datetime.date(2009, 03, 01), xtype), + '2009-03-01 00:00:00') + # Valid values: strings + self.assertEqual(ExifTag._convert_to_string(u'Some text', xtype), 'Some text') + self.assertEqual(ExifTag._convert_to_string(u'Some text with exotic chàräctérʐ.', xtype), + 'Some text with exotic chàräctérʐ.') + self.assertEqual(ExifTag._convert_to_string('Some text with exotic chàräctérʐ.', xtype), + 'Some text with exotic chàräctérʐ.') + # Invalid values + self.failUnlessRaises(ExifValueError, ExifTag._convert_to_string, None, xtype) + def test_convert_to_python_short(self): xtype = 'Short' # Valid values |