# -*- coding: utf-8 -*- # ****************************************************************************** # # Copyright (C) 2009 Olivier Tilloy # # This file is part of the pyexiv2 distribution. # # pyexiv2 is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # pyexiv2 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with pyexiv2; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA. # # Author: Olivier Tilloy # # ****************************************************************************** import unittest from pyexiv2 import IptcTag, IptcValueError class TestIptcTag(unittest.TestCase): def test_convert_to_python_short(self): xtype = 'Short' # Valid values self.assertEqual(IptcTag._convert_to_python('23', xtype), 23) self.assertEqual(IptcTag._convert_to_python('+5628', xtype), 5628) self.assertEqual(IptcTag._convert_to_python('-4', xtype), -4) # Invalid values self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, 'abc', xtype) self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, '5,64', xtype) self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, '47.0001', xtype) self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, '1E3', xtype) def test_convert_to_python_string(self): xtype = 'String' # Valid values self.assertEqual(IptcTag._convert_to_python('Some text.', xtype), u'Some text.') self.assertEqual(IptcTag._convert_to_python('Some text with exotic chàräctérʐ.', xtype), u'Some text with exotic chàräctérʐ.') # Invalid values self.failUnlessRaises(IptcValueError, IptcTag._convert_to_python, None, xtype) # TODO: other types