345.1.1
by Olivier Tilloy
Support pickling EXIF tags. |
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 |
from pyexiv2.exif import ExifTag |
|
345.1.3
by Olivier Tilloy
Support pickling IPTC tags. |
28 |
from pyexiv2.iptc import IptcTag |
345.1.4
by Olivier Tilloy
Support pickling XMP tags. |
29 |
from pyexiv2.xmp import XmpTag |
347.1.2
by Olivier Tilloy
Handle fractions in a transparent manner, |
30 |
from pyexiv2.utils import make_fraction, FixedOffset |
345.1.1
by Olivier Tilloy
Support pickling EXIF tags. |
31 |
|
32 |
import unittest |
|
33 |
import pickle |
|
34 |
import datetime |
|
35 |
||
36 |
||
37 |
class TestPicklingTags(unittest.TestCase): |
|
38 |
||
39 |
def test_pickle_exif_tag(self): |
|
40 |
tags = [] |
|
41 |
tags.append(ExifTag('Exif.Image.DateTime', |
|
42 |
datetime.datetime(2010, 12, 22, 19, 21, 0))) |
|
43 |
tags.append(ExifTag('Exif.GPSInfo.GPSDateStamp', datetime.date.today())) |
|
44 |
tags.append(ExifTag('Exif.Image.Copyright', '(C) 2010 Santa Claus')) |
|
45 |
tags.append(ExifTag('Exif.GPSInfo.GPSVersionID', '0')) |
|
46 |
tags.append(ExifTag('Exif.Pentax.Temperature', '14')) |
|
47 |
tags.append(ExifTag('Exif.Photo.UserComment', 'foo bar baz')) |
|
48 |
tags.append(ExifTag('Exif.Image.BitsPerSample', 8)) |
|
49 |
tags.append(ExifTag('Exif.Image.TimeZoneOffset', 7)) |
|
50 |
tags.append(ExifTag('Exif.Image.ImageWidth', 7492)) |
|
51 |
tags.append(ExifTag('Exif.OlympusCs.ManometerReading', 29)) |
|
347.1.2
by Olivier Tilloy
Handle fractions in a transparent manner, |
52 |
tags.append(ExifTag('Exif.Image.XResolution', make_fraction(7, 3))) |
53 |
tags.append(ExifTag('Exif.Image.BaselineExposure', make_fraction(-7, 3))) |
|
345.1.1
by Olivier Tilloy
Support pickling EXIF tags. |
54 |
tags.append(ExifTag('Exif.Photo.ExifVersion', '0100')) |
55 |
for tag in tags: |
|
56 |
s = pickle.dumps(tag) |
|
57 |
t = pickle.loads(s) |
|
58 |
self.assert_(isinstance(t, ExifTag)) |
|
59 |
self.assertEqual(t.key, tag.key) |
|
60 |
self.assertEqual(t.type, tag.type) |
|
61 |
self.assertEqual(t.name, tag.name) |
|
62 |
self.assertEqual(t.label, tag.label) |
|
63 |
self.assertEqual(t.description, tag.description) |
|
64 |
self.assertEqual(t.section_name, tag.section_name) |
|
65 |
self.assertEqual(t.section_description, tag.section_description) |
|
66 |
self.assertEqual(t.raw_value, tag.raw_value) |
|
67 |
self.assertEqual(t.value, tag.value) |
|
68 |
self.assertEqual(t.human_value, tag.human_value) |
|
69 |
||
345.1.3
by Olivier Tilloy
Support pickling IPTC tags. |
70 |
def test_pickle_iptc_tag(self): |
71 |
tags = [] |
|
72 |
tags.append(IptcTag('Iptc.Envelope.FileFormat', [23])) |
|
73 |
tags.append(IptcTag('Iptc.Application2.Subject', ['foo', 'bar', 'baz'])) |
|
74 |
tags.append(IptcTag('Iptc.Envelope.DateSent', [datetime.date.today()])) |
|
75 |
tags.append(IptcTag('Iptc.Envelope.TimeSent', |
|
76 |
[datetime.time(23, 37, 4, tzinfo=FixedOffset('+', 6, 0))])) |
|
77 |
tags.append(IptcTag('Iptc.Application2.Preview', ['01001101'])) |
|
78 |
for tag in tags: |
|
79 |
s = pickle.dumps(tag) |
|
80 |
t = pickle.loads(s) |
|
81 |
self.assert_(isinstance(t, IptcTag)) |
|
82 |
self.assertEqual(t.key, tag.key) |
|
83 |
self.assertEqual(t.type, tag.type) |
|
84 |
self.assertEqual(t.name, tag.name) |
|
85 |
self.assertEqual(t.title, tag.title) |
|
86 |
self.assertEqual(t.description, tag.description) |
|
87 |
self.assertEqual(t.photoshop_name, tag.photoshop_name) |
|
88 |
self.assertEqual(t.repeatable, tag.repeatable) |
|
89 |
self.assertEqual(t.record_name, tag.record_name) |
|
90 |
self.assertEqual(t.record_description, tag.record_description) |
|
91 |
self.assertEqual(t.raw_value, tag.raw_value) |
|
92 |
self.assertEqual(t.value, tag.value) |
|
93 |
||
345.1.4
by Olivier Tilloy
Support pickling XMP tags. |
94 |
def test_pickle_xmp_tag(self): |
95 |
tags = [] |
|
96 |
tags.append(XmpTag('Xmp.dc.subject', ['foo', 'bar', 'baz'])) |
|
97 |
tags.append(XmpTag('Xmp.xmpRights.Marked', True)) |
|
98 |
tags.append(XmpTag('Xmp.xmp.CreateDate', datetime.date.today())) |
|
99 |
tags.append(XmpTag('Xmp.xmpMM.SaveID', 34)) |
|
100 |
tags.append(XmpTag('Xmp.dc.format', ('image', 'jpeg'))) |
|
101 |
tags.append(XmpTag('Xmp.photoshop.CaptionWriter', 'John Doe')) |
|
102 |
tags.append(XmpTag('Xmp.dc.source', 'bleh')) |
|
103 |
tags.append(XmpTag('Xmp.xmpMM.DocumentID', 'http://example.com')) |
|
104 |
tags.append(XmpTag('Xmp.xmp.BaseURL', 'http://example.com')) |
|
347.1.2
by Olivier Tilloy
Handle fractions in a transparent manner, |
105 |
tags.append(XmpTag('Xmp.xmpDM.videoPixelAspectRatio', make_fraction(5, 3))) |
345.1.4
by Olivier Tilloy
Support pickling XMP tags. |
106 |
for tag in tags: |
107 |
s = pickle.dumps(tag) |
|
108 |
t = pickle.loads(s) |
|
109 |
self.assert_(isinstance(t, XmpTag)) |
|
110 |
self.assertEqual(t.key, tag.key) |
|
111 |
self.assertEqual(t.type, tag.type) |
|
112 |
self.assertEqual(t.name, tag.name) |
|
113 |
self.assertEqual(t.title, tag.title) |
|
114 |
self.assertEqual(t.description, tag.description) |
|
115 |
self.assertEqual(t.raw_value, tag.raw_value) |
|
116 |
self.assertEqual(t.value, tag.value) |
|
117 |