Exemple #1
0
def test_tags_unique(database):
    entry = DatabaseEntry()
    entry.tags = [Tag('foo')]
    database.add(entry)
    database.commit()
    entry.tags.append(Tag('foo'))
    with pytest.raises(sqlalchemy.orm.exc.FlushError):
        database.commit()
Exemple #2
0
def test_unstar_undo(database):
    entry = DatabaseEntry()
    entry.starred = True
    database.unstar(entry)
    assert not entry.starred
    database.undo()
    assert entry.starred
    database.redo()
    assert not entry.starred
Exemple #3
0
def test_entry_from_qr_block_with_missing_physobs(qr_block_with_missing_physobs):
    entry = DatabaseEntry._from_query_result_block(qr_block_with_missing_physobs)
    expected_entry = DatabaseEntry(
        source='STEREO_A', provider='SSC',
        fileid='swaves/2013/swaves_average_20130805_a_hfr.dat',
        observation_time_start=datetime(2013, 8, 5),
        observation_time_end=datetime(2013, 8, 6), instrument='SWAVES',
        size=3601.08, wavemin=2398339664000.0, wavemax=18737028625.0)
    assert entry == expected_entry
Exemple #4
0
def test_entry_from_qr_block(query_result):
    entry = DatabaseEntry._from_query_result_block(query_result[0])
    expected_entry = DatabaseEntry(
        source='SOHO', provider='SDAC', physobs='intensity',
        fileid='/archive/soho/private/data/processed/eit/lz/2001/01/efz20010101.010014',
        observation_time_start=datetime(2001, 1, 1, 1, 0, 14),
        observation_time_end=datetime(2001, 1, 1, 1, 0, 21),
        instrument='EIT', size=2059.0, wavemin=17.1, wavemax=17.1)
    assert entry == expected_entry
Exemple #5
0
def test_from_fido_search_result_block(fido_search_result):
    entry = DatabaseEntry._from_fido_search_result_block(
        fido_search_result[0, 0][0].get_response(0)[0])
    expected_entry = DatabaseEntry(
        source='Proba2', provider='esa', physobs='irradiance',
        fileid='http://proba2.oma.be/lyra/data/bsd/2012/01/01/lyra_20120101-000000_lev2_std.fits',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        wavemin=np.nan, wavemax=np.nan,
        instrument='lyra')
    assert entry == expected_entry
Exemple #6
0
def test_entry_from_qr_block_kev(qr_block_with_kev_unit):
    # See issue #766.
    entry = DatabaseEntry._from_query_result_block(qr_block_with_kev_unit)
    assert entry.source == 'RHESSI'
    assert entry.provider == 'LSSP'
    assert entry.fileid == '/hessidata/2011/09/20/hsi_20110920_010920'
    assert entry.observation_time_start == datetime(2011, 9, 20, 1, 9, 20)
    assert entry.observation_time_end == datetime(2011, 9, 20, 2, 27, 40)
    assert entry.instrument == 'RHESSI'
    assert entry.size == -1
    assert round(entry.wavemin, 3) == 0.413
    assert round(entry.wavemax, 7) == 0.0000729
Exemple #7
0
def test_entry_from_qr_block_kev(qr_block_with_kev_unit):
    # See issue #766.
    entry = DatabaseEntry._from_query_result_block(qr_block_with_kev_unit)
    assert entry.source == 'RHESSI'
    assert entry.provider == 'LSSP'
    # TODO: Flaky test that needs a fix
    assert entry.fileid in ['/hessidata/2011/09/19/hsi_20110919_233340',
                            '/hessidata/2011/09/20/hsi_20110920_010920']
    assert entry.observation_time_start in [datetime(2011, 9, 20, 1, 9, 20),
                                            datetime(2011, 9, 19, 23, 33, 40)]
    assert entry.observation_time_end in [datetime(2011, 9, 20, 2, 27, 40),
                                          datetime(2011, 9, 20, 1, 9, 20)]
    assert entry.instrument == 'RHESSI'
    assert round(entry.wavemin, 3) == 0.413
    assert round(entry.wavemax, 7) == 0.0000729
Exemple #8
0
def test_remove_nonexisting_entry(database):
    with pytest.raises(NoSuchEntryError):
        database.remove(DatabaseEntry())
Exemple #9
0
def test_add_already_existing_entry(database):
    entry = DatabaseEntry()
    database.add(entry)
    database.commit()
    with pytest.raises(EntryAlreadyAddedError):
        database.add(entry)
Exemple #10
0
def test_add_already_existing_entry_ignore(database):
    entry = DatabaseEntry()
    database.add(entry)
    database.add(entry, True)
    database.commit()
    assert entry.id == 1
