Exemple #1
0
def test_device_capture_scanner():
    """
    Tests that the element ScannerCapture is created correctly using
    the device_capture function.
    """
    model = _element('ScannerModel')
    max_res = _element('MaximumOpticalResolution')
    software = _element('ScanningSystemSoftware')
    mix = device_capture(device_type='scanner',
                         manufacturer='acme',
                         sensor='undefined',
                         child_elements=[software, model, max_res])

    xml_str = ('<mix:ScannerCapture '
               'xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:scannerManufacturer>acme</mix:scannerManufacturer>'
               '<mix:ScannerModel/><mix:MaximumOpticalResolution/>'
               '<mix:scannerSensor>undefined</mix:scannerSensor>'
               '<mix:ScanningSystemSoftware/>'
               '</mix:ScannerCapture>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
Exemple #2
0
def test_device_capture_camera():
    """
    Tests that the element DigitalCameraCapture is created correctly
    using the device_capture function.
    """
    model = _element('DigitalCameraModel')
    settings = _element('CameraCaptureSettings')
    mix = device_capture(device_type='camera',
                         manufacturer='acme',
                         sensor='undefined',
                         child_elements=[settings, model])

    xml_str = ('<mix:DigitalCameraCapture '
               'xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:digitalCameraManufacturer>acme'
               '</mix:digitalCameraManufacturer>'
               '<mix:DigitalCameraModel/>'
               '<mix:cameraSensor>undefined</mix:cameraSensor>'
               '<mix:CameraCaptureSettings/>'
               '</mix:DigitalCameraCapture>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
Exemple #3
0
def test_capture_metadata():
    """
    Tests that the element ImageCaptureMetadata is created correctly
    and that the subelements are properly sorted.
    """
    source = _element('SourceInformation')
    capture = _element('GeneralCaptureInformation')
    scanner = _element('ScannerCapture')
    camera = _element('DigitalCameraCapture')
    mix = image_capture_metadata(
        orientation='unknown',
        methodology='2',
        child_elements=[camera, capture, scanner, source])

    xml_str = ('<mix:ImageCaptureMetadata '
               'xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:SourceInformation/><mix:GeneralCaptureInformation/>'
               '<mix:ScannerCapture/><mix:DigitalCameraCapture/>'
               '<mix:orientation>unknown</mix:orientation><mix:methodology>2'
               '</mix:methodology></mix:ImageCaptureMetadata>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
Exemple #4
0
def test_source_size():
    """Tests that the element SourceSize is created correctly."""
    mix = source_size(x_value='1',
                      x_unit='mm',
                      y_value='2',
                      y_unit='mm',
                      z_value='3',
                      z_unit='mm')

    xml_str = ('<mix:SourceSize xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:SourceXDimension><mix:sourceXDimensionValue>1'
               '</mix:sourceXDimensionValue><mix:sourceXDimensionUnit>mm'
               '</mix:sourceXDimensionUnit></mix:SourceXDimension>'
               '<mix:SourceYDimension><mix:sourceYDimensionValue>2'
               '</mix:sourceYDimensionValue><mix:sourceYDimensionUnit>mm'
               '</mix:sourceYDimensionUnit></mix:SourceYDimension>'
               '<mix:SourceZDimension><mix:sourceZDimensionValue>3'
               '</mix:sourceZDimensionValue><mix:sourceZDimensionUnit>mm'
               '</mix:sourceZDimensionUnit></mix:SourceZDimension>'
               '</mix:SourceSize>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
def test_metshdr():
    """test metshdr"""
    xml = '<mets:metsHdr xmlns:mets="http://www.loc.gov/METS/" ' \
          'CREATEDATE="2017-12-12T12:12:12" ' \
          'RECORDSTATUS="submission">' \
          '<mets:agent ROLE="CREATOR" TYPE="ORGANIZATION">' \
          '<mets:name>zzz</mets:name></mets:agent>' \
          '<mets:agent ROLE="ARCHIVIST" TYPE="ORGANIZATION">' \
          '<mets:name>zzz</mets:name></mets:agent>' \
          '<mets:agent ROLE="CREATOR" TYPE="OTHER" OTHERTYPE="SOFTWARE">' \
          '<mets:name>Pekan Paketointipalvelu Öy</mets:name></mets:agent>' \
          '</mets:metsHdr>'
    hdr = m.metshdr(create_date='2017-12-12T12:12:12',
                    record_status='submission',
                    agents=[
                        m.agent('zzz'),
                        m.agent('zzz', agent_role='ARCHIVIST'),
                        m.agent('Pekan Paketointipalvelu Öy',
                                agent_role='CREATOR',
                                agent_type='OTHER',
                                othertype='SOFTWARE')
                    ])
    assert u.compare_trees(hdr, ET.fromstring(xml)) is True
Exemple #6
0
def test_event():
    """Test event"""
    event = e.event(p.identifier('a', 'b', 'event'),
                    'c',
                    'd',
                    'e',
                    linking_objects=[p.identifier('f', 'g')])
    xml = ('<premis:event xmlns:premis="info:lc/xmlns/premis-v2">'
           '<premis:eventIdentifier><premis:eventIdentifierType>a'
           '</premis:eventIdentifierType><premis:eventIdentifierValue>b'
           '</premis:eventIdentifierValue></premis:eventIdentifier>'
           '<premis:eventType>c</premis:eventType>'
           '<premis:eventDateTime>d</premis:eventDateTime>'
           '<premis:eventDetail>e</premis:eventDetail>'
           '<premis:linkingObjectIdentifier>'
           '<premis:linkingObjectIdentifierType>'
           'f'
           '</premis:linkingObjectIdentifierType>'
           '<premis:linkingObjectIdentifierValue>'
           'g'
           '</premis:linkingObjectIdentifierValue>'
           '</premis:linkingObjectIdentifier></premis:event>')
    assert u.compare_trees(event, ET.fromstring(xml))
Exemple #7
0
def test_iter_environments():
    """Test the iter_environments function. Test asserts that the
    environment was yielded from the created test data and that its
    contents matches the expected premis XML.
    """
    env = o.environment(child_elements=[
        o.dependency(identifiers=[p.identifier('c', 'd', 'dependency')])
    ])
    obj = o.object(p.identifier('x', 'y', 'object'), child_elements=[env])

    xml = ('<premis:environment xmlns:premis="info:lc/xmlns/premis-v2" '
           'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
           '<premis:dependency>'
           '<premis:dependencyIdentifier><premis:dependencyIdentifierType>'
           'c</premis:dependencyIdentifierType>'
           '<premis:dependencyIdentifierValue>'
           'd</premis:dependencyIdentifierValue></premis:dependencyIdentifier>'
           '</premis:dependency></premis:environment>')

    i = 0
    for penv in o.iter_environments(obj):
        i = i + 1
        assert u.compare_trees(penv, ET.fromstring(xml))
    assert i == 1
Exemple #8
0
def test_parse_dependency():
    """Test parse_dependency"""

    env = o.environment(child_elements=[
        o.dependency(
            identifiers=[p.identifier('e', 'f', prefix='dependency')]),
        o.dependency(identifiers=[p.identifier('c', 'd', prefix='dependency')])
    ])
    obj = o.object(p.identifier('x', 'y', 'object'), child_elements=[env])
    dep = o.parse_dependency(obj)

    xml1 = ('<premis:dependency xmlns:premis="info:lc/xmlns/premis-v2" '
            'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
            '<premis:dependencyIdentifier><premis:dependencyIdentifierType>'
            'e</premis:dependencyIdentifierType>'
            '<premis:dependencyIdentifierValue>'
            'f</premis:dependencyIdentifierValue>'
            '</premis:dependencyIdentifier>'
            '</premis:dependency>')

    xml2 = ('<premis:dependency xmlns:premis="info:lc/xmlns/premis-v2" '
            'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
            '<premis:dependencyIdentifier><premis:dependencyIdentifierType>'
            'c</premis:dependencyIdentifierType>'
            '<premis:dependencyIdentifierValue>'
            'd</premis:dependencyIdentifierValue>'
            '</premis:dependencyIdentifier>'
            '</premis:dependency>')

    test_list = [xml1, xml2]

    i = 0

    for iter_depend in dep:
        assert u.compare_trees(iter_depend, ET.fromstring(test_list[i]))
        i += 1
Exemple #9
0
def test_jpeg2000():
    """Test that the element JPEG2000 is created correctly."""
    mix = jpeg2000(codec='jp2',
                   codec_version='1.0',
                   codestream_profile='P1',
                   compliance_class='C0',
                   tile_width=1,
                   tile_height=2,
                   quality_layers=3,
                   resolution_levels=4)

    xml_str = ('<mix:JPEG2000 xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:CodecCompliance><mix:codec>jp2</mix:codec>'
               '<mix:codecVersion>1.0</mix:codecVersion>'
               '<mix:codestreamProfile>P1</mix:codestreamProfile>'
               '<mix:complianceClass>C0</mix:complianceClass>'
               '</mix:CodecCompliance><mix:EncodingOptions><mix:Tiles>'
               '<mix:tileWidth>1</mix:tileWidth>'
               '<mix:tileHeight>2</mix:tileHeight></mix:Tiles>'
               '<mix:qualityLayers>3</mix:qualityLayers>'
               '<mix:resolutionLevels>4</mix:resolutionLevels>'
               '</mix:EncodingOptions></mix:JPEG2000>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
def test_subelement():
    """Test PREMIS _subelement"""
    xml = """<premis:xxx xmlns:premis="info:lc/xmlns/premis-v2"/>"""
    parent_xml = """<premis:premis xmlns:premis="info:lc/xmlns/premis-v2"/>"""
    parent = ET.fromstring(parent_xml)
    assert u.compare_trees(p._subelement(parent, 'xxx'), ET.fromstring(xml))
def test_element():
    """Test PREMIS _element"""
    xml = """<premis:xxx xmlns:premis="info:lc/xmlns/premis-v2"/>"""
    assert u.compare_trees(p._element('xxx'), ET.fromstring(xml))
Exemple #12
0
def test_amdsec():
    """test amdsec"""
    xml = '<mets:amdSec xmlns:mets="http://www.loc.gov/METS/"/>'
    amd = m.amdsec()
    assert u.compare_trees(amd, ET.fromstring(xml)) is True
Exemple #13
0
def test_digiprovmd():
    """test digiprovmd"""
    xml = '<mets:digiprovMD xmlns:mets="http://www.loc.gov/METS/" ' \
          'ID="xxx" CREATED="2017-12-12T12:12:12"/>'
    digiprov = m.digiprovmd('xxx', created_date='2017-12-12T12:12:12')
    assert u.compare_trees(digiprov, ET.fromstring(xml)) is True
Exemple #14
0
def test_techmd():
    """test techmd"""
    xml = '<mets:techMD xmlns:mets="http://www.loc.gov/METS/" ' \
          'ID="xxx" CREATED="2017-12-12T12:12:12"/>'
    tech = m.techmd('xxx', created_date='2017-12-12T12:12:12')
    assert u.compare_trees(tech, ET.fromstring(xml)) is True
def test_element():
    """Test METS _element"""
    xml = """<mets:xxx xmlns:mets="http://www.loc.gov/METS/"/>"""
    assert u.compare_trees(m._element('xxx'), ET.fromstring(xml)) is True
def test_div():
    """test div"""
    xml = '<mets:div xmlns:mets="http://www.loc.gov/METS/" ' \
          'TYPE="xxx"/>'
    div = m.div(type_attr='xxx')
    assert u.compare_trees(div, ET.fromstring(xml)) is True
def test_element():
    """Test ADDML _element"""
    xml = """<addml:xxx
        xmlns:addml="http://www.arkivverket.no/standarder/addml"/>"""
    assert h.compare_trees(a._element('xxx'), ET.fromstring(xml)) is True
def test_element_with_prefix():
    """Test ADDML _elementi with a prefix."""
    xml = """<addml:flatFileDefinition
        xmlns:addml="http://www.arkivverket.no/standarder/addml"/>"""
    assert h.compare_trees(a._element('definition', prefix="flatFile"),
                           ET.fromstring(xml)) is True
Exemple #19
0
def test_image_data():
    """Tests that the element ImageData is created correctly."""

    contents = {
        "fnumber": "1",
        "exposure_time": "2",
        "exposure_program": "3",
        "spectral_sensitivity": ["4", "4b"],
        "isospeed_ratings": 5,
        "oecf": 6,
        "exif_version": "7",
        "shutter_speed_value": 8,
        "aperture_value": 9,
        "brightness_value": 10,
        "exposure_bias_value": 11,
        "max_aperture_value": 12,
        "distance": "13",
        "min_distance": "14",
        "max_distance": "15",
        "metering_mode": "16",
        "light_source": "17",
        "flash": "18",
        "focal_length": "19",
        "flash_energy": 20,
        "back_light": "21",
        "exposure_index": "22",
        "sensing_method": "23",
        "cfa_pattern": 24,
        "auto_focus": "25",
        "x_print_aspect_ratio": "26",
        "y_print_aspect_ratio": "27"
    }

    mix = image_data(contents=contents)

    xml_str = ('<mix:ImageData '
               'xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:fNumber>1</mix:fNumber><mix:exposureTime>2'
               '</mix:exposureTime><mix:exposureProgram>3'
               '</mix:exposureProgram>'
               '<mix:spectralSensitivity>4</mix:spectralSensitivity>'
               '<mix:spectralSensitivity>4b</mix:spectralSensitivity>'
               '<mix:isoSpeedRatings>5</mix:isoSpeedRatings>'
               '<mix:oECF><mix:numerator>6</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:oECF>'
               '<mix:exifVersion>7</mix:exifVersion>'
               '<mix:shutterSpeedValue><mix:numerator>8</mix:numerator>'
               '<mix:denominator>1</mix:denominator>'
               '</mix:shutterSpeedValue><mix:apertureValue>'
               '<mix:numerator>9</mix:numerator>'
               '<mix:denominator>1</mix:denominator>'
               '</mix:apertureValue><mix:brightnessValue>'
               '<mix:numerator>10</mix:numerator>'
               '<mix:denominator>1</mix:denominator>'
               '</mix:brightnessValue><mix:exposureBiasValue>'
               '<mix:numerator>11</mix:numerator>'
               '<mix:denominator>1</mix:denominator>'
               '</mix:exposureBiasValue><mix:maxApertureValue>'
               '<mix:numerator>12</mix:numerator>'
               '<mix:denominator>1</mix:denominator>'
               '</mix:maxApertureValue><mix:SubjectDistance>'
               '<mix:distance>13</mix:distance><mix:MinMaxDistance>'
               '<mix:minDistance>14</mix:minDistance>'
               '<mix:maxDistance>15</mix:maxDistance>'
               '</mix:MinMaxDistance></mix:SubjectDistance>'
               '<mix:meteringMode>16</mix:meteringMode>'
               '<mix:lightSource>17</mix:lightSource><mix:flash>18</mix:flash>'
               '<mix:focalLength>19</mix:focalLength><mix:flashEnergy>'
               '<mix:numerator>20</mix:numerator>'
               '<mix:denominator>1</mix:denominator>'
               '</mix:flashEnergy><mix:backLight>21</mix:backLight>'
               '<mix:exposureIndex>22</mix:exposureIndex>'
               '<mix:sensingMethod>23</mix:sensingMethod>'
               '<mix:cfaPattern>24</mix:cfaPattern>'
               '<mix:autoFocus>25</mix:autoFocus><mix:PrintAspectRatio>'
               '<mix:xPrintAspectRatio>26</mix:xPrintAspectRatio>'
               '<mix:yPrintAspectRatio>27</mix:yPrintAspectRatio>'
               '</mix:PrintAspectRatio></mix:ImageData>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
Exemple #20
0
def test_gps_data():
    """Test that the element GPSData is
    created correctly.
    """

    contents = {
        "version_id": "1",
        "lat_ref": "2",
        "lat_degrees": 3,
        "lat_minutes": 4,
        "lat_seconds": 5,
        "long_ref": "6",
        "long_degrees": 7,
        "long_minutes": 8,
        "long_seconds": 9,
        "altitude_ref": "10",
        "altitude": 11,
        "timestamp": "12",
        "satellites": "13",
        "status": "14",
        "measure_mode": "15",
        "dop": 16,
        "speed_ref": "17",
        "speed": 18,
        "track_ref": "19",
        "track": 20,
        "img_direction_ref": "21",
        "direction": 22,
        "map_datum": "23",
        "dest_lat_ref": "24",
        "dest_lat_degrees": 25,
        "dest_lat_minutes": 26,
        "dest_lat_seconds": 27,
        "dest_long_ref": "28",
        "dest_long_degrees": 29,
        "dest_long_minutes": 30,
        "dest_long_seconds": 31,
        "dest_bearing_ref": "32",
        "dest_bearing": 33,
        "dest_distance_ref": "34",
        "dest_distance": [35, 3],
        "processing_method": "36",
        "area_information": "37",
        "datestamp": "38",
        "differential": "39",
        "gps_groups": "40"
    }

    mix = gps_data(contents=contents)

    xml_str = ('<mix:GPSData xmlns:mix="http://www.loc.gov/mix/v20">'
               '<mix:gpsVersionID>1</mix:gpsVersionID><mix:gpsLatitudeRef>2'
               '</mix:gpsLatitudeRef><mix:GPSLatitude><mix:degrees>'
               '<mix:numerator>3</mix:numerator><mix:denominator>1'
               '</mix:denominator></mix:degrees><mix:minutes><mix:numerator>4'
               '</mix:numerator><mix:denominator>1</mix:denominator>'
               '</mix:minutes><mix:seconds><mix:numerator>5</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:seconds>'
               '</mix:GPSLatitude><mix:gpsLongitudeRef>6</mix:gpsLongitudeRef>'
               '<mix:GPSLongitude><mix:degrees><mix:numerator>7'
               '</mix:numerator><mix:denominator>1</mix:denominator>'
               '</mix:degrees><mix:minutes><mix:numerator>8</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:minutes>'
               '<mix:seconds><mix:numerator>9</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:seconds>'
               '</mix:GPSLongitude><mix:gpsAltitudeRef>10</mix:gpsAltitudeRef>'
               '<mix:gpsAltitude><mix:numerator>11</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:gpsAltitude>'
               '<mix:gpsTimeStamp>12</mix:gpsTimeStamp><mix:gpsSatellites>13'
               '</mix:gpsSatellites><mix:gpsStatus>14</mix:gpsStatus>'
               '<mix:gpsMeasureMode>15</mix:gpsMeasureMode><mix:gpsDOP>'
               '<mix:numerator>16</mix:numerator><mix:denominator>1'
               '</mix:denominator></mix:gpsDOP><mix:gpsSpeedRef>17'
               '</mix:gpsSpeedRef><mix:gpsSpeed><mix:numerator>18'
               '</mix:numerator><mix:denominator>1</mix:denominator>'
               '</mix:gpsSpeed><mix:gpsTrackRef>19</mix:gpsTrackRef>'
               '<mix:gpsTrack><mix:numerator>20</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:gpsTrack>'
               '<mix:gpsImgDirectionRef>21</mix:gpsImgDirectionRef>'
               '<mix:gpsImgDirection><mix:numerator>22</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:gpsImgDirection>'
               '<mix:gpsMapDatum>23</mix:gpsMapDatum>'
               '<mix:gpsDestLatitudeRef>24</mix:gpsDestLatitudeRef>'
               '<mix:GPSDestLatitude><mix:degrees><mix:numerator>25'
               '</mix:numerator><mix:denominator>1</mix:denominator>'
               '</mix:degrees><mix:minutes><mix:numerator>26</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:minutes>'
               '<mix:seconds><mix:numerator>27</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:seconds>'
               '</mix:GPSDestLatitude><mix:gpsDestLongitudeRef>28'
               '</mix:gpsDestLongitudeRef><mix:GPSDestLongitude>'
               '<mix:degrees><mix:numerator>29</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:degrees>'
               '<mix:minutes><mix:numerator>30</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:minutes>'
               '<mix:seconds><mix:numerator>31</mix:numerator>'
               '<mix:denominator>1</mix:denominator></mix:seconds>'
               '</mix:GPSDestLongitude><mix:gpsDestBearingRef>32'
               '</mix:gpsDestBearingRef><mix:gpsDestBearing><mix:numerator>33'
               '</mix:numerator><mix:denominator>1</mix:denominator>'
               '</mix:gpsDestBearing><mix:gpsDestDistanceRef>34'
               '</mix:gpsDestDistanceRef><mix:gpsDestDistance>'
               '<mix:numerator>35</mix:numerator><mix:denominator>3'
               '</mix:denominator></mix:gpsDestDistance>'
               '<mix:gpsProcessingMethod>36</mix:gpsProcessingMethod>'
               '<mix:gpsAreaInformation>37</mix:gpsAreaInformation>'
               '<mix:gpsDateStamp>38</mix:gpsDateStamp><mix:gpsDifferential>39'
               '</mix:gpsDifferential></mix:GPSData>')

    assert h.compare_trees(mix, ET.fromstring(xml_str))
def test_compare_trees(compare_tree_xml, xml, expected):
    """Test compare_trees-function."""
    assert u.compare_trees(ET.fromstring(compare_tree_xml.base()),
                           ET.fromstring(getattr(compare_tree_xml,
                                                 xml)())) == expected
Exemple #22
0
def test_filegrp():
    """test filegrp"""
    xml = '<mets:fileGrp xmlns:mets="http://www.loc.gov/METS/" ' \
          'USE="xxx"/>'
    fgrp = m.filegrp(use='xxx')
    assert u.compare_trees(fgrp, ET.fromstring(xml)) is True
def test_fptr():
    """test fptr"""
    xml = '<mets:fptr xmlns:mets="http://www.loc.gov/METS/" ' \
          'FILEID="xxx"/>'
    fptr = m.fptr('xxx')
    assert u.compare_trees(fptr, ET.fromstring(xml)) is True
Exemple #24
0
def test_filesec():
    """test filegrp"""
    xml = '<mets:fileSec xmlns:mets="http://www.loc.gov/METS/"/>'
    fsec = m.filesec()
    assert u.compare_trees(fsec, ET.fromstring(xml)) is True
def test_structmap():
    """test div"""
    xml = '<mets:structMap xmlns:mets="http://www.loc.gov/METS/"/>'
    smap = m.structmap()
    assert u.compare_trees(smap, ET.fromstring(xml)) is True
Exemple #26
0
def test_xmldata():
    """test xmldata"""
    xml = '<mets:xmlData xmlns:mets="http://www.loc.gov/METS/"/>'
    data = mets.xmldata()
    assert compare_trees(data, ET.fromstring(xml)) is True