'Test metadata writing through the python code'

def test_write_metadata(self):

    img = Image.open('Tests/images/hopper.tif')
    f = self.tempfile('temp.tiff')
    img.save(f, tiffinfo=img.tag)
    loaded = Image.open(f)
    original = img.tag_v2.named()
    reloaded = loaded.tag_v2.named()
    for (k, v) in original.items():
        if isinstance(v, IFDRational):
            original[k] = IFDRational(*_limit_rational(v, (2 ** 31)))
        if (isinstance(v, tuple) and isinstance(v[0], IFDRational)):
            original[k] = tuple([IFDRational(*_limit_rational(elt, (2 ** 31))) for elt in v])
    ignored = ['StripByteCounts', 'RowsPerStrip', 'PageNumber', 'StripOffsets']
    for (tag, value) in reloaded.items():
        if (tag in ignored):
            continue
        if (isinstance(original[tag], tuple) and isinstance(original[tag][0], IFDRational)):
            self.assert_deep_equal(original[tag], value, ("%s    didn't    roundtrip,    %s,    %s" % (tag, original[tag], value)))
        else:
            self.assertEqual(original[tag], value, ("%s    didn't    roundtrip,    %s,    %s" % (tag, original[tag], value)))
    for (tag, value) in original.items():
        if (tag not in ignored):
            self.assertEqual(value, reloaded[tag], ("%s    didn't    roundtrip" % tag))
