Commits

Aleš Erjavec committed 80b9e52

Fixed and added some tests for obiKEGG2

Comments (0)

Files changed (1)

tests/test_kegg.py

 
 #class TestServices(unittest.TestCase):
 #    def test_services(self):
-#        service = kegg.web_service()
+#        service = kegg.service.web_service()
 #        service.binfo("gb")
 #        service.bfind("gb E-cadherin human")
 #        service.bget("eco:b0002 hin:tRNA-Cys-1")
         
-        
 class TestGenome(unittest.TestCase):
     def test_genome(self):
         genome = kegg.KEGGGenome()
 class TestGenes(unittest.TestCase):
     def _tester(self, org):
         genes = kegg.KEGGGenes(org)
-        keys = genes.keys()
-        for gene in keys[:10]:
+        keys = genes.keys()[:10]
+        all_entries = []
+        for gene in keys:
             self.assertTrue(gene in genes)
             self.assertTrue(genes.has_key(gene))
             entry = genes[gene]
+            self.assertEqual(entry.entry_key,
+                             genes.get(gene).entry_key,
+                             "__getitem__ and get return different result")
             self.assertTrue(gene.endswith(entry.entry_key))
             self.assertIsInstance(entry, genes.ENTRY_TYPE)
             self.assertIsInstance(entry.aliases(), list)
             self.assertTrue(all(isinstance(a, basestring) for a in entry.aliases()))
+            all_entries.append(entry)
+            
+        self.assertSequenceEqual([(e.name, e.entry_key) for e in all_entries],
+                                 [(e.name, e.entry_key) for e in genes.batch_get(keys)],
+                                 "batch_get returns different result")
             
     def test_hsa(self):
         self._tester("hsa")
         
     def test_sce(self):
-        self._tester("sce") 
+        self._tester("sce")
         
+    def test_ddi(self):
+        self._tester("ddi")
     
 class TestPathways(unittest.TestCase):
     def _tester(self, id):
         pathway = pathways[id]
         self.assertTrue(id.endswith(pathway.entry_key))
         self.assertIsInstance(pathway, pathways.ENTRY_TYPE)
+        genes = pathway.gene or []
         
         path = kegg.KEGGPathway(id)
+        self.assertEqual(sorted(genes), sorted(path.genes()))
+        
         
     def test_1(self):
         self._tester("ec00190")
     def test_2(self):
         self._tester("hsa00190")
         
+    def test_3(self):
+        self._tester("sce00190")
+        
         
 class TestOrganism(unittest.TestCase):
     def _tester(self, org):
     def test_sce(self):
         self._tester("sce")
         
+        
+class TestUtils(unittest.TestCase):
+    def test_batch_iter(self):
+        iter = range(25)
+        expected = [range(10),
+                     range(10, 20),
+                     range(20, 25)]
+        for exp, batch in zip(expected, 
+                              kegg.databases.batch_iter(iter, 10)
+                              ):
+            self.assertEqual(exp, batch)
+    
+    
 class TestOld(unittest.TestCase):
     def test(self):
         p = kegg.KEGGPathway("sce00010")