aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2010-11-15 21:55:44 +0100
committerOlivier Tilloy <olivier@tilloy.net>2010-11-15 21:55:44 +0100
commit712d3725f35a9bfdb55b4bcf41dd194a5786ef32 (patch)
treea00b8aad12f4933b97a0a1440d0e19d9beaa4328 /test
parent3f20b1b4d94a544d4a2bf42f97500ccb39d971eb (diff)
downloadpyexiv2-712d3725f35a9bfdb55b4bcf41dd194a5786ef32.tar.gz
Strip trailing white spaces in string_to_undefined(…).
New unit tests for string ⟷ undefined conversions.
Diffstat (limited to 'test')
-rwxr-xr-xtest/TestsRunner.py2
-rw-r--r--test/exif.py8
-rw-r--r--test/metadata.py2
-rw-r--r--test/utils.py50
4 files changed, 57 insertions, 5 deletions
diff --git a/test/TestsRunner.py b/test/TestsRunner.py
index ac9f2d3..d0a1c92 100755
--- a/test/TestsRunner.py
+++ b/test/TestsRunner.py
@@ -38,6 +38,7 @@ from xmp import TestXmpTag
from metadata import TestImageMetadata
from buffer import TestBuffer
from encoding import TestEncodings
+from utils import TestConversions
def run_unit_tests():
@@ -53,6 +54,7 @@ def run_unit_tests():
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestImageMetadata))
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestBuffer))
suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestEncodings))
+ suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(TestConversions))
# Run the test suite
return unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/test/exif.py b/test/exif.py
index e1cf8b9..bb218c2 100644
--- a/test/exif.py
+++ b/test/exif.py
@@ -293,16 +293,16 @@ class TestExifTag(unittest.TestCase):
def test_convert_to_python_undefined(self):
# Valid values
- tag = ExifTag('Exif.Photo.ExifVersion', '48 49 48 48 ')
+ tag = ExifTag('Exif.Photo.ExifVersion')
self.assertEqual(tag.type, 'Undefined')
- self.assertEqual(tag._convert_to_python('48 49 48 48 '), '0100')
+ self.assertEqual(tag._convert_to_python('48 49 48 48'), '0100')
def test_convert_to_string_undefined(self):
# Valid values
tag = ExifTag('Exif.Photo.ExifVersion')
self.assertEqual(tag.type, 'Undefined')
- self.assertEqual(tag._convert_to_string('0100'), '48 49 48 48 ')
- self.assertEqual(tag._convert_to_string(u'0100'), '48 49 48 48 ')
+ self.assertEqual(tag._convert_to_string('0100'), '48 49 48 48')
+ self.assertEqual(tag._convert_to_string(u'0100'), '48 49 48 48')
# Invalid values
self.failUnlessRaises(ExifValueError, tag._convert_to_string, 3)
diff --git a/test/metadata.py b/test/metadata.py
index cb63c71..98ce689 100644
--- a/test/metadata.py
+++ b/test/metadata.py
@@ -497,7 +497,7 @@ class TestImageMetadata(unittest.TestCase):
self.failUnlessEqual(self.metadata._tags['xmp'][key], tag)
# Replace existing tags
key = 'Exif.Photo.ExifVersion'
- tag = ExifTag(key, '48 50 50 48 ')
+ tag = ExifTag(key, '0220')
self.metadata[key] = tag
self.failUnless(key in self.metadata._tags['exif'])
self.failUnlessEqual(self.metadata._tags['exif'][key], tag)
diff --git a/test/utils.py b/test/utils.py
new file mode 100644
index 0000000..2f0d19b
--- /dev/null
+++ b/test/utils.py
@@ -0,0 +1,50 @@
+# -*- 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>
+#
+# ******************************************************************************
+
+import unittest
+
+from pyexiv2.utils import undefined_to_string, string_to_undefined
+
+
+class TestConversions(unittest.TestCase):
+
+ def test_undefined_to_string(self):
+ self.assertEqual(undefined_to_string("48 50 50 49"), "0221")
+ self.assertEqual(undefined_to_string("48 50 50 49 "), "0221")
+ self.assertRaises(ValueError, undefined_to_string, "")
+ self.assertRaises(ValueError, undefined_to_string, "foo")
+ self.assertRaises(ValueError, undefined_to_string, "48 50 50 49")
+
+ def test_string_to_undefined(self):
+ self.assertEqual(string_to_undefined("0221"), "48 50 50 49")
+ self.assertEqual(string_to_undefined(""), "")
+
+ def test_identity(self):
+ value = "0221"
+ self.assertEqual(undefined_to_string(string_to_undefined(value)), value)
+ value = "48 50 50 49"
+ self.assertEqual(string_to_undefined(undefined_to_string(value)), value)
+