Skip to content
Snippets Groups Projects
Commit ca024fd0 authored by Florstedt, Julius's avatar Florstedt, Julius
Browse files

Merge branch 'main' into '29-confidential-issue'

# Conflicts:
#   plot_serializer/matplotlib/serializer.py
parents 671e753c d20de117
Branches 29-confidential-issue
Tags
3 merge requests!41Resolve "Refactor/Documentation?",!39Resolve "Refactor/Documentation",!37Resolve "Refactor/Documentation"
Pipeline #1624139 failed
Showing
with 575 additions and 1 deletion
......@@ -11,6 +11,7 @@ __pycache__
!/.gitlab
!/.vscode
!/tests
!/tests_automatic
!/plot_serializer
!/doc
......
......@@ -181,3 +181,10 @@ pytest tests --update-tests=confirm
The first type of files created being all the tests accomodating the new model under the tests_updated folder. They have to be manually checked for correctness and then moved into the initial [plots](./tests/plots) folder.
The second being the new model under [specification](./doc/static/specification) where it will have to be renamed according to the current version of PlotSerializer to be pushed.
The third being pictures of every plottype deserialized into a figure to broadly confirm the deserializer is still functioning. Once again the contents must me renamed and replace the old files in [folder](./tests/deserializer_matrix) upon confirming correctness.
Besides the manual tests comparing generated JSON files to the expected result there are automatic tests checking if errors are thrown for automatically generated input arguments and testing if the returned JSON is empty. So far these tests mostly only support the main parameters of the functions and only some keyword parameters.
It is recommended to run the test for the specific plot under scrutiny, not the entire testfolder via pytest as the . An example for boxplot:
```cmd
pytest tests_automatic test_box_automatic.py
```
\ No newline at end of file
......@@ -22,6 +22,7 @@ types-docutils
# Unit testing
pytest
hypothesis
#Debug
debugpy
\ No newline at end of file
......@@ -109,6 +109,9 @@ def test_hist_plot(
update_tests = request.config.getoption("--update-tests")
_, ax = serializer.subplots()
if bins is None and cumulative is None and density is None:
# giving arguments the none value throws errors, might need a test overhaul overall
ax.hist(x)
ax.hist(
x,
bins=bins,
......@@ -126,7 +129,7 @@ def test_hist_plot(
ax.set_ylabel(ylabel)
if metadata:
ax.hist(x, bins=bins, color=color, label=label, cumulative=cumulative, density=density)
ax.hist(x)
serializer.add_custom_metadata_figure(metadata)
serializer.add_custom_metadata_plot(metadata, plot_selector=0)
serializer.add_custom_metadata_axis(metadata, axis="y", plot_selector=0)
......
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.integers(),
st.floats(),
st.text(),
st.lists(st.text()),
st.lists(st.integers()),
st.lists(st.floats()),
arrays(np.int64, st.integers(min_value=0, max_value=10)),
arrays(np.float64, st.integers(min_value=0, max_value=10)),
)
heights_strategy = st.one_of(
st.integers(),
st.floats(),
st.lists(st.integers()),
st.lists(st.floats()),
arrays(np.int64, st.integers(min_value=0, max_value=10)),
arrays(np.float64, st.integers(min_value=0, max_value=10)),
)
@given(x=x_strategy, heights=heights_strategy)
def test_bar_properties(
x: Any,
heights: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.bar(x, heights)
except Exception as _e:
pass
else:
serializer_ax.bar(x, heights)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given, settings
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.lists(st.lists(st.floats(), min_size=1), min_size=1),
st.lists(arrays(np.float64, st.integers(min_value=1, max_value=10)), min_size=1),
arrays(np.float64, st.integers(min_value=1, max_value=10)),
arrays(np.int64, st.integers(min_value=1, max_value=10)),
)
notch_strategy = st.one_of(st.none(), st.booleans())
whis_strategy = st.one_of(
st.none(),
st.floats(),
st.tuples(st.floats(), st.floats()),
)
bootstrap_strategy = st.one_of(st.none(), st.integers(min_value=0))
usermedians_strategy = st.one_of(
st.none(),
st.lists(st.one_of(st.floats(), st.none()), min_size=1),
arrays(np.float64, st.integers(min_value=1, max_value=10)),
)
conf_intervals_strategy = st.one_of(
st.none(),
st.lists(
st.tuples(
st.one_of(st.floats(), st.none()),
st.one_of(st.floats(), st.none()),
),
min_size=1,
),
arrays(np.float64, st.integers(min_value=1, max_value=10)),
)
tick_labels_strategy = st.one_of(st.none(), st.lists(st.text(), min_size=1))
@given(
x=x_strategy,
notch=notch_strategy,
whis=whis_strategy,
bootstrap=bootstrap_strategy,
usermedians=usermedians_strategy,
conf_intervals=conf_intervals_strategy,
tick_labels=tick_labels_strategy,
)
@settings(deadline=500)
def test_box_properties(
x: Any,
notch: Any,
whis: Any,
bootstrap: Any,
usermedians: Any,
conf_intervals: Any,
tick_labels: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.boxplot(
x=x,
notch=notch,
whis=whis,
bootstrap=bootstrap,
usermedians=usermedians,
conf_intervals=conf_intervals,
tick_labels=tick_labels,
)
except Exception as _e:
pass
else:
serializer_ax.boxplot(
x=x,
notch=notch,
whis=whis,
bootstrap=bootstrap,
usermedians=usermedians,
conf_intervals=conf_intervals,
tick_labels=tick_labels,
)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(np.float64, shape=st.integers(min_value=1, max_value=10)),
)
y_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(np.float64, shape=st.integers(min_value=1, max_value=10)),
)
xerr_strategy = st.one_of(
st.none(),
st.floats(min_value=0, allow_nan=False, allow_infinity=False),
st.lists(st.floats(min_value=0, allow_nan=False, allow_infinity=False), min_size=1),
arrays(np.float64, shape=st.integers(min_value=1, max_value=10)),
arrays(np.float64, shape=st.tuples(st.just(2), st.integers(min_value=1, max_value=10))),
)
yerr_strategy = st.one_of(
st.none(),
st.floats(min_value=0, allow_nan=False, allow_infinity=False),
st.lists(st.floats(min_value=0, allow_nan=False, allow_infinity=False), min_size=1),
arrays(np.float64, shape=st.integers(min_value=1, max_value=10)),
arrays(np.float64, shape=st.tuples(st.just(2), st.integers(min_value=1, max_value=10))),
)
marker_strategy = st.one_of(st.none(), st.text())
label_strategy = st.one_of(st.none(), st.text())
@given(x=x_strategy, y=y_strategy, xerr=xerr_strategy, yerr=yerr_strategy, marker=marker_strategy, label=label_strategy)
def test_bar_properties(
x: Any,
y: Any,
xerr: Any,
yerr: Any,
marker: Any,
label: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.errorbar(x, y, xerr=xerr, yerr=yerr, marker=marker, label=label)
except Exception as _e:
pass
else:
serializer_ax.errorbar(x, y, xerr=xerr, yerr=yerr, marker=marker, label=label)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
st.lists(st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1), min_size=1),
st.lists(arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)), min_size=1),
arrays(
dtype=np.float64,
shape=st.tuples(st.integers(min_value=1, max_value=10), st.integers(min_value=1, max_value=10)),
),
)
bins_strategy = st.one_of(
st.integers(min_value=1, max_value=50),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=50)),
)
density_strategy = st.booleans()
cumulative_strategy = st.one_of(st.booleans(), st.just(-1))
label_strategy = st.one_of(st.none(), st.text())
@given(
x=x_strategy, bins=bins_strategy, label=label_strategy, densitiy=density_strategy, culumative=cumulative_strategy
)
def test_hist_properties(
x: Any,
bins: Any,
label: Any,
densitiy: Any,
culumative: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.hist(x, bins=bins, label=label, density=densitiy, cumulative=culumative)
except Exception as _e:
pass
else:
serializer_ax.hist(x, bins=bins, label=label, density=densitiy, cumulative=culumative)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
y_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
z_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
label_strategy = st.one_of(st.none(), st.text())
linewidth_strategy = st.one_of(st.floats(allow_nan=False, allow_infinity=False), st.integers())
@given(x=x_strategy, y=y_strategy, z=z_strategy, label=label_strategy, linewidth=linewidth_strategy)
def test_line_properties(
x: Any,
y: Any,
z: Any,
label: Any,
linewidth: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.plot(x, y, z, label=label, linewidth=linewidth)
except Exception as _e:
pass
else:
serializer_ax.plot(x, y, z, label=label, linewidth=linewidth)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
y_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
label_strategy = st.one_of(st.none(), st.text())
linewidth_strategy = st.one_of(st.floats(allow_nan=False, allow_infinity=False), st.integers())
@given(x=x_strategy, y=y_strategy, label=label_strategy, linewidth=linewidth_strategy)
def test_line_properties(
x: Any,
y: Any,
label: Any,
linewidth: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.plot(x, y, label=label, linewidth=linewidth)
except Exception as _e:
pass
else:
serializer_ax.plot(x, y, label=label, linewidth=linewidth)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
explode_strategy = st.one_of(
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
st.none(),
)
radius_strategy = st.floats(allow_nan=False, allow_infinity=False)
labels_strategy = st.one_of(st.lists(st.text(), min_size=1), st.none())
@given(x=x_strategy, explode=explode_strategy, labels=labels_strategy, radius=radius_strategy)
def test_pie_properties(
x: Any,
explode: Any,
labels: Any,
radius: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.pie(x, explode=explode, labels=labels, radius=radius)
except Exception as _e:
pass
else:
serializer_ax.pie(x, explode=explode, labels=labels, radius=radius)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
y_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
z_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
s_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
label_strategy = st.one_of(st.none(), st.text())
@given(x=x_strategy, y=y_strategy, z=z_strategy, s=s_strategy, label=label_strategy)
def test_scatter3d_properties(
x: Any,
y: Any,
z: Any,
s: Any,
label: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots(subplot_kw={"projection": "3d"})
_fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
try:
ax.scatter(x, y, z, s=s, label=label) # type: ignore
except Exception as _e:
pass
else:
serializer_ax.scatter(x, y, z, s=s, label=label)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
x_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
y_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
s_strategy = st.one_of(
st.floats(allow_nan=False, allow_infinity=False),
st.lists(st.floats(allow_nan=False, allow_infinity=False), min_size=1),
arrays(dtype=np.float64, shape=st.integers(min_value=1, max_value=10)),
)
label_strategy = st.one_of(st.none(), st.text())
@given(x=x_strategy, y=y_strategy, s=s_strategy, label=label_strategy)
def test_scatter_properties(
x: Any,
y: Any,
s: Any,
label: Any,
) -> None:
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots()
_fig, ax = plt.subplots()
try:
ax.scatter(x, y, s=s, label=label)
except Exception as _e:
pass
else:
serializer_ax.scatter(x, y, s=s, label=label)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
from typing import Any
import numpy as np
from hypothesis import given
from hypothesis import strategies as st
from hypothesis.extra.numpy import arrays
from matplotlib import pyplot as plt
from plot_serializer.matplotlib.serializer import MatplotlibSerializer
@st.composite
def matrix_triplet_strategy(draw, min_dim=1, max_dim=10, min_value=0, max_value=100): # type: ignore
rows = draw(st.integers(min_value=min_dim, max_value=max_dim))
cols = draw(st.integers(min_value=min_dim, max_value=max_dim))
matrix_strategy = st.one_of(
st.lists(
st.lists(st.integers(min_value=min_value, max_value=max_value), min_size=cols, max_size=cols),
min_size=rows,
max_size=rows,
),
arrays(dtype=np.int64, shape=(rows, cols)),
)
matrix1 = draw(matrix_strategy)
matrix2 = draw(matrix_strategy)
matrix3 = draw(matrix_strategy)
return matrix1, matrix2, matrix3
@given(matrix_triplet_strategy())
def test_surface_properties(
matrix_triplet: Any,
) -> None:
x, y, z = matrix_triplet
serializer = MatplotlibSerializer()
_, serializer_ax = serializer.subplots(subplot_kw={"projection": "3d"})
_fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
try:
ax.plot_surface(x, y, z) # type: ignore
except Exception as _e:
pass
else:
serializer_ax.plot_surface(x, y, z)
assert serializer.to_json() != "{}", "Serialized JSON is empty check input"
finally:
plt.close(_)
plt.close(_fig)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment