aboutsummaryrefslogtreecommitdiffstats
path: root/test/pickling.py
blob: d98c1468dab0bfe19348bd1f2e94af2ff1111dfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-

# ******************************************************************************
#
# Copyright (C) 2010 Olivier Tilloy <olivier@tilloy.net>
#
# 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 <olivier@tilloy.net>
#
# ******************************************************************************

from pyexiv2.exif import ExifTag
from pyexiv2.iptc import IptcTag
from pyexiv2.xmp import XmpTag
from pyexiv2.utils import Rational, FixedOffset

import unittest
import pickle
import datetime


class TestPicklingTags(unittest.TestCase):

    def test_pickle_exif_tag(self):
        tags = []
        tags.append(ExifTag('Exif.Image.DateTime',
                            datetime.datetime(2010, 12, 22, 19, 21, 0)))
        tags.append(ExifTag('Exif.GPSInfo.GPSDateStamp', datetime.date.today()))
        tags.append(ExifTag('Exif.Image.Copyright', '(C) 2010 Santa Claus'))
        tags.append(ExifTag('Exif.GPSInfo.GPSVersionID', '0'))
        tags.append(ExifTag('Exif.Pentax.Temperature', '14'))
        tags.append(ExifTag('Exif.Photo.UserComment', 'foo bar baz'))
        tags.append(ExifTag('Exif.Image.BitsPerSample', 8))
        tags.append(ExifTag('Exif.Image.TimeZoneOffset', 7))
        tags.append(ExifTag('Exif.Image.ImageWidth', 7492))
        tags.append(ExifTag('Exif.OlympusCs.ManometerReading', 29))
        tags.append(ExifTag('Exif.Image.XResolution', Rational(7, 3)))
        tags.append(ExifTag('Exif.Image.BaselineExposure', Rational(-7, 3)))
        tags.append(ExifTag('Exif.Photo.ExifVersion', '0100'))
        for tag in tags:
            s = pickle.dumps(tag)
            t = pickle.loads(s)
            self.assert_(isinstance(t, ExifTag))
            self.assertEqual(t.key, tag.key)
            self.assertEqual(t.type, tag.type)
            self.assertEqual(t.name, tag.name)
            self.assertEqual(t.label, tag.label)
            self.assertEqual(t.description, tag.description)
            self.assertEqual(t.section_name, tag.section_name)
            self.assertEqual(t.section_description, tag.section_description)
            self.assertEqual(t.raw_value, tag.raw_value)
            self.assertEqual(t.value, tag.value)
            self.assertEqual(t.human_value, tag.human_value)

    def test_pickle_iptc_tag(self):
        tags = []
        tags.append(IptcTag('Iptc.Envelope.FileFormat', [23]))
        tags.append(IptcTag('Iptc.Application2.Subject', ['foo', 'bar', 'baz']))
        tags.append(IptcTag('Iptc.Envelope.DateSent', [datetime.date.today()]))
        tags.append(IptcTag('Iptc.Envelope.TimeSent',
                            [datetime.time(23, 37, 4, tzinfo=FixedOffset('+', 6, 0))]))
        tags.append(IptcTag('Iptc.Application2.Preview', ['01001101']))
        for tag in tags:
            s = pickle.dumps(tag)
            t = pickle.loads(s)
            self.assert_(isinstance(t, IptcTag))
            self.assertEqual(t.key, tag.key)
            self.assertEqual(t.type, tag.type)
            self.assertEqual(t.name, tag.name)
            self.assertEqual(t.title, tag.title)
            self.assertEqual(t.description, tag.description)
            self.assertEqual(t.photoshop_name, tag.photoshop_name)
            self.assertEqual(t.repeatable, tag.repeatable)
            self.assertEqual(t.record_name, tag.record_name)
            self.assertEqual(t.record_description, tag.record_description)
            self.assertEqual(t.raw_value, tag.raw_value)
            self.assertEqual(t.value, tag.value)

    def test_pickle_xmp_tag(self):
        tags = []
        tags.append(XmpTag('Xmp.dc.subject', ['foo', 'bar', 'baz']))
        tags.append(XmpTag('Xmp.xmpRights.Marked', True))
        tags.append(XmpTag('Xmp.xmp.CreateDate', datetime.date.today()))
        tags.append(XmpTag('Xmp.xmpMM.SaveID', 34))
        tags.append(XmpTag('Xmp.dc.format', ('image', 'jpeg')))
        tags.append(XmpTag('Xmp.photoshop.CaptionWriter', 'John Doe'))
        tags.append(XmpTag('Xmp.dc.source', 'bleh'))
        tags.append(XmpTag('Xmp.xmpMM.DocumentID', 'http://example.com'))
        tags.append(XmpTag('Xmp.xmp.BaseURL', 'http://example.com'))
        tags.append(XmpTag('Xmp.xmpDM.videoPixelAspectRatio', Rational(5, 3)))
        for tag in tags:
            s = pickle.dumps(tag)
            t = pickle.loads(s)
            self.assert_(isinstance(t, XmpTag))
            self.assertEqual(t.key, tag.key)
            self.assertEqual(t.type, tag.type)
            self.assertEqual(t.name, tag.name)
            self.assertEqual(t.title, tag.title)
            self.assertEqual(t.description, tag.description)
            self.assertEqual(t.raw_value, tag.raw_value)
            self.assertEqual(t.value, tag.value)