Exemple #11
0
def test_len(database):
    assert len(database) == 0
    database.session.add(DatabaseEntry())
    assert len(database) == 1
Exemple #12
0
def test_entries_from_fido_search_result(fido_search_result):
    entries = list(entries_from_fido_search_result(fido_search_result))
    # 66 entries for 8 instruments in fido_search_result
    assert len(entries) == 66
    # First 2 entries are from lyra
    assert entries[0] == DatabaseEntry(
        source='PROBA2',
        provider='ESA',
        physobs='irradiance',
        fileid=
        'http://proba2.oma.be/lyra/data/bsd/2012/01/01/lyra_20120101-000000_lev2_std.fits',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='LYRA')
    # 2 entries from eve, level 0
    assert entries[2] == DatabaseEntry(
        source='SDO',
        provider='LASP',
        physobs='irradiance',
        fileid=("http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook"
                "/L0CS/SpWx/2012/20120101_EVE_L0CS_DIODES_1m.txt"),
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='EVE')
    # 54 entries from EVE
    assert entries[4] == DatabaseEntry(
        source='SDO',
        provider='LASP',
        physobs='irradiance',
        fileid='EVE_L1_esp_2012001_00',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        size=None,
        instrument='EVE',
        wavemin=0.1,
        wavemax=30.4)
    # 2 entries from goes
    assert entries[58] == DatabaseEntry(
        source='GOES',
        provider='NOAA',
        physobs='irradiance',
        fileid='https://satdat.ngdc.noaa.gov/sem/goes/data/science/xrs/goes15/'
        'gxrs-l2-irrad_science/2012/01/sci_gxrs-l2-irrad_g15_d20120101_v0-0-0.nc',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='XRS')
    # 1 entry from noaa-indices
    assert entries[60] == DatabaseEntry(
        source='SIDC',
        provider='SWPC',
        physobs='sunspot number',
        fileid=
        'https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json',
        observation_time_start=None,
        observation_time_end=None,
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='NOAA-Indices')
    # 1 entry from noaa-predict
    assert entries[61] == DatabaseEntry(
        source='ISES',
        provider='SWPC',
        physobs='sunspot number',
        fileid=
        'https://services.swpc.noaa.gov/json/solar-cycle/predicted-solar-cycle.json',
        observation_time_start=None,
        observation_time_end=None,
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='NOAA-Predict')
    # 2 entries from norh
    assert entries[62] == DatabaseEntry(
        source='NAOJ',
        provider='NRO',
        physobs=None,
        fileid=("ftp://solar-pub.nao.ac.jp/"
                "pub/nsro/norh/data/tcx/2012/01/tca120101"),
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=17634850.470588233,
        wavemax=17634850.470588233,
        instrument='NORH')
    # 1 entry from rhessi
    assert entries[64] == DatabaseEntry(
        source="RHESSI",
        provider='NASA',
        physobs='summary_lightcurve',
        fileid=("https://hesperia.gsfc.nasa.gov/"
                "hessidata/metadata/catalog/hsi_obssumm_20120101_032.fits"),
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='RHESSI')
Exemple #13
0
def test_getitem_negative_index(filled_database):
    entry = filled_database[-4]
    assert entry == DatabaseEntry(id=7)
Exemple #14
0
def test_contains_precommit(database):
    entry = DatabaseEntry()
    database.add(entry)
    assert entry not in database
Exemple #15
0
def test_star_entry(database):
    entry = DatabaseEntry()
    assert not entry.starred
    database.star(entry)
    assert entry.starred
Exemple #16
0
def test_star_already_starred_entry(database):
    entry = DatabaseEntry()
    database.star(entry)
    with pytest.raises(EntryAlreadyStarredError):
        database.star(entry)
Exemple #17
0
def test_tag_missing_tags_arg(database):
    with pytest.raises(TypeError):
        database.tag(DatabaseEntry())
Exemple #18
0
def test_tag_existing_tag(database):
    entry1 = DatabaseEntry()
    entry2 = DatabaseEntry()
    database.tag(entry1, 'tag')
    database.tag(entry2, 'tag')
    assert entry1.tags == entry2.tags
Exemple #19
0
def test_get_entry_by_id_accessible(filled_database):
    assert filled_database.get_entry_by_id(1) == DatabaseEntry(id=1)
Exemple #20
0
def test_create_display_table_missing_columns():
    with pytest.raises(TypeError):
        _create_display_table([DatabaseEntry()], [])
