def test_search_metadata_finds_recursively(): d = Datasource() d._metadata = { "car": "toyota", "inlets": { "inlet_a": "45m", "inlet_b": "3580m" } } result = d.search_metadata(search_terms=["45m", "3580m", "toyota"], find_all=True) assert result is True result = d.search_metadata( search_terms=["100m", "violin", "toyota", "swallow"], find_all=True) assert result is False result = d.search_metadata( search_terms=["100m", "violin", "toyota", "swallow"], find_all=False) assert result is True
def test_search_metadata(): d = Datasource() d._metadata = {"unladen": "swallow", "spam": "eggs"} assert d.search_metadata(unladen="swallow") == True assert d.search_metadata(spam="eggs") == True assert d.search_metadata(unladen="Swallow") == True assert d.search_metadata(giraffe="beans") == False assert d.search_metadata(bird="flamingo") == False
def test_search_metadata_find_all(): d = Datasource() d._metadata = {"inlet": "100m", "instrument": "violin", "car": "toyota"} result = d.search_metadata(inlet="100m", instrument="violin", car="toyota", find_all=True) assert result is True result = d.search_metadata(inlet="100m", instrument="violin", car="subaru", find_all=True) assert result is False
def test_dated_metadata_search(): d = Datasource() start = pd.Timestamp("2001-01-01-00:00:00", tz="UTC") end = pd.Timestamp("2001-03-01-00:00:00", tz="UTC") d._start_date = start d._end_date = end d._metadata = {"inlet": "100m", "instrument": "violin", "site": "timbuktu"} assert d.search_metadata(inlet="100m", instrument="violin") == True assert (d.search_metadata( search_terms=["100m", "violin"], start_date=pd.Timestamp("2015-01-01"), end_date=pd.Timestamp("2021-01-01"), ) == False) assert (d.search_metadata( inlet="100m", instrument="violin", start_date=pd.Timestamp("2001-01-01"), end_date=pd.Timestamp("2002-01-01"), ) == True)