From c6d1c13fb06334d3bded5aeba32b77d7d649019f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr>
Date: Tue, 14 Apr 2020 13:43:26 +0200
Subject: [PATCH] add unit test for smi2sdf utils function

---
 ippisite/ippidb/tests.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/ippisite/ippidb/tests.py b/ippisite/ippidb/tests.py
index 49a36599..cd0914b0 100644
--- a/ippisite/ippidb/tests.py
+++ b/ippisite/ippidb/tests.py
@@ -26,7 +26,7 @@ from .models import (
     PcaBiplotData,
 )
 from .models import DrugBankCompound, Protein
-from .utils import FingerPrinter, mol2smi, smi2mol, smi2inchi, smi2inchikey
+from .utils import FingerPrinter, mol2smi, smi2mol, smi2inchi, smi2inchikey, smi2sdf
 
 
 class MolSmiTestCase(TestCase):
@@ -918,6 +918,30 @@ class TestConvertSMILESToIUPAC(TestCase):
             )
 
 
+class TestConvertSMILESToSDF(TestCase):
+    """
+    Test converting a smiles to SDF using openbabel
+    """
+
+    def test_valid(self):
+        smiles_to_sdfs = {
+            "C": [
+                "1",
+                " OpenBabel04142011372D",
+                "",
+                "  1  0  0  0  0  0  0  0  0  0999 V2000",
+                "    0.0000    0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0",
+                "M  END",
+                "$$$$",
+            ]
+        }
+        for smiles, expected_lines in smiles_to_sdfs.items():
+            result = smi2sdf({1: smiles})
+            result_lines = result.split("\n")
+            for line_idx in [0, 2, 3, 4, 5, 6]:
+                self.assertEqual(result_lines[line_idx], expected_lines[line_idx])
+
+
 class DuplicateGeneNameTestCase(TestCase):
     def test_works(self):
         models.Protein.objects.get_or_create(uniprot_id="P12497")
-- 
GitLab