from dqc_wrapper.test05_temporal_consistency import TemporalConsistencyTest
from datetime import datetime
import pytest
from dqc_wrapper.unit_tests.conftest import dirs

def test_monthdelta():
    test = TemporalConsistencyTest('', '1', 'a', 'yes')
    d1 = datetime(2019, 11, 15)
    d2 = datetime(2020, 3, 19)
    delta = test.monthdelta(d1, d2)
    assert delta == 4


def test_get_time_difference():
    test = TemporalConsistencyTest('', '3', 'day', 'yes')
    d1 = datetime(2019, 11, 15)
    d2 = datetime(2019, 11, 18)
    response = test.get_time_difference(d1, d2)
    assert response[0]

    d3 = datetime(2024, 12, 12)
    response = test.get_time_difference(d2, d3)
    assert not response[0]

    with pytest.raises(Exception):
        test = TemporalConsistencyTest('', '', 'week', 'yes')
        test.get_time_difference(d1, d2)


def test_check_timestamps():
    test = TemporalConsistencyTest([dirs.nc_file], '1', 'day', 'yes')
    response = test.check_timestamps()
    assert response[0] == 'ok'

    test = TemporalConsistencyTest([dirs.nc_file], '27', 'month', 'yes')
    response = test.check_timestamps()
    assert response[0] == 'err'
