import os
import pytest
import modrna_params as mp


def test_frcmod_path_exists():
    p = mp.frcmod_path()
    assert os.path.isfile(p) and p.endswith("frcmod.modxna")


def test_lib_path_forms():
    assert mp.lib_path("5MC").endswith("/lib/5MC.lib")
    assert mp.lib_path("5MC", "5prime").endswith("/lib/5MC5.lib")
    assert mp.lib_path("5MC", "3prime").endswith("/lib/5MC3.lib")
    assert os.path.isfile(mp.lib_path("5MC"))
    with pytest.raises(KeyError):
        mp.lib_path("XXX")


def test_lib_paths_has_all_27():
    paths = mp.lib_paths()
    assert len(paths) == 27
    assert all(os.path.isfile(p) for p in paths.values())


def test_leaprc_lines():
    lines = mp.leaprc_lines()
    assert lines[0].startswith("loadamberparams ")
    assert sum(1 for x in lines if x.startswith("loadoff ")) == 27
    subset = mp.leaprc_lines(residues=["5MC"], termini=["internal"])
    assert subset == [
        f"loadamberparams {mp.frcmod_path()}",
        f"loadoff {mp.lib_path('5MC')}",
    ]
