示例#1
0
 def test_extract_gz(self):
     with TemporaryDirectory() as tempd:
         extract_gz(Test_File.TAR_GZ_FILE, tempd)
         self.assertEqual(
             sha256(Path(os_path.join(
                 tempd, 'data.tar')).read_bytes()).hexdigest(),
             'd3eb1c4b3604e6863fb4c4da930b4df74217fcf95c78439bc721ea83ce280f19'
         )
示例#2
0
    def test_generate_cache(self):
        r"""Test of genrating all rpCache files from input_cache.

        Method: Generate a full rpCache. Then, for each file, compare its size
        with it is supposed to be.
        """
        self.skipTest("Tool long, not in standard tests")
        rpCache.generate_cache(self.outdir)
        for file, size in self.files:
            outfile = extract_gz(file, self.outdir)
            self.assertTrue(Main._check_file_size(outfile, size))
            os_rm(outfile)
示例#3
0
    def setUp(self):
        self.logger = create_logger(__name__, 'ERROR')

        # Create persistent temp folder
        # to deflate compressed data file so that
        # it remains reachable outside of this method.
        # Has to remove manually it in tearDown() method 
        self.temp_d = mkdtemp()

        self.e_coli_model_path = extract_gz(
            self.e_coli_model_path_gz,
            self.temp_d
        )
示例#4
0
 def test_compress_gz_with_outFile(self):
     infile_t = '100l_file.txt'
     infile = os_path.join('data', infile_t)
     outfile_temp = NamedTemporaryFile().name
     outfile = compress_gz(infile, outfile_temp)
     # Check if the original file still exists
     self.assertTrue(os_path.isfile(infile))
     # Check if outfile is well named
     self.assertEqual(outfile, outfile_temp)
     # Check if extracted file is equal to original one
     with TemporaryDirectory() as tempd:
         self.assertTrue(cmp(infile, extract_gz(outfile, tempd)))
     remove(outfile)
示例#5
0
 def test_compress_gz_delete(self):
     infile_t = '100l_file.txt'
     infile = os_path.join('data', infile_t)
     infile_temp = NamedTemporaryFile().name
     copyfile(infile, infile_temp)
     outfile = compress_gz(infile_temp, delete=True)
     # Check if the original file does not exist anymore
     self.assertTrue(not os_path.isfile(infile_temp))
     # Check if outfile is well named
     self.assertEqual(outfile, infile_temp + '.gz')
     # Check if extracted file is equal to original one
     with TemporaryDirectory() as tempd:
         self.assertTrue(cmp(infile, extract_gz(outfile, tempd)))
     remove(outfile)
示例#6
0
def gunzip_to_csv(filename: str, indir: str) -> str:
    """
    Uncompress gzip file into indir.

    Parameters
    ----------
    filename : str
        Path of file to deflate.
    indir : str
        Path where install.

    """
    new_f = os_path.join(indir, os_path.basename(filename) + '.gz')
    copyfile(filename, new_f)
    filename = extract_gz(new_f, indir)
    rename(filename, filename + '.csv')
    filename += '.csv'

    return filename