"""Tests para parse_cron_expr."""

import pytest
from parse_cron_expr import parse_cron_expr


def test_expande_minutos_a_0_15_30_45():
    """*/15 expande minutos a [0 15 30 45]"""
    sched = parse_cron_expr("*/15 * * * *")
    assert sched["minute"] == [0, 15, 30, 45]
    assert sched["hour"] == list(range(24))


def test_daily_resuelve_a_minuto_0_hora_0():
    """@daily resuelve a minuto 0 hora 0"""
    sched = parse_cron_expr("@daily")
    assert sched["minute"] == [0]
    assert sched["hour"] == [0]
    assert sched["day_of_month"] == list(range(1, 32))


def test_0_9_1_15_expande_dias_a_1_15():
    """0 9 1,15 * * expande dias a [1 15]"""
    sched = parse_cron_expr("0 9 1,15 * *")
    assert sched["minute"] == [0]
    assert sched["hour"] == [9]
    assert sched["day_of_month"] == [1, 15]


def test_0_9_1_5_expande_dia_semana_a_1_2_3_4_5():
    """0 9 * * 1-5 expande dia de semana a [1 2 3 4 5]"""
    sched = parse_cron_expr("0 9 * * 1-5")
    assert sched["day_of_week"] == [1, 2, 3, 4, 5]


def test_expresion_con_4_campos_lanza_valueerror():
    """expresion con 4 campos lanza ValueError"""
    with pytest.raises(ValueError):
        parse_cron_expr("0 9 * *")


def test_minuto_fuera_de_rango_lanza_valueerror():
    """minuto fuera de rango lanza ValueError"""
    with pytest.raises(ValueError):
        parse_cron_expr("60 * * * *")
