Add comprehensive test suite for lorepy plotting functions#15
Open
Add comprehensive test suite for lorepy plotting functions#15
Conversation
This commit overhauls the test suite to provide more thorough coverage: **New conftest.py with shared fixtures:** - Deterministic random seeds for reproducibility - Multiple data fixtures (binary, multiclass, NaN data, edge cases) - Pre-fitted model fixtures for unit testing internal functions - Removed duplicate fixtures between test files **test_plot.py improvements:** - New TestPrepareData class: Tests for _prepare_data function including NaN handling, confounders, x_range calculation, data ordering - New TestGetAreaDf class: Tests for _get_area_df including probability sum validation, range respecting, confounders, multiclass - New TestGetDotsDf class: Tests for _get_dots_df including coordinate validation, jitter functionality, probability band verification - Improved TestLoreplot class: Tests for axis limits, dot rendering, confounders disabling dots, custom classifiers and parameters - New TestEdgeCases class: Single class, empty data, missing columns, NaN handling, inverted ranges, zero-width range edge cases **test_uncertainty.py improvements:** - New TestGetUncertaintyData class: Tests for _get_uncertainty_data (previously untested) including output structure, bounds ordering, probability ranges, multiclass support - Improved TestGetFeatureImportance: Added confidence interval, proportion validation, p-value range, interpretation format tests - Improved TestUncertaintyPlot: Added plot content verification (fill, lines), axis setup, multiclass axes count - New TestUncertaintyEdgeCases: Edge cases for iterations, jackknife fractions, string labels, NaN handling Test count increased from 27 to 91 tests, achieving 100% code coverage. https://claude.ai/code/session_01VQDpjboqTU7pr11X9tVWCX
Apply ruff and black formatting: - Remove unused imports (SVC, ListedColormap, LogisticRegression) - Apply black code formatting to test files https://claude.ai/code/session_01VQDpjboqTU7pr11X9tVWCX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR significantly expands the test coverage for the lorepy package by adding a comprehensive test suite with 50+ test cases covering all major functions and edge cases.
Key Changes
New Test Infrastructure (
tests/conftest.py)binary_sample_data: Two-class classification dataset with confoundersmulticlass_sample_data: Three-class classification datasetdata_with_nan: Dataset with missing values for NaN handling testssmall_deterministic_data: Small, reproducible dataset for precise testingfitted_logistic_model/fitted_multiclass_model: Pre-fitted classifierssingle_class_data,empty_dataframe: Edge case datasetsstring_class_labels: Non-integer class labelscustom_colormap: Matplotlib colormap for visualization testsExpanded Test Coverage (
tests/test_plot.py)Reorganized and expanded from ~130 to ~523 lines with structured test classes:
TestPrepareData (7 tests)
TestGetAreaDf (7 tests)
TestGetDotsDf (7 tests)
TestLoreplot (15 tests)
TestEdgeCases (8 tests)
Implementation Details
https://claude.ai/code/session_01VQDpjboqTU7pr11X9tVWCX