#!/usr/bin/env python3
"""Test MolDesc class with get_all_desc method"""

from qspoc.descriptor import MolDesc
from test_utils import BaseTestCase, MoleculeTestMixin


class TestMolDescAllDescriptors(BaseTestCase, MoleculeTestMixin):
    """Test MolDesc class with get_all_desc method"""

    @classmethod
    def setUpClass(cls):
        super().setUpClass()
        cls.test_molecules = [{"smiles": "[H]C(C)(C)C", "name": "dimethyl_sulfoxide", "sterimol_vec": (0, 1), "expect_error": False}]
        # [{"smiles": "[H]C(C)(C)C", "name": "dimethyl_sulfoxide", "sterimol_vec": (0, 1), "expect_error": False}]

    def test_individual_molecules_get_all_desc(self):
        """Test get_all_desc method for each molecule"""
        self.print_test_header("Test molecules with steric hindrance descriptor.")

        for mol_data in self.test_molecules:
            with self.subTest(molecule=mol_data["name"]):
                result = self._test_single_molecule(mol_data)
                self.display_molecule_result(result)

    def _test_single_molecule(self, mol_data):
        """Test get_all_desc for a single molecule"""
        expect_error = mol_data.get("expect_error", False)

        try:
            mol_desc = MolDesc(SMILES=mol_data["smiles"])
            mol_desc.get_3D_struct()
            mol_desc.get_xtb_opt_struct()
            mol_desc.get_stric_hindrance_desc(mol_data["sterimol_vec"])

            if expect_error:
                self.fail(f"Expected error for {mol_data['name']}, but got success")

            print(mol_desc._mol_props)
            self.validate_mol_desc_results(mol_desc, True)
            return self.get_molecule_result_summary(mol_data, mol_desc, True)

        except Exception as e:
            if expect_error:
                return self.get_molecule_result_summary(mol_data, None, True, "Expected error occurred")

            result = self.get_molecule_result_summary(mol_data, None, False, str(e))
            raise


if __name__ == "__main__":
    import unittest

    unittest.main(verbosity=2)
