-
Notifications
You must be signed in to change notification settings - Fork 11
[WIP] Test Coverage for Line Methods, Changes to Line Methods #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c055305
Add line tests for base module, changes to line methods in base module.
marty-larocque bfa569f
Minor change to assert_xy conversion method.
marty-larocque baee57e
Revert "Minor change to assert_xy conversion method."
marty-larocque 9ca93cf
Improved handline of lines without xy-data (Issue #238)
marty-larocque 92ae521
Added docstrings to line tests.
marty-larocque 5e33728
Added Seaborn to dev requirements
marty-larocque 76f2624
Undo changes regarding x-limits problems (Issue #235)
marty-larocque c81f6d1
Merge branch 'master' into line_tests
marty-larocque 75a8fb1
Merge branch 'master' into line_tests
marty-larocque 5352acc
Made checking line coverage optional for base.assert_line()
marty-larocque 5b51d0e
Fix double requirement in dev-requirements.txt
marty-larocque 7dc3c9a
Change seaborn version
marty-larocque ae7c000
Seaborn requirement version change
marty-larocque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,5 @@ setuptools==46.1.3 | |
| pre-commit==1.20.0 | ||
| pip==19.0.3 | ||
| descartes==1.1.0 | ||
| seaborn>=0.9.1 | ||
| pillow==7.1.2 | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import pytest | ||
| from matplotcheck.base import PlotTester | ||
| import matplotlib.pyplot as plt | ||
| import pandas as pd | ||
| import seaborn as sns | ||
| from scipy import stats | ||
|
|
||
| """Fixtures""" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pd_df_reg_data(): | ||
| """Create a pandas dataframe with points that are roughly along the same | ||
| line.""" | ||
| data = { | ||
| "A": [1.2, 1.9, 3.0, 4.1, 4.6, 6.0, 6.9, 8.4, 9.0], | ||
| "B": [2.4, 3.9, 6.1, 7.8, 9.0, 11.5, 15.0, 16.2, 18.6], | ||
| } | ||
|
|
||
| return pd.DataFrame(data) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pt_reg_data(pd_df_reg_data): | ||
| """Create a PlotTester object with a regression line""" | ||
| fig, ax = plt.subplots() | ||
| sns.regplot("A", "B", data=pd_df_reg_data, ax=ax) | ||
|
|
||
| return PlotTester(ax) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pt_one2one(): | ||
| """Create a PlotTester object a one-to-one line""" | ||
| fig, ax = plt.subplots() | ||
| ax.plot((0, 1), (0, 1), transform=ax.transAxes, ls="--", c="k") | ||
|
|
||
| return PlotTester(ax) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pt_reg_one2one(pd_df_reg_data): | ||
| """Create a PlotTester object with a regression line and a one-to-one | ||
| line""" | ||
| fig, ax = plt.subplots() | ||
| sns.regplot("A", "B", data=pd_df_reg_data, ax=ax) | ||
| ax.plot((0, 1), (0, 1), transform=ax.transAxes, ls="--", c="k") | ||
|
|
||
| return PlotTester(ax) | ||
|
|
||
|
|
||
| def test_reg_plot(pd_df_reg_data, pt_reg_data): | ||
| """Test that assert_line() correctly passes when given the correct slope | ||
| and intercept.""" | ||
| # Get the correct slope and intercept for the data | ||
| slope_exp, intercept_exp, _, _, _ = stats.linregress( | ||
| pd_df_reg_data.A, pd_df_reg_data.B | ||
| ) | ||
|
|
||
| pt_reg_data.assert_line(slope_exp, intercept_exp) | ||
|
|
||
|
|
||
| def test_reg_plot_slope_fails(pd_df_reg_data, pt_reg_data): | ||
| """Check that assert_line() correctly falis when given an incorrect | ||
| slope.""" | ||
| _, intercept_exp, _, _, _ = stats.linregress( | ||
| pd_df_reg_data.A, pd_df_reg_data.B | ||
| ) | ||
| with pytest.raises(AssertionError, match="Expected line not displayed"): | ||
| pt_reg_data.assert_line(1, intercept_exp) | ||
|
|
||
|
|
||
| def test_reg_plot_intercept_fails(pd_df_reg_data, pt_reg_data): | ||
| """Check that assert_line() correctly fails when given an incorrect | ||
| intercept""" | ||
| slope_exp, _, _, _, _ = stats.linregress( | ||
| pd_df_reg_data.A, pd_df_reg_data.B | ||
| ) | ||
|
|
||
| with pytest.raises(AssertionError, match="Expected line not displayed"): | ||
| pt_reg_data.assert_line(slope_exp, 1) | ||
|
|
||
|
|
||
| def test_line_type_reg(pt_reg_data): | ||
| """Check that assert_lines_of_type() correctly passes when checking for a | ||
| regression line.""" | ||
| pt_reg_data.assert_lines_of_type("regression") | ||
|
|
||
|
|
||
| def test_line_type_one2one(pt_one2one): | ||
| """Check that assert_lines_of_type() correctly passes when checking for a | ||
| one-to-one line.""" | ||
| pt_one2one.assert_lines_of_type("onetoone") | ||
|
|
||
|
|
||
| def test_line_type_reg_one2one(pt_reg_one2one): | ||
| """Check that assert_lines_of_type() correctly passes when checking for | ||
| both a regression line and a one-to-one line.""" | ||
| pt_reg_one2one.assert_lines_of_type(["regression", "onetoone"]) | ||
|
|
||
|
|
||
| def test_line_type_reg_fails(pt_one2one): | ||
| """Check that assert_lines_of_type() correctly fails when checking for a | ||
| regression line, but one does not exist.""" | ||
| with pytest.raises( | ||
| AssertionError, match="regression line not displayed properly" | ||
| ): | ||
| pt_one2one.assert_lines_of_type("regression") | ||
|
|
||
|
|
||
| def test_line_type_one2one_fails(pt_reg_data): | ||
| """Check that assert_lines_of_type() correctly fails when checking for a | ||
| one-to-one line, but one does not exist.""" | ||
| with pytest.raises( | ||
| AssertionError, match="onetoone line not displayed properly" | ||
| ): | ||
| pt_reg_data.assert_lines_of_type("onetoone") |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets: