Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8344d56
Merge pull request #1 from earthlab/master
nkorinek Feb 6, 2020
b87394d
Merge pull request #2 from earthlab/master
nkorinek Feb 12, 2020
7cf2703
Merge pull request #3 from earthlab/master
nkorinek Feb 12, 2020
c4d904e
Merge pull request #4 from earthlab/master
nkorinek Feb 13, 2020
eef044b
add flake 8
Feb 13, 2020
3a05d3a
yay cleanup
Feb 13, 2020
1e24b60
update change log
Feb 13, 2020
c6deb54
Merge pull request #5 from earthlab/master
nkorinek Feb 13, 2020
202c737
add flake 8 dep
Feb 13, 2020
cb10408
Merge branch 'add-flake8' of https://github.com/earthlab/matplotcheck…
nkorinek Feb 13, 2020
e80cec7
autograde flake8 fixes
nkorinek Feb 13, 2020
df21ddb
Fixed base to be flake8 compliant (phew)
nkorinek Feb 13, 2020
07a74e3
more line length issues
Feb 13, 2020
2c3827b
Made folium.py flake8 compliant
nkorinek Feb 13, 2020
5480112
made notebook.py flake8 compliant
nkorinek Feb 14, 2020
8c26fe7
Fixed raster.py for flake8
nkorinek Feb 14, 2020
5597f2d
Fixed timeseries.py
nkorinek Feb 14, 2020
d255a55
fixed conftest.py
nkorinek Feb 14, 2020
a7b7f80
fixed test_base.py
nkorinek Feb 14, 2020
3c242d1
fixed test_base_axis.py
nkorinek Feb 14, 2020
709aaec
fixed text_base_data.py
nkorinek Feb 14, 2020
d214602
fixed test_base_legends.py
nkorinek Feb 14, 2020
5d551db
fixed test_base_titles_captions.py
nkorinek Feb 14, 2020
dbc354b
Format files to be flake8 acceptable (#197)
nkorinek Feb 14, 2020
9c1d133
Fixed test_raster.py and issue with legends tests
nkorinek Feb 14, 2020
7b3040f
black
nkorinek Feb 14, 2020
61344b0
more black changes
nkorinek Feb 14, 2020
936980a
Merge branch 'add-flake8' of https://github.com/nkorinek/matplotcheck…
Feb 14, 2020
30b4aa1
Merge pull request #7 from earthlab/master
nkorinek Feb 17, 2020
4bd4aa2
Merge branch 'master' of https://github.com/earthlab/matplotcheck
nkorinek Feb 17, 2020
f8dee03
Fixing merge conflicts in the changelog
nkorinek Feb 17, 2020
20a080b
Fixing merge conflicts that were found
nkorinek Feb 17, 2020
e4453bb
Changing accepted changes
nkorinek Feb 17, 2020
5fac436
Merge branch 'add-flake8-fix' of https://github.com/nkorinek/matplotc…
nkorinek Feb 17, 2020
f670b38
minor changes
nkorinek Feb 17, 2020
65ca30c
Changing to make CI happy, modified to pass black and make -B docs
nkorinek Feb 17, 2020
bcdda7f
Merge branch 'add-flake8-fix' of https://github.com/nkorinek/matplotc…
nkorinek Feb 20, 2020
0fb16b4
Reformatting to make black and flake8 happy. Also updated crs assignment
nkorinek Feb 20, 2020
006ac1c
Fixed formatting issue with timeseries
nkorinek Feb 27, 2020
e337686
Better fix for timeseries formatting
nkorinek Feb 27, 2020
165afd6
Black
nkorinek Feb 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ repos:
hooks:
- id: black
language_version: python3.7
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.7
hooks:
- id: flake8
language: python_venv
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.2]
* Adding flake8 for format and other syntax issues! yay! (@lwasser, #195)
* Created a vignette covering the testing of histograms (@ryla5068, #149)
* Created `get_plot_image()` function for the RasterTester object (@nkorinek, #192)
* Allowed `assert_polygons()` to accept GeoDataFrames and added tests (@nkorinek, #175)
Expand Down
7 changes: 4 additions & 3 deletions matplotcheck/autograde.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def run_test(
pass : bool : passing status of test function
description : str : test function name that was run
message : str : custom message returned based on passing status
traceback : AssertionError : returned from test function when pass is False
traceback : AssertionError : returned from test function when pass is
False
"""
results = {"points": 0, "pass": False}
score = 0
try:
fname = func.__name__
results["description"] = fname
Expand Down Expand Up @@ -72,7 +72,8 @@ def output_results(results):
pass : bool : passing status of test function
description : str : test function name that was run
message : str : custom message returned based on passing status
traceback : AssertionError : returned from test function when pass is False
traceback : AssertionError : returned from test function when pass is
False

Returns
-------
Expand Down
119 changes: 64 additions & 55 deletions matplotcheck/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ def assert_string_contains(
Similar to `message_default`, `message_or` is the error message to
be displated if `string` does not contain at least one of
the strings in an inner list in `strings_expected`. If `message`
contains ``'{0}'``, it will be replaced with the first failing inner
list in `strings_expected`.
contains ``'{0}'``, it will be replaced with the first failing
inner list in `strings_expected`.

Raises
-------
AssertionError
if `string` does not contain expected strings
"""
# Assertion passes if strings_expected == [] or strings_expected == None
# Assertion passes if strings_expected == [] or
# strings_expected == None
if not strings_expected:
return

Expand Down Expand Up @@ -149,8 +150,8 @@ def assert_plot_type(
String specifying the expected plot type. Options:
`scatter`, `bar`, `line`
message : string
The error message to be displayed if Plot does not match `plot_type`. If
`message` contains ``'{0}'``, it will be replaced
The error message to be displayed if Plot does not match
`plot_type`. If `message` contains ``'{0}'``, it will be replaced
with the epected plot type.

Raises
Expand Down Expand Up @@ -219,18 +220,19 @@ def assert_title_contains(
assertion.
The combined title will be tested.
message_default : string
The error message to be displayed if the axis label does not contain
a string in strings_expected. If `message` contains ``'{0}'``, it
will be replaced with the first expected string not found in the
label.
The error message to be displayed if the axis label does not
contain a string in strings_expected. If `message` contains
``'{0}'``, it will be replaced with the first expected string not
found in the label.
message_or : string
Similar to `message_default`, `message_or` is the error message to
be displated if the axis label does not contain at least one of
the strings in an inner list in `strings_expected`. If `message`
contains ``'{0}'``, it will be replaced with the first failing inner
list in `strings_expected`.
contains ``'{0}'``, it will be replaced with the first failing
inner list in `strings_expected`.
message_no_title : string
The error message to be displayed if the expected title is not displayed.
The error message to be displayed if the expected title is not
displayed.

Raises
-------
Expand All @@ -246,7 +248,8 @@ def assert_title_contains(
title = axtitle
else:
raise ValueError(
'title_type must be one of the following ["figure", "axes", "either"]'
"title_type must be one of the following "
+ '["figure", "axes", "either"]'
)

assert title, message_no_title
Expand All @@ -268,7 +271,8 @@ def get_caption(self):
Returns
-------
caption : string
the text that is found in bottom right, ``None`` if no text is found
the text that is found in bottom right, ``None`` if no text is
found
"""
caption = None
ax_position = self.ax.get_position()
Expand Down Expand Up @@ -308,16 +312,16 @@ def assert_caption_contains(
``'a'`` AND ``'b'`` AND (at least one of: ``'c'``, ``'d'``) must be
in the title for the assertion to pass. Case insensitive.
message_default : string
The error message to be displayed if the axis label does not contain
a string in strings_expected. If `message` contains ``'{0}'``, it
will be replaced with the first expected string not found in the
label.
The error message to be displayed if the axis label does not
contain a string in strings_expected. If `message` contains
``'{0}'``, it will be replaced with the first expected string
not found in the label.
message_or : string
Similar to `message_default`, `message_or` is the error message to
be displated if the axis label does not contain at least one of
the strings in an inner list in `strings_expected`. If `message`
contains ``'{0}'``, it will be replaced with the first failing inner
list in `strings_expected`.
contains ``'{0}'``, it will be replaced with the first failing
inner list in `strings_expected`.
message_no_caption : string
The error message to be displayed if no caption exists in the
appropriate location.
Expand Down Expand Up @@ -360,12 +364,10 @@ def assert_axis_off(self, message="Axis lines are displayed on plot"):
"""
flag = False
# Case 1: check if axis have been turned off
if self.ax.axison == False:
if not self.ax.axison:
flag = True
# Case 2: Check if both axis visibilities set to false
elif (
self.ax.xaxis._visible == False and self.ax.yaxis._visible == False
):
elif not self.ax.xaxis._visible and not self.ax.yaxis._visible:
flag = True
# Case 3: Check if both axis ticks are set to empty lists
elif (
Expand Down Expand Up @@ -403,18 +405,18 @@ def assert_axis_label_contains(
``'a'`` AND ``'b'`` AND (at least one of: ``'c'``, ``'d'``) must be
in the title for the assertion to pass. Case insensitive.
message_default : string
The error message to be displayed if the axis label does not contain
a string in strings_expected. If `message` contains ``'{1}'``, it
will be replaced with `axis`. If `message` contains ``'{0}'``, it
will be replaced with the first expected string not found in the
label.
The error message to be displayed if the axis label does not
contain a string in strings_expected. If `message` contains
``'{1}'``, it will be replaced with `axis`. If `message` contains
``'{0}'``, it will be replaced with the first expected string not
found in the label.
message_or : string
Similar to `message_default`, `message_or` is the error message to
be displated if the axis label does not contain at least one of
the strings in an inner list in `strings_expected`. If `message`
contains ``'{1}'``, it will be replaced with `axis`. If `message`
contains ``'{0}'``, it will be replaced with the first failing inner
list in `strings_expected`.
contains ``'{0}'``, it will be replaced with the first failing
inner list in `strings_expected`.
message_not_displayed : string
The error message to be displayed if the expected axis label is not
displayed. If `message_not_displayed` contains ``'{0}'``, it will
Expand Down Expand Up @@ -574,7 +576,8 @@ def assert_legend_titles(
self,
titles_exp,
message="Legend title does not contain expected string: {0}",
message_num_titles="I was expecting {0} legend titles but instead found {1}",
message_num_titles="I was expecting {0} legend titles but instead "
+ "found {1}",
):
"""Asserts legend titles contain expected text in titles_exp list.

Expand All @@ -592,8 +595,8 @@ def assert_legend_titles(
The error message to be displayed if there exist a different number
of legend titles than expected. If `message_num_titles` contains
``'{0}'`` it will be replaced with the number of titles found. If
`message_num_titles` contains ``'{1}'`` it will be replaced with the
expected number of titles.
`message_num_titles` contains ``'{1}'`` it will be replaced with
the expected number of titles.

Raises
-------
Expand Down Expand Up @@ -625,7 +628,8 @@ def assert_legend_labels(
labels_exp,
message="Legend does not have expected labels",
message_no_legend="Legend does not exist",
message_num_labels="I was expecting {0} legend entries, but found {1}. Are there extra labels in your legend?",
message_num_labels="I was expecting {0} legend entries, but found "
+ "{1}. Are there extra labels in your legend?",
):
"""Asserts legends on ax have the correct entry labels

Expand All @@ -643,8 +647,8 @@ def assert_legend_labels(
The error message to be displayed if there exist a different number
of legend labels than expected. If `message_num_labels` contains
``'{0}'`` it will be replaced with the number of labels found. If
`message_num_labels` contains ``'{1}'`` it will be replaced with the
expected number of labels.
`message_num_labels` contains ``'{1}'`` it will be replaced with
the expected number of labels.


Raises
Expand Down Expand Up @@ -750,8 +754,8 @@ def assert_no_legend_overlap(self, message="Legends overlap eachother"):
leg_extent2 = (
legends[j].get_window_extent(RendererBase()).get_points()
)
assert (
self.legends_overlap(leg_extent1, leg_extent2) == False
assert not self.legends_overlap(
leg_extent1, leg_extent2
), message

""" BASIC PLOT DATA FUNCTIONS """
Expand All @@ -765,9 +769,11 @@ def get_xy(self, points_only=False, xtime=False):
ax : matplotlib.axes.Axes
Matplotlib Axes object to be tested
points_only : boolean
Set ``True`` to check only points, set ``False`` to check all data on plot.
Set ``True`` to check only points, set ``False`` to check all data
on plot.
xtime : boolean
Set equal to True if the x axis of the plot contains datetime values
Set equal to True if the x axis of the plot contains datetime
values

Returns
-------
Expand Down Expand Up @@ -872,12 +878,13 @@ def assert_xydata(
return
elif not isinstance(xy_expected, pd.DataFrame):
raise ValueError(
"xy_expected must be of type: pandas dataframe or Geopandas Dataframe"
"xy_expected must be of type: pandas dataframe or Geopandas "
+ "Dataframe"
)

# If xy_expected is a GeoDataFrame, then we make is a normal DataFrame
# with the coordinates of the geometry in that GeoDataFrame as the x and
# y data
# with the coordinates of the geometry in that GeoDataFrame as the x
# and y data
if isinstance(xy_expected, gpd.geodataframe.GeoDataFrame) and not xcol:
xy_expected = pd.DataFrame(
data={
Expand Down Expand Up @@ -1018,7 +1025,7 @@ def assert_xlabel_ydata(
except AssertionError:
raise AssertionError(message)

### LINE TESTS/HELPER FUNCTIONS ###
# LINE TESTS/HELPER FUNCTIONS

def get_slope_yintercept(self, path_verts):
"""Returns the y-intercept of line based on the average slope of the
Expand Down Expand Up @@ -1125,21 +1132,22 @@ def assert_lines_of_type(self, line_types):
slope_exp, intercept_exp = 1, 0
else:
raise ValueError(
'each string in line_types must be from the following ["regression","onetoone"]'
"each string in line_types must be from the following "
+ '["regression","onetoone"]'
)

self.assert_line(
slope_exp,
intercept_exp,
message_no_line="{0} line is not displayed properly".format(
message_no_line="{0} line not displayed properly".format(
line_type
),
message_data="{0} line does not cover dataset".format(
line_type
),
)

## HISTOGRAM FUNCTIONS ##
# HISTOGRAM FUNCTIONS

def get_num_bins(self):
"""Gets the number of bins in histogram with a unique x-position.
Expand All @@ -1149,8 +1157,9 @@ def get_num_bins(self):
Int :
Returns the number of bins with a unique x-position. For a normal
histogram, this is just the number of bins. If there are two
overlapping or stacked histograms in the same `matplotlib.axis.Axis`
object, then this returns the number of bins with unique edges. """
overlapping or stacked histograms in the same
`matplotlib.axis.Axis` object, then this returns the number of bins
with unique edges. """
x_data = self.get_xy(xtime=False)["x"]
unique_x_data = list(set(x_data))
num_bins = len(unique_x_data)
Expand All @@ -1170,9 +1179,9 @@ def assert_num_bins(
Number of bins expected.
message : string
The error message to be displayed if plot does not contain
`num_bins`. If `message` contains ``'{0}'`` it will be replaced with
expected number of bins. If `message` contains ``'{1}'``, it will
be replaced with the number of bins found.
`num_bins`. If `message` contains ``'{0}'`` it will be replaced
with expected number of bins. If `message` contains ``'{1}'``, it
will be replaced with the number of bins found.

Raises
-------
Expand Down Expand Up @@ -1210,8 +1219,8 @@ def assert_bin_values(
Parameters
----------
bin_values : list
A list of numbers representing the expected values of each consecutive
bin (i.e. the heights of the bars in the histogram).
A list of numbers representing the expected values of each
consecutive bin (i.e. the heights of the bars in the histogram).
tolerence : float
Measure of relative error allowed.
For example: Given a tolerance ``tolerence=0.1``, an expected value
Expand Down
Loading