Exemple #21
0
def test_entry_from_query_results_with_none_wave_and_default_unit(
        qr_with_none_waves):
    entries = list(entries_from_query_result(qr_with_none_waves, 'nm'))
    expected = [
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/level1/1212/HK/121222_1.H01',
            observation_time_start=datetime(2012, 12, 23, 23, 59, 3),
            observation_time_end=datetime(2012, 12, 24, 23, 59, 2),
            instrument='VIRGO',
            size=155.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/level1/1212/LOI/121224_1.L01',
            observation_time_end=datetime(2012, 12, 24, 23, 59, 2),
            observation_time_start=datetime(2012, 12, 23, 23, 59, 3),
            instrument='VIRGO',
            size=329.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/level1/1212/SPM/121222_1.S02',
            observation_time_start=datetime(2012, 12, 23, 23, 59, 3),
            observation_time_end=datetime(2012, 12, 24, 23, 59, 2),
            instrument='VIRGO',
            size=87.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/level1/1212/DIARAD/121222_1.D01',
            observation_time_start=datetime(2012, 12, 24, 0, 1, 58),
            observation_time_end=datetime(2012, 12, 25, 0, 1, 57),
            instrument='VIRGO',
            size=14.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/sph/VIRGO_D4.2_SPH_960411_120914.tar.gz',
            observation_time_start=datetime(1996, 4, 11, 0, 0),
            observation_time_end=datetime(2012, 9, 14, 0, 0),
            instrument='VIRGO',
            size=512000.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/tsi_full/VIRGO_TSI_hourly.dat.tar.gz',
            observation_time_start=datetime(1995, 12, 2, 0, 0),
            observation_time_end=datetime(2020, 1, 1, 0, 0),
            instrument='VIRGO',
            size=3072.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/tsi_full/VIRGO_TSI_daily.dat.tar.gz',
            observation_time_start=datetime(1995, 12, 2, 0, 0),
            observation_time_end=datetime(2020, 1, 1, 0, 0),
            instrument='VIRGO',
            size=140.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/spm/VIRGO-SPM-BLUE-L2-MISSIONLONG.fits',
            observation_time_start=datetime(1996, 1, 23, 0, 0),
            observation_time_end=datetime(2021, 5, 15, 23, 59),
            instrument='VIRGO',
            size=32652.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/spm/VIRGO-SPM-GREEN-L2-MISSIONLONG.fits',
            observation_time_start=datetime(1996, 1, 23, 0, 0),
            observation_time_end=datetime(2021, 5, 15, 23, 59),
            instrument='VIRGO',
            size=32652.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/spm/VIRGO-SPM-RED-L2-MISSIONLONG.fits',
            observation_time_start=datetime(1996, 1, 23, 0, 0),
            observation_time_end=datetime(2021, 5, 15, 23, 59),
            instrument='VIRGO',
            size=32652.0,
            wavemin=None,
            wavemax=None),
        DatabaseEntry(
            source='SOHO',
            provider='SDAC',
            physobs='intensity',
            fileid=
            '/archive/soho/private/data/processed/virgo/loi/VIRGO-LOI-ALL-PIXELS-LEVEL2-19960401-20210430_V01.fits',
            observation_time_start=datetime(1996, 4, 1, 0, 0),
            observation_time_end=datetime(2021, 4, 30, 23, 59),
            instrument='VIRGO',
            size=1677722.0,
            wavemin=None,
            wavemax=None),
    ]

    assert len(entries) == len(expected)
    for e in entries:
        assert e in expected
Exemple #22
0
def test_getitem_one(filled_database):
    first_entry = DatabaseEntry(id=1)
    assert filled_database[0] == first_entry
Exemple #23
0
def test_unstar_already_unstarred_entry(database):
    with pytest.raises(EntryAlreadyUnstarredError):
        database.unstar(DatabaseEntry())
Exemple #24
0
def test_getitem_custom(filled_database):
    entries = filled_database[1:5:2]
    foo = Tag('foo')
    foo.id = 1
    assert entries == [
        DatabaseEntry(id=2), DatabaseEntry(id=4, tags=[foo])]
Exemple #25
0
def test_edit_entry_invalid(session):
    with pytest.raises(ValueError):
        EditEntry(DatabaseEntry())
Exemple #26
0
def test_contains_exists(database):
    entry = DatabaseEntry()
    database.add(entry)
    database.commit()
    assert entry in database
Exemple #27
0
def test_edit_entry_repr():
    entry = DatabaseEntry(id=7)
    expected_repr_result = "<EditEntry(kwargs {'foo': 'bar'}, entry id 7)>"
    assert fnmatch.fnmatch(repr(EditEntry(entry, foo='bar')), expected_repr_result)
Exemple #28
0
def test_contains_notexists(database):
    assert DatabaseEntry() not in database
