コード例 #1
0
def test_visitor(test_name):
    dao_name = DAOName(basename(test_name).replace('.header', '.gz'))
    file_info = FileInfo(id=dao_name.file_uri, file_type='application/fits')
    headers = ac.make_headers_from_file(test_name)
    metadata_reader = rdc.FileMetadataReader()
    metadata_reader._headers = {dao_name.file_uri: headers}
    metadata_reader._file_info = {dao_name.file_uri: file_info}
    kwargs = {
        'storage_name': dao_name,
        'metadata_reader': metadata_reader,
    }
    expected_fqn = (f'{TEST_DATA_DIR}/{dao_name.file_id}.expected.xml')
    actual_fqn = expected_fqn.replace('expected', 'actual')
    if exists(actual_fqn):
        unlink(actual_fqn)
    observation = None
    observation = fits2caom2_augmentation.visit(observation, **kwargs)

    expected = mc.read_obs_from_file(expected_fqn)
    compare_result = get_differences(expected, observation)
    if compare_result is not None:
        mc.write_obs_to_file(observation, actual_fqn)
        compare_text = '\n'.join([r for r in compare_result])
        msg = (f'Differences found in observation {expected.observation_id}\n'
               f'{compare_text}')
        raise AssertionError(msg)
コード例 #2
0
def test_multi_plane(data_client_mock, test_name):
    dao_name = DAOName(file_name=f'{LOOKUP[test_name][0]}.fits')
    lineage = _get_lineage(dao_name.obs_id)
    expected_fqn = f'{test_main_app.TEST_DATA_DIR}/{DIR_NAME}/' \
                   f'{dao_name.obs_id}.expected.xml'
    actual_fqn = f'{test_main_app.TEST_DATA_DIR}/{DIR_NAME}/' \
                 f'{dao_name.obs_id}.actual.xml'

    local = _get_local(test_name)
    plugin = test_main_app.PLUGIN

    data_client_mock.return_value.get_file_info.side_effect = \
        test_main_app._get_file_info

    if os.path.exists(actual_fqn):
        os.remove(actual_fqn)

    sys.argv = \
        (f'{APPLICATION} --quiet --no_validate --local {local} '
         f'--observation {COLLECTION} {dao_name.obs_id} '
         f'--plugin {plugin} --module {plugin} --out {actual_fqn} '
         f'--lineage {lineage}').split()
    print(sys.argv)
    try:
        main_app.to_caom2()
    except Exception as e:
        import logging
        import traceback
        logging.error(traceback.format_exc())

    compare_result = mc.compare_observations(actual_fqn, expected_fqn)
    if compare_result is not None:
        raise AssertionError(compare_result)
コード例 #3
0
def test_processed():
    test_subject = DAOName('dao_c122_2020_004100_v.fits.gz')
    assert test_subject is not None, 'expect a value'
    assert test_subject.obs_id == 'dao_c122_2020_004100', 'wrong obs id'
    assert (
        test_subject.file_name == 'dao_c122_2020_004100_v.fits.gz'
    ), 'wrong file name'
    assert (
        test_subject.product_id == 'dao_c122_2020_004100_v'
    ), 'wrong product id'
    assert test_subject.file_id == 'dao_c122_2020_004100_v', 'wrong file id'
    assert (
        test_subject.source_names == ['dao_c122_2020_004100_v.fits.gz']
    ), 'wrong source names'
    assert (
        test_subject.destination_uris ==
        [f'cadc:{PRODUCT_COLLECTION}/dao_c122_2020_004100_v.fits']
    ), 'wrong destination uris'
    assert (
        test_subject.file_uri ==
        f'cadc:{PRODUCT_COLLECTION}/dao_c122_2020_004100_v.fits'
    ), 'wrong file uri'
    assert (
            test_subject.collection == PRODUCT_COLLECTION
    ), 'wrong collection'
