def test_upload_reads(self):
    collection = self.res.collection.create(name='Test upload reads')
    samplesheet = self.get_samplesheet()
    with self.assertLogs() as logs:
        collection.upload_reads(samplesheet, basedir='files')
    self.assertEqual(len(logs.output), 37)
    upload_errprefix = 'ERROR:resdk.data_upload.reads:'
    upload_errs = ["Skipping upload of 'Sample 1': No forward reads given.", 'File /storage/61_cat_R1_001.fastq.gz not found.', 'File /storage/63_cat_R1_001.fastq.gz not found.', "Skipping upload of '01_1-1_IP_plus': Invalid file extension(s). (Options: .fq, .fastq)", "Skipping upload of 'missing barcode': Invalid file extension(s). (Options: .fq, .fastq)", "Skipping upload of 'bad extension': Invalid file extension(s). (Options: .fq, .fastq)"]
    for error in upload_errs:
        message = (upload_errprefix + error)
        self.assertIn(message, logs.output)
    upload_fail = ['Sample 1', 'Sample 2', 'Sample 3', 'bad single path', 'bad paired path', ' ,', 'missing annotator', 'missing organism', 'missing source', 'missing molecule', 'missing seq_type', '01_1-1_IP_plus', '02_1-1_IP_minus', 'missing barcode', 'other barcode', '01_1-1_IP_plus2', '02_1-1_IP_minus2', 'duplicated sample', 'invalid qseq', 'invalid qseq2', 'bad extension']
    for invalid in upload_fail:
        self.assertIn(invalid, logs.output[31])
    for missing in upload_fail:
        self.assertIn(missing, logs.output[32])
    upload_success = ['single-reads', 'paired-reads']
    for uploaded in upload_success:
        self.assertNotIn(uploaded, logs.output[31])
        self.assertNotIn(uploaded, logs.output[32])
    names = [sample.name for sample in collection.samples]
    self.assertIn('single-reads', names)
    self.assertIn('paired-reads', names)
    with self.assertLogs() as logs2:
        collection.upload_reads(samplesheet, basedir='files')
    already_up = ["Skipping upload of 'single-reads': File already uploaded.", "Skipping upload of 'paired-reads': File already uploaded."]
    for error in already_up:
        message = (upload_errprefix + error)
        self.assertIn(message, logs2.output)
    self.assertEqual(len(collection.data), 2)
    self.assertEqual(len(collection.samples), 2)
    filepath = 'annotation_template2.xlsm'
    try:
        os.remove(filepath)
    except OSError:
        pass
    collection.export_annotation(filepath)
    assert os.path.exists(filepath)
    os.remove(filepath)
def test_upload_reads(self):
    collection = self.res.collection.create(name='Test upload reads')
    samplesheet = self.get_samplesheet()
    with self.assertLogs() as logs:
        collection.upload_reads(samplesheet, basedir='files')
    self.assertEqual(len(logs.output), 37)
    upload_errprefix = 'ERROR:resdk.data_upload.reads:'
    upload_errs = ["Skipping upload of 'Sample 1': No forward reads given.", 'File /storage/61_cat_R1_001.fastq.gz not found.', 'File /storage/63_cat_R1_001.fastq.gz not found.', "Skipping upload of '01_1-1_IP_plus': Invalid file extension(s). (Options: .fq, .fastq)", "Skipping upload of 'missing barcode': Invalid file extension(s). (Options: .fq, .fastq)", "Skipping upload of 'bad extension': Invalid file extension(s). (Options: .fq, .fastq)"]
    for error in upload_errs:
        message = (upload_errprefix + error)
        self.assertIn(message, logs.output)
    upload_fail = ['Sample 1', 'Sample 2', 'Sample 3', 'bad single path', 'bad paired path', ' ,', 'missing annotator', 'missing organism', 'missing source', 'missing molecule', 'missing seq_type', '01_1-1_IP_plus', '02_1-1_IP_minus', 'missing barcode', 'other barcode', '01_1-1_IP_plus2', '02_1-1_IP_minus2', 'duplicated sample', 'invalid qseq', 'invalid qseq2', 'bad extension']
    for invalid in upload_fail:
        self.assertIn(invalid, logs.output[31])
    for missing in upload_fail:
        self.assertIn(missing, logs.output[32])
    upload_success = ['single-reads', 'paired-reads']
    for uploaded in upload_success:
        self.assertNotIn(uploaded, logs.output[31])
        self.assertNotIn(uploaded, logs.output[32])
    names = [sample.name for sample in collection.samples]
    self.assertIn('single-reads', names)
    self.assertIn('paired-reads', names)
    with self.assertLogs() as logs2:
        collection.upload_reads(samplesheet, basedir='files')
    already_up = ["Skipping upload of 'single-reads': File already uploaded.", "Skipping upload of 'paired-reads': File already uploaded."]
    for error in already_up:
        message = (upload_errprefix + error)
        self.assertIn(message, logs2.output)
    self.assertEqual(len(collection.data), 2)
    self.assertEqual(len(collection.samples), 2)
    filepath = 'annotation_template2.xlsm'
    try:
        os.remove(filepath)
    except OSError:
        pass
    collection.export_annotation(filepath)
    assert os.path.exists(filepath)
    os.remove(filepath)