~osomon/pyexiv2/pyexiv2-0.3

« back to all changes in this revision

Viewing changes to test/iptc.py

  • Committer: Olivier Tilloy
  • Date: 2011-08-03 06:57:19 UTC
  • mfrom: (358.1.3 timezones)
  • Revision ID: olivier@tilloy.net-20110803065719-cjwhptodhu0e3i6y
Fix timezone formatting when writing IPTC and XMP tags.
This introduces an optional dependency on python-tz in unit tests.

Original patch by Petri Damstén, thanks Petri!

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import datetime
33
33
import warnings
34
34
 
 
35
# Optional dependency on python-tz, more tests can be run if it is installed
 
36
try:
 
37
    import pytz
 
38
except ImportError:
 
39
    pytz = None
 
40
 
35
41
 
36
42
class TestIptcTag(unittest.TestCase):
37
43
 
160
166
        # Invalid values
161
167
        self.failUnlessRaises(IptcValueError, tag._convert_to_string, 'invalid')
162
168
 
 
169
    @unittest.skipIf(pytz is None, 'install python-tz to run this test')
 
170
    def test_convert_to_string_time_with_real_timezones(self):
 
171
        tag = IptcTag('Iptc.Envelope.TimeSent')
 
172
        self.assertEqual(tag.type, 'Time')
 
173
        t = pytz.timezone('UTC').localize(datetime.datetime(2011, 2, 2, 10, 52, 4))
 
174
        self.assertEqual(tag._convert_to_string(t), '10:52:04+00:00')
 
175
        t = pytz.timezone('CET').localize(datetime.datetime(2011, 2, 2, 10, 52, 4))
 
176
        self.assertEqual(tag._convert_to_string(t), '10:52:04+01:00')
 
177
 
163
178
    def test_convert_to_python_undefined(self):
164
179
        # Valid values
165
180
        tag = IptcTag('Iptc.Application2.Preview')