コード例 #1
0
def test_storage_name():
    em.set_ofr(None)
    mock_obs_id = 'GN-2013B-Q-28-150-002'
    test_sn = GemName(file_name='N20131203S0006i.fits.bz2', obs_id=mock_obs_id)
    assert test_sn.file_uri == f'{SCHEME}:{ARCHIVE}/N20131203S0006i.fits'
    assert test_sn.file_name == 'N20131203S0006i.fits'
    assert test_sn.prev == 'N20131203S0006i.jpg'
    assert test_sn.thumb == 'N20131203S0006i_th.jpg'
    assert test_sn.compressed_file_name is None
    assert test_sn.get_file_id(test_sn.file_name) == 'N20131203S0006i'

    test_sn = GemName(file_name='S20060920S0137.jpg', obs_id=mock_obs_id)
    assert test_sn.file_uri == f'{SCHEME}:{ARCHIVE}/S20060920S0137.jpg'
    assert test_sn.file_name == 'S20060920S0137.jpg'
    assert test_sn.prev == 'S20060920S0137.jpg'
    assert test_sn.thumb == 'S20060920S0137_th.jpg'
    assert test_sn.compressed_file_name is None

    test_sn = GemName(fname_on_disk='N20100104S0208.fits.header')
    assert test_sn.obs_id == 'GN-2009B-Q-121-15-001', 'wrong obs id'
    assert test_sn.file_uri == f'{SCHEME}:{ARCHIVE}/N20100104S0208.fits'
    assert test_sn.external_urls == 'https://archive.gemini.edu/fullheader/' \
                                    'N20100104S0208.fits'

    test_sn = GemName(fname_on_disk='N20200810A0490r.fits',
                      instrument=em.Inst.ALOPEKE)
    assert test_sn.obs_id == 'N20200810A0490', 'wrong obs id'
    assert test_sn.product_id == 'N20200810A0490r', 'wrong product id'
    assert test_sn.file_uri == f'{SCHEME}:{ARCHIVE}/N20200810A0490r.fits'
    assert test_sn.external_urls == 'https://archive.gemini.edu/fullheader/' \
                                    'N20200810A0490r.fits'
    assert test_sn.lineage == f'{test_sn.obs_id}r/{SCHEME}:{ARCHIVE}/' \
                              f'{test_sn.file_id}.fits', 'wrong lineage'
コード例 #2
0
def test_storage_name():
    mock_obs_id = 'GN-2013B-Q-28-150-002'
    test_sn = GemName(file_name='N20131203S0006i.fits.bz2', obs_id=mock_obs_id)
    assert test_sn.file_uri == '{}:{}/N20131203S0006i.fits'.format(
        SCHEME, ARCHIVE)
    assert test_sn.file_name == 'N20131203S0006i.fits'
    assert test_sn.prev == 'N20131203S0006i.jpg'
    assert test_sn.thumb == 'N20131203S0006i_th.jpg'
    assert test_sn.compressed_file_name is None
    assert test_sn.get_file_id(test_sn.file_name) == 'N20131203S0006i'

    test_sn = GemName(file_name='S20060920S0137.jpg', obs_id=mock_obs_id)
    assert test_sn.file_uri == '{}:{}/S20060920S0137.jpg'.format(
        SCHEME, ARCHIVE)
    assert test_sn.file_name == 'S20060920S0137.jpg'
    assert test_sn.prev == 'S20060920S0137.jpg'
    assert test_sn.thumb == 'S20060920S0137_th.jpg'
    assert test_sn.compressed_file_name is None
コード例 #3
0
def test_storage_name(tap_mock, cap_mock):
    tap_mock.side_effect = gem_mocks.mock_query_tap
    cap_mock.return_value = 'https://localhost'
    test_config = mc.Config()
    test_config.proxy_fqn = path.join(gem_mocks.TEST_DATA_DIR, 'cadcproxy.pem')
    test_config.tap_id = 'ivo://cadc.nrc.ca/test'
    test_sn = GemName(file_name='N20131203S0006i.fits.bz2')
    assert (
        test_sn.file_uri == f'{SCHEME}:{COLLECTION}/N20131203S0006i.fits.bz2')
    assert test_sn.file_name == 'N20131203S0006i.fits.bz2'
    assert test_sn.prev == 'N20131203S0006i.jpg'
    assert test_sn.thumb == 'N20131203S0006i_th.jpg'
    assert test_sn.file_id == 'N20131203S0006i'

    test_sn = GemName(file_name='S20060920S0137.jpg')
    assert test_sn.file_uri == f'{SCHEME}:{COLLECTION}/S20060920S0137.jpg'
    assert test_sn.file_name == 'S20060920S0137.jpg'
    assert test_sn.prev == 'S20060920S0137.jpg'
    assert test_sn.thumb == 'S20060920S0137_th.jpg'
