Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMainguy committed Dec 19, 2024
1 parent af582a7 commit 98cdde5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/cds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def test_write_faa(contig1, orf_finder):

predicted_genes = orf_finder.find_genes(contig1.seq)
contig_name = "contig"
output_file = "tests/tmp_file.faa"
output_file = "tests/tmp_file.faa.gz"

cds.write_faa(output_file, [(contig_name, predicted_genes)])

# Check if the file was created and first seq starts
# with the contig name as expected
assert Path(output_file).exists()
with open(output_file, "r") as f:
with gzip.open(output_file, "rt") as f:
assert f.read().startswith(f">{contig_name}")


Expand Down
9 changes: 5 additions & 4 deletions tests/contig_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@


# Parses a valid FASTA file and returns a pyfastx.Fasta object.
def test_valid_fasta_file():
def test_valid_fasta_file(tmp_path):
# Arrange
fasta_file = "tests/contigs.fasta"

# Act
result = contig_manager.parse_fasta_file(fasta_file)
index_file = "tests/contigs.fasta.fxi"

result = contig_manager.parse_fasta_file(fasta_file, str(index_file))

# Assert
assert isinstance(result, pyfastx.Fasta)
Expand All @@ -22,7 +23,7 @@ def test_invalid_fasta_file():

# Act and Assert
with pytest.raises(RuntimeError):
contig_manager.parse_fasta_file(fasta_file)
contig_manager.parse_fasta_file(fasta_file, "./index.fxi")


# The function returns a tuple containing two dictionaries.
Expand Down
2 changes: 1 addition & 1 deletion tests/diamonds_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(self, returncode):
# Simulating successful run of diamond command
if (
args[0]
== "diamond blastp --outfmt 6 --max-target-seqs 1 --query test.faa -o output.txt --threads 1 --db db --query-cover 80 --subject-cover 80 --id 30 --evalue 1e-05 --block-size 2 2> log.txt"
== "diamond blastp --outfmt 6 --max-target-seqs 1 --query test.faa -o output.txt --threads 1 --db db --compress 1 --query-cover 80 --subject-cover 80 --id 30 --evalue 1e-05 --block-size 2 2> log.txt"
):
return CompletedProcess(0)

Expand Down
11 changes: 7 additions & 4 deletions tests/main_binette_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def test_manage_protein_alignement_resume(tmp_path):
contig_to_kegg_counter, contig_to_genes = manage_protein_alignement(
faa_file=Path(faa_file),
contigs_fasta=Path("contigs_fasta"),
temporary_dir=Path(tmp_path),
contig_to_length=contig_to_length,
contigs_in_bins=set(),
diamond_result_file=Path("diamond_result_file"),
Expand Down Expand Up @@ -179,6 +180,7 @@ def test_manage_protein_alignement_not_resume(tmpdir, tmp_path):
contig_to_kegg_counter, contig_to_genes = manage_protein_alignement(
faa_file=Path(faa_file),
contigs_fasta=Path(contigs_fasta),
temporary_dir=Path(tmp_path),
contig_to_length=contig_to_length,
contigs_in_bins=set(),
diamond_result_file=Path(diamond_result_file),
Expand Down Expand Up @@ -208,7 +210,7 @@ def test_parse_input_files_with_contig2bin_tables(tmp_path):

# Call the function and capture the return values
original_bins, contigs_in_bins, contig_to_length = parse_input_files(
None, [bin_set1, bin_set2], fasta_file
None, [bin_set1, bin_set2], fasta_file, tmp_path
)

# # Perform assertions on the returned values
Expand All @@ -230,7 +232,7 @@ def test_parse_input_files_with_contig2bin_tables_with_unknown_contig(tmp_path):
fasta_file.write_text(fasta_file_content)

with pytest.raises(ValueError):
parse_input_files(None, [bin_set3], fasta_file)
parse_input_files(None, [bin_set3], fasta_file, tmp_path)


def test_parse_input_files_bin_dirs(create_temp_bin_directories, tmp_path):
Expand All @@ -247,7 +249,7 @@ def test_parse_input_files_bin_dirs(create_temp_bin_directories, tmp_path):

# Call the function and capture the return values
original_bins, contigs_in_bins, contig_to_length = parse_input_files(
bin_dirs, contig2bin_tables, fasta_file
bin_dirs, contig2bin_tables, fasta_file, temporary_dir=tmp_path
)

# # Perform assertions on the returned values
Expand Down Expand Up @@ -384,6 +386,7 @@ def test_manage_protein_alignment_no_resume(tmp_path):
contig_to_kegg_counter, contig_to_genes = manage_protein_alignement(
faa_file,
contigs_fasta,
tmp_path,
contig_to_length,
contigs_in_bins,
diamond_result_file,
Expand All @@ -395,7 +398,7 @@ def test_manage_protein_alignment_no_resume(tmp_path):
)

# Assertions to check if functions were called
mock_parse_fasta_file.assert_called_once_with(contigs_fasta.as_posix())
mock_parse_fasta_file.assert_called_once()
mock_predict.assert_called_once()
mock_diamond_get_contig_to_kegg_id.assert_called_once()
mock_diamond_run.assert_called_once_with(
Expand Down

0 comments on commit 98cdde5

Please sign in to comment.