.. -*-doctest-*-

===================
Metadata Extraction
===================

Register the image data annotation adapter.

    >>> from zope import interface
    >>> from zope import component
    >>> from p4a.image import imageanno
    >>> component.provideAdapter(
    ...     imageanno.AnnotationImage, adapts=[interface.Interface])

Mock an image content object.

    >>> from zope.annotation import interfaces
    >>> class Content(dict):
    ...     interface.implements(interfaces.IAnnotations)
    ...     def getContentType(self): return 'image/jpeg'
    >>> content = Content()

Ensure that the empty data accessor defaults pass the schema
validation.

    >>> from p4a.image import validation
    >>> image = imageanno.AnnotationImage(content)
    >>> image.image_type = 'image/jpeg'
    >>> validator = validation.ValidationView()
    >>> validator.context = image
    >>> [str(i) for i in validator()]
    ["('height', u'Height', )", "('width', u'Width', )"]

Ensure that metadata extraction passes the schema validation.

    >>> import os
    >>> from p4a.image.thirdparty import _imagedata
    >>> from p4a.image import tests
    >>> accessor = _imagedata.ImageDataAccessor(content)
    >>> accessor.load(
    ...     os.path.join(os.path.dirname(tests.__file__),
    ...                  'samples', 'USS_Constitution.jpg'))
    >>> validator()
    []

Ensure that metadata extraction for an image with no metadata passes
the schema validation.

    >>> accessor.load(
    ...     os.path.join(os.path.dirname(tests.__file__),
    ...                  'samples', 'no_metadata.jpg'))
    >>> [str(i) for i in validator()]
    []