コード例 #4
0
def _update_last_modified(obs):
    max_last_modified = datetime(1970, 1, 1).timestamp()
    for p in obs.planes:
        for a in obs.planes[p].artifacts:
            file_name = ex_comp.CaomName(
                obs.planes[p].artifacts[a].uri).file_name
            file_id = GemName.remove_extensions(file_name)
            ts = em.gofr.get_timestamp(file_id)
            max_last_modified = max(ts, max_last_modified)
            ts_dt = datetime.fromtimestamp(ts)
            obs.planes[p].max_last_modified = ts_dt
            obs.planes[p].artifacts[a].max_last_modified = ts_dt
            obs.planes[p].last_modified = ts_dt
            obs.planes[p].artifacts[a].last_modified = ts_dt
            for pt in obs.planes[p].artifacts[a].parts:
                obs.planes[p].artifacts[a].parts[pt].max_last_modified = ts_dt
                obs.planes[p].artifacts[a].parts[pt].last_modified = ts_dt
                for c in obs.planes[p].artifacts[a].parts[pt].chunks:
                    c.max_last_modified = ts_dt
                    c.last_modified = ts_dt
    max_dt = datetime.fromtimestamp(max_last_modified)
    obs.max_last_modified = max_dt
    obs.last_modified = max_dt
コード例 #5
0
def test_preview_augment_plane(mock_obs_id):
    mock_obs_id.return_value = TEST_OBS
    thumb = os.path.join(TESTDATA_DIR,
                         'GMOS/{}'.format(GemName(TEST_FILE).thumb))
    if os.path.exists(thumb):
        os.remove(thumb)
    test_fqn = os.path.join(TESTDATA_DIR, '{}/{}.in.xml'.format(
        'GMOS', TEST_OBS))
    test_obs = mc.read_obs_from_file(test_fqn)
    assert len(test_obs.planes[TEST_OBS].artifacts) == 2
    thumba = '{}:{}/N20131203S0006_th.jpg'.format(SCHEME, ARCHIVE)

    test_kwargs = {'working_directory': '{}/GMOS'.format(TESTDATA_DIR),
                   'cadc_client': None,
                   'stream': 'default'}
    test_result = preview_augmentation.visit(test_obs, **test_kwargs)
    assert test_result is not None, 'expected a visit return value'
    assert test_result['artifacts'] == 1
    assert len(test_obs.planes[TEST_OBS].artifacts) == 3
    assert os.path.exists(thumb)
    assert test_obs.planes[TEST_OBS].artifacts[thumba].content_checksum == \
        ChecksumURI('md5:a8c106c04db4c148695787bfc364cbd8'), \
        'thumb checksum failure'

    # now do updates
    test_obs.planes[TEST_OBS].artifacts[thumba].content_checksum = \
        ChecksumURI('19661c3c2508ecc22425ee2a05881ed4')
    test_result = preview_augmentation.visit(test_obs, **test_kwargs)
    assert test_result is not None, 'expected update visit return value'
    assert test_result['artifacts'] == 1
    assert len(test_obs.planes) == 1
    assert len(test_obs.planes[TEST_OBS].artifacts) == 3
    assert os.path.exists(thumb)
    assert test_obs.planes[TEST_OBS].artifacts[thumba].content_checksum == \
        ChecksumURI('md5:a8c106c04db4c148695787bfc364cbd8'), \
        'thumb update failed'
コード例 #6
0
def test_is_valid():
    assert GemName(file_name='anything.fits').is_valid()
    assert GemName(file_name='anything.jpg').is_valid()
コード例 #7
0
def test_is_valid():
    mock_obs_id = 'GN-2013B-Q-28-150-002'
    assert GemName(file_name='anything.fits', obs_id=mock_obs_id).is_valid()
    assert GemName(file_name='anything.jpg', obs_id=mock_obs_id).is_valid()