Skip to content

Add comprehensive tests: coverage from 54% to 97%#13

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/analyze-test-coverage
Draft

Add comprehensive tests: coverage from 54% to 97%#13
Copilot wants to merge 3 commits intomainfrom
copilot/analyze-test-coverage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

Summary

This PR significantly improves the test coverage of pyCrossTalkeR from 54% to 97% by adding 75 new tests and fixing two pre-existing bugs found during test writing.

New files

File Description
test/helpers.py Shared SEL_COLUMNS constant and make_lr_df() synthetic-data factory
test/__init__.py Makes test/ a proper package so helpers.py is importable
test/conftest.py Session-scoped analysed_adata pytest fixture (synthetic CTR + EXP conditions)
test/test_coverage.py 75 new tests across 20+ test classes

Coverage per module

Module Before After
tools/utils.py 71% 99%
tools/Single_Condition.py 81% 100%
tools/Comparative_condition.py 77% 100%
plots/plot.py 21% 93%
TOTAL 54% 97%

What is tested

  • utils.py: add_node_type, graph JSON serialization (including numpy scalar edge attrs), get_clustered_node_order, create_ordered_circular_layout, ranking_net (signed + unsigned modes), comparative_pagerank/comparative_med, fisher_test_cci and mannwhitneyu_test_cci with explicit comparison parameter, from_liana (DataFrame path with label, dict path, pval_filter, compute_means)
  • Single_Condition.py: dict-of-CSV-paths input, invalid input types (ValueError), receptor-first gene ordering
  • Comparative_condition.py: explicit comparison parameter, multiple comparison pairs
  • plots/plot.py: plot_cci with log=True, single-coord, emax; plot_bar_rankings with all type filter lengths (1/2/3 chars), filter_sign pos/neg, empty result message; plot_clustermap and plot_graph_clustermap; plot_volcane with annotated red points; plot_pca_LR_comparative (non-ggi, ggi with gene_types, include_tf=True); plot_sankey all filter branches; gen_sankey2

Bug fixes

  1. plot_bar_rankings filter_sign (plots/plot.py line 337–339): Referenced hardcoded string 'ranking' instead of the ranking parameter, always raising KeyError. Fixed to use the variable.

  2. plot_pca_LR_comparative include_tf=True (plots/plot.py line 195): Used pd.DataFrame(pca_df.index, columns=["gene"]) which returns an empty DataFrame in pandas 2.x when the index originates from a .loc[] call. Fixed to pd.DataFrame({"gene": pca_df.index}).

Remaining uncovered lines (3%)

  • utils.py 458, 509: Dead code — B <= 0 branch, B is hardcoded to 1000
  • plot.py 187: gene_types="TF" in ggi mode produces empty PCA → crash
  • plot.py 227: PCA text annotation only fires when a point is >4σ (not reproducible with small synthetic data)
  • plot.py 415, 421: Legacy data handling when gene names don't yet have | separators
  • plot.py 683–716: gene_annotation() — requires live external gProfiler API call
  • generate_report.py 80: save=True branch — requires a filesystem output path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants