Files
macro_split/tests/test_fragment_prep.py
lingyuzeng 5e7b236f31 feat(toolkit): ship macro_lactone_toolkit package
Unify macrolactone detection, numbering, fragmentation, and
splicing under the installable macro_lactone_toolkit package.

- replace legacy src.* modules with the new package layout
- add analyze/number/fragment CLI entrypoints and pixi tasks
- migrate tests, README, and scripts to the new package API
2026-03-18 22:06:45 +08:00

43 lines
1.3 KiB
Python

import pytest
from rdkit import Chem
from macro_lactone_toolkit.splicing.fragment_prep import activate_fragment
def test_activate_smart_ethanol():
mol = activate_fragment("CCO", strategy="smart")
assert mol is not None
assert mol.GetNumAtoms() == 4
dummy_atom = next(atom for atom in mol.GetAtoms() if atom.GetAtomicNum() == 0)
assert dummy_atom.GetNeighbors()[0].GetSymbol() == "O"
assert "*" in Chem.MolToSmiles(mol)
def test_activate_smart_amine():
mol = activate_fragment("CCN", strategy="smart")
dummy_atom = next(atom for atom in mol.GetAtoms() if atom.GetAtomicNum() == 0)
assert dummy_atom.GetNeighbors()[0].GetSymbol() == "N"
def test_activate_random_pentane():
mol = activate_fragment("CCCCC", strategy="random")
assert mol.GetNumAtoms() == 6
dummy_atom = next(atom for atom in mol.GetAtoms() if atom.GetAtomicNum() == 0)
assert dummy_atom.GetNeighbors()[0].GetSymbol() == "C"
def test_activate_smart_fallback():
mol = activate_fragment("CCC", strategy="smart")
dummy_atom = next(atom for atom in mol.GetAtoms() if atom.GetAtomicNum() == 0)
assert dummy_atom.GetNeighbors()[0].GetSymbol() == "C"
assert Chem.SanitizeMol(mol) == Chem.SanitizeFlags.SANITIZE_NONE
def test_invalid_smiles():
with pytest.raises(ValueError):
activate_fragment("NotASmiles", strategy="smart")