Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMainguy committed Dec 18, 2024
1 parent 9ffe382 commit 5701506
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion binette/bin_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def assess_bins_quality_by_chunk(

for i, chunk_bins_iter in enumerate(chunks(bins, chunk_size)):
chunk_bins = set(chunk_bins_iter)
logging.debug(f"chunk {i}: assessing quality of {len(chunk_bins)}")
logging.debug(f"chunk {i}: assessing quality of {len(chunk_bins)} bins")
assess_bins_quality(
bins=chunk_bins,
contig_to_kegg_counter=contig_to_kegg_counter,
Expand Down
22 changes: 10 additions & 12 deletions tests/bin_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ def test_select_best_bins_with_equality():

# The function should create intersection bins when there are overlapping contigs between bins.
def test_intersection_bins_created():
set1 = [
set1 = {
bin_manager.Bin(contigs={"1", "2"}, origin="A", name="bin1"),
bin_manager.Bin(contigs={"3", "4"}, origin="A", name="bin2"),
bin_manager.Bin(contigs={"5"}, origin="A", name="bin2"),
]
}
# need to defined completeness and conta
# because when too low the bin is not used in all operation
for b in set1:
Expand All @@ -270,14 +270,12 @@ def test_intersection_bins_created():
binA = bin_manager.Bin(contigs={"1", "3"}, origin="B", name="binA")
binA.contamination = 0
binA.completeness = 100
set2 = [
set2 = {
binA,
]
bin_set_name_to_bins = {"set1": set1, "set2": set2}
}
input_bins = set1 | set2

intermediate_bins_result = bin_manager.create_intermediate_bins(
bin_set_name_to_bins
)
intermediate_bins_result = bin_manager.create_intermediate_bins(input_bins)

expected_intermediate_bins = {
bin_manager.Bin(contigs={"1", "2", "3"}, origin="bin1 | binA ", name="NA"),
Expand Down Expand Up @@ -337,19 +335,19 @@ def test_dereplicate_bin_sets():
assert derep_bins_result == {b1, b2, b3}


def test_from_bin_sets_to_bin_graph():
def test_from_bins_to_bin_graph():

bin1 = bin_manager.Bin(contigs={"1", "2"}, origin="A", name="bin1")
bin2 = bin_manager.Bin(contigs={"3", "4"}, origin="A", name="bin2")
bin3 = bin_manager.Bin(contigs={"5"}, origin="A", name="bin3")

set1 = [bin1, bin2, bin3]
set1 = {bin1, bin2, bin3}

binA = bin_manager.Bin(contigs={"1", "3"}, origin="B", name="binA")

set2 = [binA]
set2 = {binA}

result_graph = bin_manager.from_bin_sets_to_bin_graph({"B": set2, "A": set1})
result_graph = bin_manager.from_bins_to_bin_graph(set1 | set2)

assert result_graph.number_of_edges() == 2
# bin3 is not connected to any bin so it is not in the graph
Expand Down
11 changes: 5 additions & 6 deletions tests/io_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,16 @@ def test_write_original_bin_metrics(mock_write_bin_info, bin1, bin2, tmp_path):

temp_directory = tmp_path / "test_output"

mock_bins = {"set1": {bin1}, "set2": {bin2}}
# Call the function with mock data
io_manager.write_original_bin_metrics(mock_bins, temp_directory)
io_manager.write_original_bin_metrics({bin1, bin2}, temp_directory)

# Check if the output directory was created
assert temp_directory.exists(), "Output directory should be created."

# Check that the correct files are created
expected_files = [
temp_directory / "input_bins_1.set1.tsv",
temp_directory / "input_bins_2.set2.tsv",
temp_directory / "input_bins_1.origin1.tsv",
temp_directory / "input_bins_2.origin2.tsv",
]

assert (
Expand All @@ -373,5 +372,5 @@ def test_write_original_bin_metrics(mock_write_bin_info, bin1, bin2, tmp_path):
), "write_bin_info should be called once for each bin set."

# Verify the specific calls to `write_bin_info`
mock_write_bin_info.assert_any_call(mock_bins["set1"], expected_files[0])
mock_write_bin_info.assert_any_call(mock_bins["set2"], expected_files[1])
mock_write_bin_info.assert_any_call({bin1}, expected_files[0])
mock_write_bin_info.assert_any_call({bin2}, expected_files[1])
14 changes: 5 additions & 9 deletions tests/main_binette_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,15 @@ def test_parse_input_files_with_contig2bin_tables(tmp_path):
fasta_file.write_text(fasta_file_content)

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

# # Perform assertions on the returned values
assert isinstance(bin_set_name_to_bins, dict)
assert isinstance(original_bins, set)
assert isinstance(contigs_in_bins, set)
assert isinstance(contig_to_length, dict)

assert set(bin_set_name_to_bins) == {"bin_set1", "bin_set2"}
assert len(original_bins) == 4
assert contigs_in_bins == {"contig1", "contig2", "contig3", "contig4"}
assert len(contig_to_length) == 4
Expand Down Expand Up @@ -248,17 +246,15 @@ def test_parse_input_files_bin_dirs(create_temp_bin_directories, tmp_path):
fasta_file.write_text(fasta_file_content)

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

# # Perform assertions on the returned values
assert isinstance(bin_set_name_to_bins, dict)
assert isinstance(original_bins, set)
assert isinstance(contigs_in_bins, set)
assert isinstance(contig_to_length, dict)

assert set(bin_set_name_to_bins) == {"set1", "set2"}
assert len(original_bins) == 3
assert contigs_in_bins == {
"contig1",
Expand Down Expand Up @@ -471,7 +467,7 @@ def test_main(monkeypatch, test_environment):
) as mock_select_bins_and_write_them:

# Set return values for mocked functions if needed
mock_parse_input_files.return_value = (None, None, None, None)
mock_parse_input_files.return_value = (None, None, None)
mock_manage_protein_alignement.return_value = (
{"contig1": 1},
{"contig1": ["gene1"]},
Expand Down

0 comments on commit 5701506

Please sign in to comment.