Skip to content

Commit

Permalink
Adding units tests for NCEDCS3DataStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuan-Fu Feng committed Jan 26, 2024
1 parent 01ba3de commit bf3303d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Binary file added tests/data/s3ncedc/AFD.NC.HHZ..D.2022.002
Binary file not shown.
Binary file added tests/data/s3ncedc/NSP.NC.EHZ..D.2022.002
Binary file not shown.
Binary file added tests/data/s3ncedc/PSN.NC.EHZ..D.2022.002
Binary file not shown.
39 changes: 38 additions & 1 deletion tests/test_scedc_s3store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from test_channelcatalog import MockCatalog

from noisepy.seis.datatypes import Channel, ChannelType, Station
from noisepy.seis.scedc_s3store import SCEDCS3DataStore, channel_filter
from noisepy.seis.scedc_s3store import (
NCEDCS3DataStore,
SCEDCS3DataStore,
channel_filter,
)

timespan1 = DateTimeRange(datetime(2022, 1, 2, tzinfo=timezone.utc), datetime(2022, 1, 3, tzinfo=timezone.utc))
timespan2 = DateTimeRange(datetime(2021, 2, 3, tzinfo=timezone.utc), datetime(2021, 2, 4, tzinfo=timezone.utc))
Expand Down Expand Up @@ -78,3 +82,36 @@ def check(sta, ch_name):
assert check(staX, "CHE") is False # invalid channel name
assert check(staZ, "BHE") is False # invalid station
assert check(staZ, "CHE") is False # invalid station and channel name


files_dates = [
("AFD.NC.HHZ..D.2022.002", timespan1),
("KCPB.NC.HHN..D.2021.034", timespan2),
("LMC.NC.HHN..D.2023.152", timespan3),
]


@pytest.mark.parametrize("file,expected", files_dates)
def test_parsefilename2(file: str, expected: DateTimeRange):
assert expected == NCEDCS3DataStore._parse_timespan(None, file)


data_paths = [
(os.path.join(os.path.dirname(__file__), "./data/s3ncedc"), None),
("s3://ncedc-pds/continuous_waveforms/NC/2022/2022.002/", None),
("s3://ncedc-pds/continuous_waveforms/", timespan1),
]


read_channels = [
(NCEDCS3DataStore._parse_channel(None, "AFD.NC.HHZ..D.2022.002")),
(NCEDCS3DataStore._parse_channel(None, "NSP.NC.EHZ..D.2022.002")),
(NCEDCS3DataStore._parse_channel(None, "PSN.NC.EHZ..D.2022.002")),
]


@pytest.fixture(params=data_paths)
def store2(request):
storage_options = {"s3": {"anon": True}}
(path, timespan) = request.param
return NCEDCS3DataStore(path, MockCatalog(), lambda ch: ch in read_channels, timespan, storage_options)

0 comments on commit bf3303d

Please sign in to comment.