~osomon/pyexiv2/pyexiv2-0.3

« back to all changes in this revision

Viewing changes to test/utils.py

  • Committer: Olivier Tilloy
  • Date: 2010-11-17 08:26:23 UTC
  • mfrom: (327.1.2 write_byte_644143)
  • Revision ID: olivier@tilloy.net-20101117082623-ueop1xvyp0nqtg96
Throw an exception instead of silently failing when unable to parse the raw value for EXIF and IPTC tags.
Note that parsing never fails for XMP tags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# ******************************************************************************
 
4
#
 
5
# Copyright (C) 2010 Olivier Tilloy <olivier@tilloy.net>
 
6
#
 
7
# This file is part of the pyexiv2 distribution.
 
8
#
 
9
# pyexiv2 is free software; you can redistribute it and/or
 
10
# modify it under the terms of the GNU General Public License
 
11
# as published by the Free Software Foundation; either version 2
 
12
# of the License, or (at your option) any later version.
 
13
#
 
14
# pyexiv2 is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
# GNU General Public License for more details.
 
18
#
 
19
# You should have received a copy of the GNU General Public License
 
20
# along with pyexiv2; if not, write to the Free Software
 
21
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
 
22
#
 
23
# Author: Olivier Tilloy <olivier@tilloy.net>
 
24
#
 
25
# ******************************************************************************
 
26
 
 
27
import unittest
 
28
 
 
29
from pyexiv2.utils import undefined_to_string, string_to_undefined
 
30
 
 
31
 
 
32
class TestConversions(unittest.TestCase):
 
33
 
 
34
    def test_undefined_to_string(self):
 
35
        self.assertEqual(undefined_to_string("48 50 50 49"), "0221")
 
36
        self.assertEqual(undefined_to_string("48 50 50 49 "), "0221")
 
37
        self.assertRaises(ValueError, undefined_to_string, "")
 
38
        self.assertRaises(ValueError, undefined_to_string, "foo")
 
39
        self.assertRaises(ValueError, undefined_to_string, "48 50  50 49")
 
40
 
 
41
    def test_string_to_undefined(self):
 
42
        self.assertEqual(string_to_undefined("0221"), "48 50 50 49")
 
43
        self.assertEqual(string_to_undefined(""), "")
 
44
 
 
45
    def test_identity(self):
 
46
        value = "0221"
 
47
        self.assertEqual(undefined_to_string(string_to_undefined(value)), value)
 
48
        value = "48 50 50 49"
 
49
        self.assertEqual(string_to_undefined(undefined_to_string(value)), value)
 
50