def test_is_compression_done_spring_new_files( crunchy_config_dict: dict, compression_object: CompressionData, spring_metadata_file: Path, caplog, ): """Test if compression is done when FASTQ files have been unpacked This test should fail since the FASTQ files are new """ caplog.set_level(logging.DEBUG) # GIVEN a crunchy-api, and FASTQ paths crunchy_api = CrunchyAPI(crunchy_config_dict) # GIVEN a existing SPRING file compression_object.spring_path.touch() assert compression_object.spring_path.exists() # GIVEN a existing flag file metadata_file = compression_object.spring_metadata_path assert spring_metadata_file == compression_object.spring_metadata_path assert metadata_file.exists() # GIVEN that the files where updated less than three weeks ago update_metadata_date(metadata_file) with open(metadata_file, "r") as infile: content: List[Dict[str, str]] = json.load(infile) for file_info in content: assert "updated" in file_info # WHEN checking if SPRING compression is done result = crunchy_api.is_fastq_compression_done(compression_object) # THEN result should be False since the updated date < 3 weeks assert result is False # THEN assert that correct information is logged assert "FASTQ files are not old enough" in caplog.text
def test_is_compression_done_no_spring(crunchy_config_dict: dict, compression_object: CompressionData, caplog): """Test if compression is done when no SPRING archive""" caplog.set_level(logging.DEBUG) # GIVEN a crunchy-api, and FASTQ paths crunchy_api = CrunchyAPI(crunchy_config_dict) # GIVEN no SPRING file exists spring_file = compression_object.spring_path assert not spring_file.exists() # WHEN checking if SPRING compression is done result = crunchy_api.is_fastq_compression_done(compression_object) # THEN result should be false assert not result # THEN assert that the correct message was communicated assert f"No SPRING file for {compression_object.run_name}" in caplog.text
def test_is_compression_done_no_flag_spring( crunchy_config_dict: dict, compression_object: CompressionData, caplog): """Test if SPRING compression is done when no metadata file""" caplog.set_level(logging.DEBUG) # GIVEN a crunchy-api, and FASTQ paths crunchy_api = CrunchyAPI(crunchy_config_dict) # GIVEN a existing SPRING file compression_object.spring_path.touch() assert compression_object.spring_path.exists() # GIVEN a non existing flag file assert not compression_object.spring_metadata_path.exists() # WHEN checking if SPRING compression is done result = crunchy_api.is_fastq_compression_done(compression_object) # THEN result should be false assert not result # THEN assert that the correct message was communicated assert "No metadata file found" in caplog.text
def test_is_compression_done( crunchy_config_dict: dict, spring_metadata_file: Path, compression_object: CompressionData, caplog, ): """Test if compression is done when everything is correct""" caplog.set_level(logging.DEBUG) # GIVEN a crunchy-api, and FASTQ paths crunchy_api = CrunchyAPI(crunchy_config_dict) # GIVEN no SPRING file exists compression_object.spring_path.touch() assert spring_metadata_file == compression_object.spring_metadata_path assert spring_metadata_file.exists() # WHEN checking if SPRING compression is done result = crunchy_api.is_fastq_compression_done(compression_object) # THEN result should be True assert result is True # THEN assert that the correct message was communicated assert "FASTQ compression is done" in caplog.text
def test_is_compression_done_spring_old_files( crunchy_config_dict: dict, compression_object: CompressionData, spring_metadata_file: Path, caplog, ): """Test if compression is done when FASTQ files are updated a long time ago The function should return True since files are old """ caplog.set_level(logging.DEBUG) # GIVEN a crunchy-api, and FASTQ paths crunchy_api = CrunchyAPI(crunchy_config_dict) # GIVEN a existing SPRING file compression_object.spring_path.touch() assert compression_object.spring_path.exists() # GIVEN a existing flag file metadata_file = compression_object.spring_metadata_path assert spring_metadata_file == compression_object.spring_metadata_path assert metadata_file.exists() # GIVEN that the files where updated less than three weeks ago update_metadata_date(metadata_file) with open(metadata_file, "r") as infile: content = json.load(infile) for file_info in content: file_info["updated"] = "2019-01-01" with open(metadata_file, "w") as outfile: outfile.write(json.dumps(content)) # WHEN checking if SPRING compression is done result = crunchy_api.is_fastq_compression_done(compression_object) # THEN result should be True since the updated date > 3 weeks assert result is True # THEN assert that correct information is logged assert "FASTQ compression is done" in caplog.text
def test_is_compression_done_spring( crunchy_config_dict: dict, compression_object: CompressionData, spring_metadata_file: Path, caplog, ): """Test if compression is done when SPRING files exists""" caplog.set_level(logging.DEBUG) # GIVEN a crunchy-api, and FASTQ paths crunchy_api = CrunchyAPI(crunchy_config_dict) # GIVEN a existing SPRING file compression_object.spring_path.touch() assert compression_object.spring_path.exists() # GIVEN a existing flag file assert spring_metadata_file == compression_object.spring_metadata_path assert compression_object.spring_metadata_path.exists() # WHEN checking if SPRING compression is done result = crunchy_api.is_fastq_compression_done(compression_object) # THEN result should be True assert result # THEN assert that the correct message was communicated assert f"FASTQ compression is done for {compression_object.run_name}" in caplog.text