def test_can_only_set_text_values(metadata): # At the moment custom namespaces only support setting simple text # values. key = 'Xmp.far.foo' register_namespace('foobar/', 'far') try: # array value not supported with pytest.raises(NotImplementedError): metadata[key] = ['foo', 'bar'] # lang alt value not supported with pytest.raises(NotImplementedError): metadata[key] = {'x-default': 'foo', 'fr-FR': 'bar'} # simple text value is supported metadata[key] = 'simple text value' assert metadata[key].raw_value == b'simple text value' # python objects stored as simple text values are supported value = D.today() dt = '%04d-%02d-%02d' % (value.year, value.month, value.day) metadata[key] = value assert metadata[key].raw_value == dt finally: unregister_namespace('foobar/')
def test_cannot_unregister_twice(): name = 'bleh/' prefix = 'ble' register_namespace(name, prefix) unregister_namespace(name) with pytest.raises(KeyError): unregister_namespace(name)
def test_cannot_register_twice(): name = 'foobar/' prefix = 'boo' register_namespace(name, prefix) try: with pytest.raises(KeyError): register_namespace(name, prefix) finally: unregister_namespace(name)
def test_cannot_register_builtin(): # Cannot overwrite the built-in .dc. prefix with pytest.raises(KeyError): register_namespace('foobar/', 'dc') # _Can_ give another prefix the same meaning register_namespace(DC_NAME, 'notdc') # unregistration will zap the most recent prefix associated with the name unregister_namespace(DC_NAME)
def test_register_and_set(metadata): register_namespace('foobar/', 'bar') try: key = 'Xmp.bar.foo' value = 'foobar' metadata[key] = value assert key in metadata.xmp_keys finally: unregister_namespace('foobar/')
def test_unregister_invalidates_keys_in_ns(self): name = 'blih/' prefix = 'bli' register_namespace(name, prefix) key = 'Xmp.%s.blu' % prefix self.metadata[key] = 'foobar' self.assert_(key in self.metadata.xmp_keys) unregister_namespace(name) self.assertRaises(KeyError, self.metadata.write)
def test_unregister_invalidates_keys_in_ns(self): name = 'blih/' prefix = 'bli' register_namespace(name, prefix) key = 'Xmp.%s.blu' % prefix self.metadata[key] = 'foobar' self.assert_(key in self.metadata.xmp_keys) unregister_namespace(name) self.assertRaises(KeyError, self.metadata.write)
def test_unregister_invalidates_keys_in_ns(metadata): name = 'blih/' prefix = 'bli' key = 'Xmp.' + prefix + '.blu' register_namespace(name, prefix) try: metadata[key] = 'foobar' assert key in metadata.xmp_keys finally: unregister_namespace(name) with pytest.raises(KeyError): metadata.write()
def test_can_only_set_text_values(self): # At the moment custom namespaces only support setting simple text # values. register_namespace('foobar/', 'far') key = 'Xmp.far.foo' value = datetime.date.today() self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = datetime.datetime.now() self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = ['foo', 'bar'] self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = {'x-default': 'foo', 'fr-FR': 'bar'} self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = 'simple text value' self.metadata[key] = value
def test_can_only_set_text_values(self): # At the moment custom namespaces only support setting simple text # values. register_namespace('foobar/', 'far') key = 'Xmp.far.foo' value = datetime.date.today() self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = datetime.datetime.now() self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = ['foo', 'bar'] self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = {'x-default': 'foo', 'fr-FR': 'bar'} self.assertRaises(XmpValueError, self.metadata.__setitem__, key, value) value = 'simple text value' self.metadata[key] = value
def test_unregister_all_ns(self): # Unregistering all custom namespaces will always succeed, even if there # are no custom namespaces registered. unregister_namespaces() name = 'blop/' prefix = 'blo' register_namespace(name, prefix) self.metadata['Xmp.%s.bar' % prefix] = 'foobar' name2 = 'blup/' prefix2 = 'blu' register_namespace(name2, prefix2) self.metadata['Xmp.%s.bar' % prefix2] = 'foobar' unregister_namespaces() self.assertRaises(KeyError, self.metadata.__setitem__, 'Xmp.%s.baz' % prefix, 'foobaz') self.assertRaises(KeyError, self.metadata.__setitem__, 'Xmp.%s.baz' % prefix2, 'foobaz')
def test_can_only_set_text_values(self): # At the moment custom namespaces only support setting simple text # values. register_namespace('foobar/', 'far') key = 'Xmp.far.foo' value = datetime.date.today() dt = '%04d-%02d-%02d' % (value.year, value.month, value.day) self.metadata[key] = value self.assertEqual(self.metadata[key].raw_value, dt) value = ['foo', 'bar'] self.assertRaises(NotImplementedError, self.metadata.__setitem__, key, value) value = {'x-default': 'foo', 'fr-FR': 'bar'} self.assertRaises(NotImplementedError, self.metadata.__setitem__, key, value) value = 'simple text value' self.metadata[key] = value
def test_unregister_all_ns(self): # Unregistering all custom namespaces will always succeed, even if there # are no custom namespaces registered. unregister_namespaces() name = 'blop/' prefix = 'blo' register_namespace(name, prefix) self.metadata['Xmp.%s.bar' % prefix] = 'foobar' name2 = 'blup/' prefix2 = 'blu' register_namespace(name2, prefix2) self.metadata['Xmp.%s.bar' % prefix2] = 'foobar' unregister_namespaces() self.assertRaises(KeyError, self.metadata.__setitem__, 'Xmp.%s.baz' % prefix, 'foobaz') self.assertRaises(KeyError, self.metadata.__setitem__, 'Xmp.%s.baz' % prefix2, 'foobaz')
def test_unregister_all_ns(metadata): # Unregistering all custom namespaces will always succeed, # even if there are no custom namespaces registered. unregister_namespaces() name = 'blop/' prefix = 'blo' register_namespace(name, prefix) metadata['Xmp.%s.bar' % prefix] = 'foobar' name2 = 'blup/' prefix2 = 'blu' register_namespace(name2, prefix2) metadata['Xmp.%s.bar' % prefix2] = 'foobar' unregister_namespaces() with pytest.raises(KeyError): metadata['Xmp.%s.baz' % prefix] = 'foobaz' with pytest.raises(KeyError): metadata['Xmp.%s.baz' % prefix2] = 'foobaz'
def test_unregister(self): name = 'blah/' prefix = 'bla' register_namespace(name, prefix) unregister_namespace(name)
def test_cannot_unregister_twice(self): name = 'bleh/' prefix = 'ble' register_namespace(name, prefix) unregister_namespace(name) self.assertRaises(KeyError, unregister_namespace, name)
def test_register_and_set(self): register_namespace('foobar/', 'bar') key = 'Xmp.bar.foo' value = 'foobar' self.metadata[key] = value self.assert_(key in self.metadata.xmp_keys)
def test_cannot_register_twice(self): name = 'foobar/' prefix = 'boo' register_namespace(name, prefix) self.assertRaises(KeyError, register_namespace, name, prefix)
def test_name_must_end_with_slash(): with pytest.raises(ValueError): register_namespace('foobar', 'foo') with pytest.raises(ValueError): unregister_namespace('foobar')
def test_unregister(self): name = 'blah/' prefix = 'bla' register_namespace(name, prefix) unregister_namespace(name)
def test_cannot_unregister_twice(self): name = 'bleh/' prefix = 'ble' register_namespace(name, prefix) unregister_namespace(name) self.assertRaises(KeyError, unregister_namespace, name)
def test_register_and_unregister(): name = 'blah/' prefix = 'bla' register_namespace(name, prefix) unregister_namespace(name)
def test_register_and_set(self): register_namespace('foobar/', 'bar') key = 'Xmp.bar.foo' value = 'foobar' self.metadata[key] = value self.assert_(key in self.metadata.xmp_keys)
def test_cannot_register_twice(self): name = 'foobar/' prefix = 'boo' register_namespace(name, prefix) self.assertRaises(KeyError, register_namespace, name, prefix)