def fixed_tempfolder_processor(self, tmpdir, num_cores): """ Create processor with known temporary folder. Provide some basic required values to the constructor, and critically, fix the temporary folder to the location into which the individual reads chunk files were ensured to exist. The processor constructor provides tempfolder parent as a parameter, but then it creates a temporary folder within that, used to search for the individual chunk output files. Those files have already been created in a test temp folder, though, so the processor needs to know about that. Cleanup of both locations is handled. The processor registers its own temporary folder for removal while pytest cleans up its folder. Parameters ---------- tmpdir : py._path.local.LocalPath Path to where chunks' dummy output files have been placed. num_cores : int Number of cores to use for the test case, parameterized. Returns ------- pararead.ParaReadProcessor New processor instance, with updated temp folder knowledge. """ path_output_file = tmpdir.join("test-output.txt").strpath processor = IdentityProcessor(PATH_ALIGNED_FILE, cores=num_cores, outfile=path_output_file) processor.temp_folder = tmpdir.strpath return processor
def test_different_format(self, tmpdir, filetype, combined_output_type, which_names, extant_files, num_cores): """ File content is actually combined, and formats can differ. """ # Manual creation of the processor here to control output type. path_output_file = tmpdir.join( "testfile.{}".format(combined_output_type)).strpath processor = IdentityProcessor(PATH_ALIGNED_FILE, cores=num_cores, outfile=path_output_file, intermediate_output_type=filetype) processor.temp_folder = tmpdir.strpath # Write to the dummy output file for each chunk. expected_lines = { fp: "file{}: {}\n".format(i, fp) for i, fp in enumerate(extant_files) } for fp, line in expected_lines.items(): with open(fp, 'w') as f: f.write(line) # For control, enforce that combined output doesn't already exist. assert not os.path.exists(path_output_file) processor.combine(self.CHUNK_NAMES[which_names], strict=True) assert os.path.isfile(path_output_file) # Check that output was combined accurately. with open(path_output_file, 'r') as combined: observed_lines = combined.readlines() assert set(expected_lines.values()) == set(observed_lines)