コード例 #4
0
def test_raw():
    test_result = DAOName('cadc:DAO/dao_c182_2018_015013.fits')
    assert test_result is not None, 'expect a result'
    assert test_result.obs_id == 'dao_c182_2018_015013'
    assert test_result.file_name == 'dao_c182_2018_015013.fits'
    assert test_result.file_id == 'dao_c182_2018_015013'
    assert test_result.source_names == ['cadc:DAO/dao_c182_2018_015013.fits']
    assert (
        test_result.destination_uris == ['cadc:DAO/dao_c182_2018_015013.fits']
    ), 'wrong destination uris'

    test_result_2 = DAOName(
        '/usr/src/app/dao_c182_2018_015013/dao_c182_2018_015013.fits.gz'
    )
    assert (
        test_result_2.source_names ==
        ['/usr/src/app/dao_c182_2018_015013/dao_c182_2018_015013.fits.gz']
    )
    assert (
        test_result_2.destination_uris ==
        [f'cadc:{COLLECTION}/dao_c182_2018_015013.fits']
    ), 'wrong destination uris'
コード例 #5
0
def test_ctor():
    test_subject = DAOName(file_name='dao_c122_2020_004100_v.fits')
    assert test_subject is not None, 'expect a value'
    assert test_subject.obs_id == 'dao_c122_2020_004100', 'wrong obs id'
    assert test_subject.fname_on_disk == 'dao_c122_2020_004100_v.fits', \
        'wrong fname on disk'
    assert test_subject.fname_in_ad == 'dao_c122_2020_004100_v.fits', \
        'wrong fname in ad'
    assert test_subject.file_name == 'dao_c122_2020_004100_v.fits', \
        'wrong file name'
    assert test_subject.product_id == 'dao_c122_2020_004100_v', \
        'wrong product id'
    assert test_subject.file_id == 'dao_c122_2020_004100_v', \
        'wrong file id'
コード例 #6
0
def test_failure():
    test_fqn = (
        f'{test_fits2caom2_augmentation.TEST_DATA_DIR}/broken_data/'
        f'dao_c122_2001_006946.fits.header'
    )
    dao_name = DAOName(basename(test_fqn).replace('.header', '.gz'))
    file_info = FileInfo(id=dao_name.file_uri, file_type='application/fits')
    headers = ac.make_headers_from_file(test_fqn)
    metadata_reader = rdc.FileMetadataReader()
    metadata_reader._headers = {dao_name.file_uri: headers}
    metadata_reader._file_info = {dao_name.file_uri: file_info}
    kwargs = {
        'storage_name': dao_name,
        'metadata_reader': metadata_reader,
    }
    observation = None
    observation = fits2caom2_augmentation.visit(observation, **kwargs)
    assert observation is None, 'failure, no observation creation'
コード例 #7
0
def test_main_app(data_client_mock, test_name):
    data_client_mock.return_value.get_file_info.side_effect = _get_file_info
    basename = os.path.basename(test_name)
    dao_name = DAOName(file_name=basename.replace('.header', '.gz'))

    obs_path = f'{TEST_DATA_DIR}/{dao_name.obs_id}.expected.xml'
    output_file = f'{TEST_DATA_DIR}/{dao_name.obs_id}.actual.xml'

    sys.argv = \
        (f'{APPLICATION} --no_validate --local {test_name} '
         f'--observation {COLLECTION} {dao_name.obs_id} -o {output_file} '
         f'--plugin {PLUGIN} --module {PLUGIN} --lineage '
         f'{dao_name.lineage}').split()
    print(sys.argv)
    try:
        main_app.to_caom2()
    except Exception as e:
        import logging
        import traceback
        logging.error(traceback.format_exc())

    compare_result = mc.compare_observations(output_file, obs_path)
    if compare_result is not None:
        raise AssertionError(compare_result)
コード例 #8
0
def test_is_valid():
    assert DAOName('anything').is_valid()
コード例 #9
0
def test_is_valid():
    assert DAOName(file_name='anything').is_valid()