"""Integration tests for the Pigeon Pea Pangenome Atlas.""" import pytest from pathlib import Path from src.state import AppState from src.callbacks import ( on_line_selected, build_umap_plot, build_donut_chart, build_treasure_table, on_pin_gene, build_hotspot_heatmap, get_protein_stats_html, on_generate_report, ) from src.gene_card import build_gene_card, render_gene_card_html class TestFullFlow: def test_full_flow(self, synthetic_data): """Simulate: select line -> UMAP -> thresholds -> gene card -> pin -> report.""" state = AppState() # Step 1: Select line line_id = synthetic_data["line_stats"].iloc[0]["line_id"] total, unique, neighbor, state = on_line_selected(line_id, state, synthetic_data) assert state.selected_line == line_id # Step 2: View UMAP fig = build_umap_plot("Country", state, synthetic_data) assert fig is not None # Step 3: Change thresholds donut = build_donut_chart(90, 10, synthetic_data) assert donut is not None # Step 4: View treasure table table = build_treasure_table(state, 90, 10, "All", synthetic_data) assert len(table) > 0 # Step 5: Click gene -> gene card gene_id = table.iloc[0]["gene_id"] card = build_gene_card(gene_id, synthetic_data) html = render_gene_card_html(card) assert gene_id in html # Step 6: Pin gene state.selected_gene = gene_id _, state = on_pin_gene(gene_id, state) assert gene_id in state.backpack_genes # Step 7: Generate report report_md, json_file, csv_file, badges, state = on_generate_report(state, synthetic_data) assert len(report_md) > 100 assert "Cartographer" in state.achievements class TestPrecomputedConsistency: def test_embedding_line_ids(self, synthetic_data): """All line_ids in embedding exist in line_stats.""" emb_lines = set(synthetic_data["embedding"]["line_id"]) stat_lines = set(synthetic_data["line_stats"]["line_id"]) assert emb_lines.issubset(stat_lines) def test_marker_gene_ids(self, synthetic_data): """All gene_ids in markers exist in gene_freq.""" if len(synthetic_data["markers"]) == 0: pytest.skip("No markers computed") marker_genes = set(synthetic_data["markers"]["gene_id"]) freq_genes = set(synthetic_data["gene_freq"]["gene_id"]) assert marker_genes.issubset(freq_genes)