diff --git a/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq.py b/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq.py
index 630c5641afceb2b894324895fb1eca468ef257cb..d59d8787e434324f3867da99b60875588c8a28e3 100644
--- a/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq.py
+++ b/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq.py
@@ -44,15 +44,14 @@ Operator Name or ID of the operator
 SampleProject  The project the sample belongs to
 '''
 
-from __future__ import with_statement
 import os
 import logging
 import re
 import sys
 import string
 import smtplib
+import argparse
 from ConfigParser import SafeConfigParser
-from optparse import OptionParser
 from datetime import *
 from collections import OrderedDict
 
@@ -104,55 +103,55 @@ def setUpLogger(logPath, logLevel=logging.INFO):
 
 def parseOptions(logger):
     logger.info('Parsing command line parameters')
-    parser = OptionParser(version='%prog 1.0')
-    parser.add_option('-f', '--flowcell',
+    parser = argparse.ArgumentParser(version='%prog 1.0', description='Process some integers.')
+    parser.add_argument('-f', '--flowcell',
                   dest='flowcell',
                   help='The flowcell which is used to create the SampleSheet.csv',
                   metavar='<flowcell>')
-    parser.add_option('-m', '--mailist',
+    parser.add_argument('-m', '--mailist',
                   dest='maillist',
                   default=False,
                   action='store_true',
-                  help='Generated Sample Sheet will be addtionally sent as email to the defined list of recipients',
-                  metavar='<maillist>')
-    parser.add_option('-l', '--lineending',
+                  help='Generated Sample Sheet will be addtionally sent as email to the defined list of recipients')
+    parser.add_argument('-l', '--lineending',
                   dest='lineending',
-                  type='choice',
                   action='store',
                   choices=['win32', 'linux', 'mac'],
                   default='win32',
                   help='Specify end of line separator: win32, linux, mac. Default: win32' ,
                   metavar='<lineending>')
-    parser.add_option('-o', '--outdir',
+    parser.add_argument('-o', '--outdir',
                   dest='outdir',
                   default='./',
                   help='Specify the ouput directory. Default: ./' ,
                   metavar='<outdir>')
-    parser.add_option('-s', '--singlelane',
+    parser.add_argument('-s', '--singlelane',
                   dest='singlelane',
                   default=False,
                   action='store_true',
                   help='Creates a single Sample Sheet for each lane. Default: False')
-    parser.add_option('-d', '--debug',
+    parser.add_argument('-d', '--debug',
                   dest='debug',
                   default=False,
                   action='store_true',
                   help='Verbose debug logging. Default: False')
-    parser.add_option('-v', '--verbose',
+    parser.add_argument('--verbose',
                   dest='verbose',
                   default=False,
                   action='store_true',
                   help='Write Sample Sheet to stout. Default: False')
 
-    (options, args) = parser.parse_args()
+    args = parser.parse_args()
+    
+    print(type(args))
 
-    if options.outdir[-1] <> '/':
-        options.outdir = options.outdir + '/'
+    if args.outdir[-1] <> '/':
+        args.outdir = args.outdir + '/'
 
-    if options.flowcell is None:
+    if args.flowcell is None:
         parser.print_help()
         exit(-1)
-    return options
+    return args
 
 
 def parseConfigurationFile(propertyFile='etc/createSampleSheet.properties'):
@@ -684,10 +683,10 @@ def main ():
         logger.setLevel(logging.DEBUG)
 
     flowCellName = myoptions.flowcell
-    configMap = readConfig(logger)
-    service = login(logger, configMap)
+    config_dict = readConfig(logger)
+    service = login(logger, config_dict)
 
-    foundFlowCell, containedSamples = get_flowcell(configMap['illuminaFlowCellTypeName'], flowCellName,
+    foundFlowCell, containedSamples = get_flowcell(config_dict['illuminaFlowCellTypeName'], flowCellName,
                                                 service, logger)
     parentDict, samplesPerLaneDict = get_contained_sample_properties(containedSamples, service)
     logger.info('Found ' + str(len(parentDict)) + ' samples on the flow cell ' + flowCellName)
@@ -698,20 +697,20 @@ def main ():
     print("Auto-detected: " + model)
     logger.info("Auto-detected: " + model)
 
-    index1Vocabulary = get_vocabulary(configMap['index1Name'], service)
-    index2Vocabulary = get_vocabulary(configMap['index2Name'], service)
+    index1Vocabulary = get_vocabulary(config_dict['index1Name'], service)
+    index2Vocabulary = get_vocabulary(config_dict['index2Name'], service)
     ordered_sample_sheet_dict, csv_file_name = create_sample_sheet_dict(model, parentDict,
-                            flowCellDict, configMap, index1Vocabulary, index2Vocabulary, flowCellName, logger)
+                            flowCellDict, config_dict, index1Vocabulary, index2Vocabulary, flowCellName, logger)
     
     if myoptions.singlelane:
         write_sample_sheet_single_lane(ordered_sample_sheet_dict, flowCellDict,
-                                          parentDict, configMap, myoptions, logger, csv_file_name)
+                                          parentDict, config_dict, myoptions, logger, csv_file_name)
     else:
-        header_list = create_header_section (configMap, parentDict, flowCellDict)
+        header_list = create_header_section (config_dict, parentDict, flowCellDict)
         sampleSheetFile = write_sample_sheet(ordered_sample_sheet_dict, header_list, 
                                           myoptions, logger, myoptions.outdir + csv_file_name + CSV)
         if myoptions.maillist:
-            sendMail(configMap['mailList'], [SampleSheetFile], flowCellName, configMap, logger)
+            sendMail(config_dict['mailList'], [sampleSheetFile], flowCellName, config_dict, logger)
 
     logout(service, logger)
 
diff --git a/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq_Test.py b/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq_Test.py
index a5b84e58005a41918cd64ae3b5e6adcd07e0b8ac..62c968ea749460b969e7487f9915180046fa364e 100644
--- a/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq_Test.py
+++ b/deep_sequencing_unit/source/Jython/createSampleSheet_bcl2fastq_Test.py
@@ -30,62 +30,95 @@ class test_get_reverse_complement(unittest.TestCase):
         self.assertNotEqual(get_reverse_complement('ACTG'), 'CAGA')
 
 
-class test_get_flowCell(unittest.TestCase):
+class create_sample_sheet(unittest.TestCase):
   
     def setUp(self):
         self.myCode = 'C7GMNANXX'
         self.logger = setUpLogger('log/')
-        configDict = readConfig(self.logger)
-        self.service = OpenbisServiceFacadeFactory.tryCreate(configDict['openbisUserName'],
-                                                      configDict['openbisPassword'],
-                                                      configDict['openbisServer'],
-                                                      configDict['connectionTimeout'])
+        self.config_dict = readConfig(self.logger)
+        
+#         self.options = parseOptions(self.logger)
+        
+        import argparse
+        import shlex
+        parser = argparse.ArgumentParser()
+        
+        parser.add_argument('--flowcell')
+        parser.add_argument('--lineending')
+        parser.add_argument('--outdir')
+        
+        cmd_string = ['--flowcell', self.myCode, '--lineending', 'win32', '--outdir', '../../targets/playground']
+        self.options = parser.parse_args(cmd_string)
+
+        self.service = OpenbisServiceFacadeFactory.tryCreate(self.config_dict['openbisUserName'],
+                                                      self.config_dict['openbisPassword'],
+                                                      self.config_dict['openbisServer'],
+                                                      self.config_dict['connectionTimeout'])
         
         self.flowcell, self.containedSamples = get_flowcell('ILLUMINA_FLOW_CELL',
                                             self.myCode, self.service, self.logger)
+        self.flowCellDict = transform_sample_to_dict(self.flowcell)
+        self.parentDict, self.samplesPerLaneDict = get_contained_sample_properties(
+                                                    self.containedSamples, self.service)
+        self.flowCellName = self.flowcell.getCode()
+        self.index1Vocabulary = get_vocabulary(self.config_dict['index1Name'], self.service)
+        self.index2Vocabulary = get_vocabulary(self.config_dict['index2Name'], self.service)
 
 
-    def test_get_flowCell (self):
 
+    def test_get_flowCell (self):
         self.assertEqual(self.flowcell.getCode(), self.myCode)
         self.assertEqual(self.containedSamples.size(), 8)
         
         fcProp = self.flowcell.getProperties()
         self.assertEqual(fcProp['SEQUENCER'], 'D00535')
-        self.flowCellDict = transform_sample_to_dict(self.flowcell)
         self.assertEqual(self.flowCellDict['FLOWCELLTYPE'], 'HiSeq Flow Cell v4')
-
+    
     
     def test_get_contained_sample_properties(self):
-        self.parentDict, self.samplesPerLaneDict = get_contained_sample_properties(
-                                                    self.containedSamples, self.service)
         self.assertEqual(self.parentDict['BSSE_QGF_34778_C7GMNANXX_1']['BARCODE'], 'GTCCGC')
         self.assertEqual(self.parentDict['BSSE_QGF_32285_C7GMNANXX_7']['CONTACT_PERSON_EMAIL'], 'yann.bourgeois@unibas.ch')
         self.assertEqual(self.samplesPerLaneDict['2'], 23)
 
-    
-    def tearDown(self):
-        self.service.logout()
-        self.logger.info('Logged out') 
-
-
-# class test_get_contained_sample_properties(unittest.TestCase):
-#     def setUp(self):
-#         self.flowcell = test_get_flowCell.setUp(self)
-#         
-
 
+    def test_get_vocabulary(self):        
+        self.assertEqual(self.index1Vocabulary['CACTCAA'], 'Illumina A032 CACTCAA')
+        self.assertEqual(self.index2Vocabulary['GTAAGGAG'],'Index2 (i5) 505 GTAAGGAG')
+    
+    
+    def test_verify_index_length(self):
+        self.index_length_dict = verify_index_length(self.parentDict, self.flowCellDict, self.config_dict, self.logger)
+        self.assertDictEqual(self.index_length_dict, {6: [6, 0], 5: [6, 0], 7: [8, 8], 8: [8, 8], 3: [8, 0], 2: [6, 0], 1: [6, 0], 4: [8, 0]})
+        
+        
+    def test_create_sample_sheet_dict(self):
+        
+        self.model = get_model(self.flowCellDict['RUN_NAME_FOLDER'])
 
+        self.ordered_sample_sheet_dict, self.csv_file_name = create_sample_sheet_dict(self.model, self.parentDict,
+                            self.flowCellDict, self.config_dict, self.index1Vocabulary, self.index2Vocabulary, self.flowCellName, self.logger)
+        
+        self.ordered_sample_sheet_dict['5_BSSE_QGF_32303_C7GMNANXX_5'] = \
+        [u'5,BSSE_QGF_32303_C7GMNANXX_5,BSSE_QGF_32303_C7GMNANXX_5_TR_EG_1_GGCTAC,,,SureSelectXT,GGCTAC,BSSE_QGF_32303_C7GMNANXX_5,']
 
+        self.ordered_sample_sheet_dict['5_BSSE_QGF_36788_C7GMNANXX_5'] = \
+        [u'5,BSSE_QGF_36788_C7GMNANXX_5,BSSE_QGF_36788_C7GMNANXX_5_G_33_run2_TAAGGC,,,N701,TAAGGC,BSSE_QGF_36788_C7GMNANXX_5,']
+        
+        self.ordered_sample_sheet_dict['BSSE_QGF_32281_C7GMNANXX_8']= \
+        [u'8,BSSE_QGF_32281_C7GMNANXX_8,BSSE_QGF_32281_C7GMNANXX_8_F2_18_3_P162Nextera_TAGGCATG_CTATTAAG,,,N706,TAGGCATG,518,CTATTAAG,BSSE_QGF_32281_C7GMNANXX_8,']
+        
+    def test_write_sample_sheet_single_lane(self):
+        self.model = get_model(self.flowCellDict['RUN_NAME_FOLDER'])
 
-# class test_verify_index_length(test_get_flowCell):
-#     
-#     def setUp(self):
-#         foundFlowCell, containedSamples = test_get_flowCell()
-#     
-#     
-#     def test_verify_index_length(self):
-#         foundFlowCell
+        self.ordered_sample_sheet_dict, self.csv_file_name = create_sample_sheet_dict(self.model, self.parentDict,
+                            self.flowCellDict, self.config_dict, self.index1Vocabulary, self.index2Vocabulary, self.flowCellName, self.logger)
+        
+        write_sample_sheet_single_lane(self.ordered_sample_sheet_dict, self.flowCellDict,
+                                          self.parentDict, self.config_dict, self.options, self.logger, self.csv_file_name)
+    
+    def tearDown(self):
+        self.service.logout()
+        self.logger.info('Logged out')
 
 def main():
     unittest.main()