diff options
-rw-r--r-- | src/pyexiv2.py | 15 | ||||
-rw-r--r-- | unittest/xmp.py | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py index 5341c86..2c00e2d 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -615,6 +615,21 @@ class XmpTag(MetadataTag): return value + @staticmethod + def _convert_to_string(value, xtype): + """ + Convert a value to its corresponding string representation. + Fallback to str(value) if no standard-compliant conversion can be done. + """ + if xtype == 'Boolean': + if value == True: + return 'True' + elif value == False: + return 'False' + + # Default fallback conversion + return str(value) + def __str__(self): """ Return a string representation of the XMP tag. diff --git a/unittest/xmp.py b/unittest/xmp.py index 9db9434..09aca55 100644 --- a/unittest/xmp.py +++ b/unittest/xmp.py @@ -46,6 +46,14 @@ class TestXmpTag(unittest.TestCase): # Invalid values: not converted self.assertEqual(XmpTag._convert_to_python('invalid', xtype), 'invalid') + def test_convert_to_string_boolean(self): + xtype = 'Boolean' + # Valid values + self.assertEqual(XmpTag._convert_to_string(True, xtype), 'True') + self.assertEqual(XmpTag._convert_to_string(False, xtype), 'False') + # Invalid values + self.assertEqual(XmpTag._convert_to_string('invalid', xtype), 'invalid') + def test_convert_to_python_choice(self): pass |