"""Tests for polytropos helpers."""

import pytest

from polytropos import ph


class TestRel:
    """Tests for the rel() function."""

    @pytest.mark.parametrize(
        "spec,current,expected",
        [
            (">=17.0", "17.0", True),
            (">=17.0", "16.0", False),
            (">=17.0", "18.0", True),
            (">=18.0", "17.0", False),
            (">=18.0", "18.0", True),
            (">=18.0", "19.0", True),
            ("<18.0", "17.0", True),
            ("<18.0", "18.0", False),
            (">=17.0,<18.0", "17.0", True),
            (">=17.0,<18.0", "17.5", True),
            (">=17.0,<18.0", "18.0", False),
            (">=18.0,<19.0", "18.0", True),
            (">=18.0,<19.0", "18.5", True),
            (">=18.0,<19.0", "19.0", False),
        ],
    )
    def test_release_matching(self, mock_odoo, spec, current, expected):
        """Test that release matching works with various specifiers."""
        mock_odoo.release.series = current
        result = ph.rel(spec)
        assert result is expected


def test_raises_module_not_found_error_without_odoo():
    """Test that _odoo() raises ModuleNotFoundError when Odoo is absent."""
    with pytest.raises(ModuleNotFoundError, match="odoo"):
        ph._odoo()
