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(dirs.log_dir, 'test.ini', '', '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(dirs.log_dir, 'test.ini', '', '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(dirs.test_dir, 'test.ini', '', '', 'week', 'yes')
        test.get_time_difference(d1, d2)


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

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