Initial port to python3
[htsworkflow.git] / htsworkflow / frontend / experiments / test_experiments.py
index 5878d726d7ee1d268382230a56a235aef7ca29e6..cd212332c1f06b3e0846a88406f8ae5c23ffb8f4 100644 (file)
@@ -2,13 +2,13 @@ import re
 from lxml.html import fromstring
 try:
     import json
-except ImportError, e:
+except ImportError as e:
     import simplejson as json
 import os
 import shutil
 import sys
 import tempfile
-from urlparse import urljoin
+from urllib.parse import urljoin
 
 from django.conf import settings
 from django.core import mail
@@ -24,7 +24,7 @@ from htsworkflow.util.ethelp import validate_xhtml
 
 from htsworkflow.pipelines.test.simulate_runfolder import TESTDATA_DIR
 
-LANE_SET = range(1,9)
+LANE_SET = list(range(1,9))
 
 NSMAP = {'libns':'http://jumpgate.caltech.edu/wiki/LibraryOntology#'}
 
@@ -177,7 +177,7 @@ class ExperimentsTestCases(TestCase):
         """
         Check the code that packs the django objects into simple types.
         """
-        for fc_id in [u'FC12150', u"42JTNAAXX", "42JU1AAXX"]:
+        for fc_id in ['FC12150', "42JTNAAXX", "42JU1AAXX"]:
             fc_dict = experiments.flowcell_information(fc_id)
             fc_django = models.FlowCell.objects.get(flowcell_id=fc_id)
             self.assertEqual(fc_dict['flowcell_id'], fc_id)
@@ -211,7 +211,7 @@ class ExperimentsTestCases(TestCase):
 
 
             for lane in fc_django.lane_set.all():
-                lane_contents = fc_json['lane_set'][unicode(lane.lane_number)]
+                lane_contents = fc_json['lane_set'][str(lane.lane_number)]
                 lane_dict = multi_lane_to_dict(lane_contents)[lane.library_id]
 
                 self.assertEqual(lane_dict['cluster_estimate'], lane.cluster_estimate)
@@ -235,7 +235,7 @@ class ExperimentsTestCases(TestCase):
         """
         Require logging in to retrieve meta data
         """
-        response = self.client.get(u'/experiments/config/FC12150/json')
+        response = self.client.get('/experiments/config/FC12150/json')
         self.assertEqual(response.status_code, 403)
 
     def test_library_id(self):
@@ -268,8 +268,8 @@ class ExperimentsTestCases(TestCase):
         This tests to make sure that the value entered in the raw library id field matches
         the library id looked up.
         """
-        expected_ids = [u'10981',u'11016',u'SL039',u'11060',
-                        u'11061',u'11062',u'11063',u'11064']
+        expected_ids = ['10981','11016','SL039','11060',
+                        '11061','11062','11063','11064']
         self.client.login(username='supertest', password='BJOKL5kAj6aFZ6A5')
         response = self.client.get('/admin/experiments/flowcell/153/')
 
@@ -322,11 +322,11 @@ class ExperimentsTestCases(TestCase):
         lane_dict = multi_lane_to_dict(lane_contents)
 
         self.assertEqual(lane_dict['12044']['index_sequence'],
-                         {u'1': u'ATCACG',
-                          u'2': u'CGATGT',
-                          u'3': u'TTAGGC'})
+                         {'1': 'ATCACG',
+                          '2': 'CGATGT',
+                          '3': 'TTAGGC'})
         self.assertEqual(lane_dict['11045']['index_sequence'],
-                         {u'1': u'ATCACG'})
+                         {'1': 'ATCACG'})
 
 
 
@@ -482,7 +482,7 @@ class ExperimentsTestCases(TestCase):
         count = 0
         for r in query.execute(model):
             count += 1
-            self.assertEqual(fromTypedNode(r['flowcell_id']), u'42JU1AAXX')
+            self.assertEqual(fromTypedNode(r['flowcell_id']), '42JU1AAXX')
             lane_id = fromTypedNode(r['lane_id'])
             library_id = fromTypedNode(r['library_id'])
             self.assertTrue(library_id in expected[lane_id])
@@ -494,8 +494,8 @@ class TestFileType(TestCase):
         file_type_objects = models.FileType.objects
         name = 'QSEQ tarfile'
         file_type_object = file_type_objects.get(name=name)
-        self.assertEqual(u"QSEQ tarfile",
-                             unicode(file_type_object))
+        self.assertEqual("QSEQ tarfile",
+                             str(file_type_object))
 
     def test_find_file_type(self):
         file_type_objects = models.FileType.objects
@@ -607,7 +607,7 @@ class TestSequencer(TestCase):
         seq.instrument_name = "HWI-SEQ1"
         seq.model = "Imaginary 5000"
 
-        self.assertEqual(unicode(seq), "Seq1 (HWI-SEQ1)")
+        self.assertEqual(str(seq), "Seq1 (HWI-SEQ1)")
 
     def test_lookup(self):
         fc = models.FlowCell.objects.get(pk=153)
@@ -698,7 +698,7 @@ def tearDownModule():
     teardown_test_environment()
 
 def suite():
-    from unittest2 import TestSuite, defaultTestLoader
+    from unittest import TestSuite, defaultTestLoader
     suite = TestSuite()
     for testcase in [ClusterStationTestCases,
                      SequencerTestCases,
@@ -710,5 +710,5 @@ def suite():
     return suite
 
 if __name__ == "__main__":
-    from unittest2 import main
+    from unittest import main
     main(defaultTest="suite")