Ejemplo n.º 1
0
 def test_check_files_exist_and_md5(self):
     """test _check_files_exist_and_md5"""
     file1 = "tmp.spreadsheet_validator.file1"
     file2 = "tmp.spreadsheet_validator.file2"
     with open(file1, "w") as f1, open(file2, "w") as f2:
         print("foo", file=f1)
         print("bar", file=f2)
     reads_file_1_md5 = utils.md5(file1)
     dict_list = [{
         "reads_file_1": file1,
         "reads_file_1_md5": reads_file_1_md5,
         "reads_file_2": file2,
         "reads_file_2_md5": utils.md5(file2),
     }]
     self.assertEqual(
         [],
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd(), md5_threads=1),
     )
     self.assertEqual(
         [],
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd(), md5_threads=2),
     )
     dict_list[0]["reads_file_1_md5"] = "12345"
     expected = ["md5_error\t" + file1 + "\t12345\t" + reads_file_1_md5]
     self.assertEqual(
         expected,
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd(), md5_threads=1),
     )
     self.assertEqual(
         [],
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd(), md5_threads=0),
     )
     os.unlink(file1)
     expected = ["File_not_found\t" + file1 + "\t2"]
     self.assertEqual(
         expected,
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd()),
     )
     os.unlink(file2)
     expected.append("File_not_found\t" + file2 + "\t2")
     self.assertEqual(
         expected,
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd()),
     )
 def test_check_files_exist_and_md5(self):
     '''test _check_files_exist_and_md5'''
     file1 = 'tmp.spreadsheet_validator.file1'
     file2 = 'tmp.spreadsheet_validator.file2'
     with open(file1, 'w') as f1, open(file2, 'w') as f2:
         print('foo', file=f1)
         print('bar', file=f2)
     reads_file_1_md5 = utils.md5(file1)
     dict_list = [{
         'reads_file_1': file1,
         'reads_file_1_md5': reads_file_1_md5,
         'reads_file_2': file2,
         'reads_file_2_md5': utils.md5(file2),
     }]
     self.assertEqual([],
                      spreadsheet_validator.SpreadsheetValidator.
                      _check_files_exist_and_md5(dict_list,
                                                 os.getcwd(),
                                                 md5_threads=1))
     self.assertEqual([],
                      spreadsheet_validator.SpreadsheetValidator.
                      _check_files_exist_and_md5(dict_list,
                                                 os.getcwd(),
                                                 md5_threads=2))
     dict_list[0]['reads_file_1_md5'] = '12345'
     expected = ['md5_error\t' + file1 + '\t12345\t' + reads_file_1_md5]
     self.assertEqual(
         expected,
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd(), md5_threads=1))
     self.assertEqual([],
                      spreadsheet_validator.SpreadsheetValidator.
                      _check_files_exist_and_md5(dict_list,
                                                 os.getcwd(),
                                                 md5_threads=0))
     os.unlink(file1)
     expected = ['File_not_found\t' + file1 + '\t2']
     self.assertEqual(
         expected,
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd()))
     os.unlink(file2)
     expected.append('File_not_found\t' + file2 + '\t2')
     self.assertEqual(
         expected,
         spreadsheet_validator.SpreadsheetValidator.
         _check_files_exist_and_md5(dict_list, os.getcwd()))
Ejemplo n.º 3
0
 def _copy_reads_file(cls, old_name, new_name, expected_md5):
     old_name_md5 = utils.md5(old_name)
     if old_name_md5 != expected_md5:
         raise Error(
             "MD5 given by submitter "
             + expected_md5
             + " does not match calculated MD5 "
             + old_name_md5
         )
     utils.rsync_and_md5(old_name, new_name, expected_md5)
Ejemplo n.º 4
0
    def test_copy_reads_file(self):
        '''test _copy_reads_file'''
        original_reads_file = os.path.join(data_dir, 'copy_reads_file.fq')
        correct_md5 = '1bf5fb5b641e793ba40285779a059132'
        tmp_reads_file = 'tmp.read_pair_importer.copy_reads_file.out'
        if os.path.exists(tmp_reads_file):
            os.unlink(tmp_reads_file)

        read_pair_importer.ReadPairImporter._copy_reads_file(original_reads_file, tmp_reads_file, correct_md5)
        self.assertTrue(os.path.exists(tmp_reads_file))
        self.assertEqual(correct_md5, utils.md5(tmp_reads_file))

        with self.assertRaises(read_pair_importer.Error):
            read_pair_importer.ReadPairImporter._copy_reads_file(original_reads_file, tmp_reads_file, 'wrong md5')

        os.unlink(tmp_reads_file)
Ejemplo n.º 5
0
    def test_copy_reads_file(self):
        """test _copy_reads_file"""
        original_reads_file = os.path.join(data_dir, "copy_reads_file.fq")
        correct_md5 = "1bf5fb5b641e793ba40285779a059132"
        tmp_reads_file = "tmp.read_pair_importer.copy_reads_file.out"
        if os.path.exists(tmp_reads_file):
            os.unlink(tmp_reads_file)

        read_pair_importer.ReadPairImporter._copy_reads_file(
            original_reads_file, tmp_reads_file, correct_md5)
        self.assertTrue(os.path.exists(tmp_reads_file))
        self.assertEqual(correct_md5, utils.md5(tmp_reads_file))

        with self.assertRaises(read_pair_importer.Error):
            read_pair_importer.ReadPairImporter._copy_reads_file(
                original_reads_file, tmp_reads_file, "wrong md5")

        os.unlink(tmp_reads_file)
Ejemplo n.º 6
0
def _write_md5_file(infile):
    print('Start calculate md5 of', infile)
    with open(infile + '.md5', 'w') as f:
        print(utils.md5(infile), os.path.basename(infile), sep='  ', file=f)
    print('End calculate md5 of', infile)
Ejemplo n.º 7
0
def _check_md5(filename, expect_md5):
    got_md5 = utils.md5(filename)
    if expect_md5 == got_md5:
        return (filename, None, None)
    else:
        return (filename, expect_md5, got_md5)
Ejemplo n.º 8
0
 def test_md5(self):
     '''test md5'''
     filename = os.path.join(data_dir, 'md5.txt')
     expected = 'f738cdb99c0c6a670aa1e5742066b0cf'
     got = utils.md5(filename)
     self.assertEqual(expected, got)
Ejemplo n.º 9
0
def _write_md5_file(infile):
    print("Start calculate md5 of", infile)
    with open(infile + ".md5", "w") as f:
        print(utils.md5(infile), os.path.basename(infile), sep="  ", file=f)
    print("End calculate md5 of", infile)
Ejemplo n.º 10
0
 def test_md5(self):
     """test md5"""
     filename = os.path.join(data_dir, "md5.txt")
     expected = "f738cdb99c0c6a670aa1e5742066b0cf"
     got = utils.md5(filename)
     self.assertEqual(expected, got)