def test_molge(self): # We want to have the default RDkit functionality for testing PandasTools.UninstallPandasTools() molge = PandasTools._molge mol1 = Chem.MolFromSmiles('CCC') mol2 = Chem.MolFromSmiles('CC') mol3 = Chem.MolFromSmiles('CN') self.assertFalse(molge(mol1, None)) self.assertFalse(molge(None, mol1)) self.assertFalse(hasattr(mol1, '_substructfp')) self.assertFalse(hasattr(mol2, '_substructfp')) self.assertFalse(hasattr(mol1, '__sssAtoms')) self.assertFalse(hasattr(mol2, '__sssAtoms')) self.assertTrue(molge(mol1, mol2)) self.assertEqual(mol1.__dict__['__sssAtoms'], [0, 1]) PandasTools.highlightSubstructures = False self.assertTrue(molge(mol1, mol2)) self.assertEqual(mol1.__dict__['__sssAtoms'], []) PandasTools.highlightSubstructures = True self.assertFalse(molge(mol2, mol1)) self.assertEqual(mol2.__dict__['__sssAtoms'], []) self.assertFalse(molge(mol1, mol3)) self.assertEqual(mol1.__dict__['__sssAtoms'], [])
def test_RestoreMonkeyPatch(self): sio = getStreamIO(methane + peroxide) df = PandasTools.LoadSDF(sio) html = df.to_html() self.assertIn('data:image/png;base64', html) self.assertIn('table', html) PandasTools.UninstallPandasTools() html = df.to_html() self.assertNotIn('data:image/png;base64', html) self.assertIn('rdkit.Chem.rdchem.Mol', html) self.assertIn('table', html) PandasTools.InstallPandasTools() html = df.to_html() self.assertIn('data:image/png;base64', html) self.assertIn('table', html) PandasTools.UninstallPandasTools() html = df.to_html() self.assertNotIn('data:image/png;base64', html) self.assertIn('rdkit.Chem.rdchem.Mol', html) self.assertIn('table', html)
def tearDown(self): PandasTools.molRepresentation = self._molRepresentation PandasTools.highlightSubstructures = self._highlightSubstructures PandasTools.UninstallPandasTools()
import unittest import tempfile import shutil import os import gzip import doctest if (getattr(doctest, 'ELLIPSIS_MARKER')): doctest.ELLIPSIS_MARKER = '*...*' try: import IPython except ImportError: IPython = None # We make sure that we don't mess up the Mol methods for the rest of the tests PandasTools.UninstallPandasTools() @unittest.skipIf(PandasTools.pd is None, 'Pandas not installed, skipping') class TestPandasTools(unittest.TestCase): def __init__(self, methodName='runTest'): self.df = getTestFrame() self.df.index.name = 'IndexName' super(TestPandasTools, self).__init__(methodName=methodName) def setUp(self): PandasTools.InstallPandasTools() PandasTools.ChangeMoleculeRendering(renderer='PNG') PandasTools.pd.set_option('display.max_columns', None) self._molRepresentation = PandasTools.molRepresentation self._highlightSubstructures = PandasTools.highlightSubstructures