import pytest
import importlib
code = importlib.import_module('data_handler')
from data_handler import START_DATE
from data_handler import END_DATE
from data_handler import OBS

@pytest.fixture
def aeronet_instance():
    return code.Observations1dHandler('20220404','20220405' , 'aeronet') 

def test_generate_obs1d_tstep_trace1(aeronet_instance):
    run = aeronet_instance.generate_obs1d_tstep_trace('OD550_DUST')
    assert str(type(run[1])) == "<class 'dash_leaflet.GeoJSON.GeoJSON'>"
    assert run[0].shape ==(120, 3)

# @pytest.fixture 
# def obsTSHandler_instance():
#     return code.ObsTimeSeriesHandler('aeronet','20220404','20220405', 'OD550_DUST', ['median', 'monarch']) 
#
# def test_retrieve_timeseries():
#     assert obsTSHandler_instance.retrieve_timeseries(idx, st_name, model) == 'hello'

    
@pytest.fixture
def TSHandler():
    return code.TimeSeriesHandler('median', '20220606', 'OD550_DUST')

def test_TimeSeriesHandler(TSHandler):
    run = TSHandler.retrieve_single_point(1, 45, 45, model='median')
    assert float(run) == 0.10633552074432373

def test_TimeSeriesHandler_1(TSHandler):
    run = TSHandler.retrieve_single_point(3, 5, 5, model=None)
    assert float(run) == 0.00830854382365942

def test_retrieve_timeseries(TSHandler):
    run = TSHandler.retrieve_timeseries(5, 5, model=None, method='netcdf', forecast=False)
    assert run.layout.title.text =='Dust Optical Depth @ lat = 5 and lon = 5'

def test_retrieve_timeseries_1(TSHandler):
    run = TSHandler.retrieve_timeseries(35, 15, model='monarch', method='netcdf', forecast=True)
    assert run.layout.title.text =='Dust Optical Depth @ lat = 35 and lon = 15'

def test_retrieve_timeseries_2(TSHandler):
    run = TSHandler.retrieve_timeseries(35, 15, model='monarch', method='netcdf', forecast=True)
    assert run.data[0].name == 'MULTI-MODEL (35.25, 15.25)'