Exemple #29
0
def test_cmd_manager_pop_redo_cmd_empty_stack(session, command_manager):
    cmd = AddEntry(session, DatabaseEntry())
    command_manager.do(cmd)
    command_manager.undo()
    popped_cmd = command_manager.pop_redo_command()
    assert popped_cmd == cmd
Exemple #30
0
def test_remove_nonexisting_tag(session):
    cmd = RemoveTag(session, DatabaseEntry(), Tag('tag'))
    with pytest.raises(NonRemovableTagError):
        cmd()
Exemple #31
0
def test_entries_from_fido_search_result(fido_search_result):
    entries = list(entries_from_fido_search_result(fido_search_result))
    # 66 entries for 8 instruments in fido_search_result
    assert len(entries) == 66
    # First 2 entries are from lyra
    assert entries[0] == DatabaseEntry(
        source='Proba2',
        provider='esa',
        physobs='irradiance',
        fileid=
        'http://proba2.oma.be/lyra/data/bsd/2012/01/01/lyra_20120101-000000_lev2_std.fits',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='lyra')
    # 54 entries from EVE
    assert entries[2] == DatabaseEntry(
        source='SDO',
        provider='LASP',
        physobs='irradiance',
        fileid='EVE_L1_esp_2012001_00',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        size=-1.0,
        instrument='EVE',
        wavemin=0.1,
        wavemax=30.4)
    # 2 entries from goes
    assert entries[56] == DatabaseEntry(
        source='nasa',
        provider='sdac',
        physobs='irradiance',
        fileid='https://umbra.nascom.nasa.gov/goes/fits/2012/go1520120101.fits',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='goes')
    # 1 entry from noaa-indices
    assert entries[58] == DatabaseEntry(
        source='sdic',
        provider='swpc',
        physobs='sunspot number',
        fileid='ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='noaa-indices')
    # 1 entry from noaa-predict
    assert entries[59] == DatabaseEntry(
        source='ises',
        provider='swpc',
        physobs='sunspot number',
        fileid=
        'http://services.swpc.noaa.gov/text/predicted-sunspot-radio-flux.txt',
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='noaa-predict')
    # 2 entries from norh
    assert entries[60] == DatabaseEntry(
        source='NAOJ',
        provider='NRO',
        physobs="",
        fileid=("ftp://*****:*****@[email protected]/"
                "pub/nsro/norh/data/tcx/2012/01/tca120101"),
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        wavemin=17634850.470588233,
        wavemax=17634850.470588233,
        instrument='NORH')
    # 1 entry from rhessi
    assert entries[62] == DatabaseEntry(
        source="rhessi",
        provider='nasa',
        physobs='irradiance',
        fileid=("https://hesperia.gsfc.nasa.gov/"
                "hessidata/metadata/catalog/hsi_obssumm_20120101_016.fits"),
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 1, 23, 59, 59, 999000),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='rhessi')
    # 2 entries from eve, level 0
    assert entries[64] == DatabaseEntry(
        source='SDO',
        provider='LASP',
        physobs='irradiance',
        fileid=("http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook"
                "/L0CS/SpWx/2012/20120101_EVE_L0CS_DIODES_1m.txt"),
        observation_time_start=datetime(2012, 1, 1, 0, 0),
        observation_time_end=datetime(2012, 1, 2, 0, 0),
        wavemin=np.nan,
        wavemax=np.nan,
        instrument='eve')
Exemple #32
0
def test_remove_nonexisting_entry(session):
    with pytest.raises(NoSuchEntryError):
        RemoveEntry(session, DatabaseEntry())()
Exemple #33
0
def test_add_entry(database):
    entry = DatabaseEntry()
    assert entry.id is None
    database.add(entry)
    database.commit()
    assert entry.id == 1
Exemple #34
0
def test_unstar_already_unstarred_entry_ignore(database):
    entry = DatabaseEntry()
    database.unstar(entry, True)
    assert not entry.starred
Exemple #35
0
def test_cmd_manager_pop_undo_cmd(session, command_manager):
    cmd = AddEntry(session, DatabaseEntry())
    command_manager.do(cmd)
    popped_cmd = command_manager.pop_undo_command()
    assert popped_cmd == cmd
Exemple #36
0
def test_add_many_with_existing_entry(database):
    evil_entry = DatabaseEntry()
    database.add(evil_entry)
    assert len(database) == 1
    with pytest.raises(EntryAlreadyAddedError):
        database.add_many([evil_entry])
Exemple #37
0
def test_display_entries_missing_columns():
    with pytest.raises(TypeError):
        display_entries([DatabaseEntry()], [])