Skip to content
Prev Previous commit
Next Next commit
Adding some tests for new code coverage
  • Loading branch information
hasanrashid committed Sep 6, 2025
commit 2065fd21afffd43ffcf48b6c69e8ab55037e78d4
63 changes: 63 additions & 0 deletions lib/matplotlib/tests/test_violinplot_datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import pytest

Check warning on line 1 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 `pytest` imported but unused Raw Output: message:"`pytest` imported but unused" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:1 column:8} end:{line:1 column:14}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"F401" url:"https://docs.astral.sh/ruff/rules/unused-import"} suggestions:{range:{start:{line:1 column:1} end:{line:2 column:1}}}
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
import numpy as np

Check warning on line 5 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 `numpy` imported but unused Raw Output: message:"`numpy` imported but unused" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:5 column:17} end:{line:5 column:19}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"F401" url:"https://docs.astral.sh/ruff/rules/unused-import"} suggestions:{range:{start:{line:5 column:1} end:{line:6 column:1}}}

from matplotlib.testing.decorators import image_comparison

Check warning on line 7 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 `matplotlib.testing.decorators.image_comparison` imported but unused Raw Output: message:"`matplotlib.testing.decorators.image_comparison` imported but unused" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:7 column:43} end:{line:7 column:59}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"F401" url:"https://docs.astral.sh/ruff/rules/unused-import"} suggestions:{range:{start:{line:7 column:1} end:{line:8 column:1}}}

def violin_plot_stats():

Check warning on line 9 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:9 column:1} end:{line:9 column:4}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:8 column:1} end:{line:9 column:1}} text:"\n\n"}
# Stats for violin plot
datetimes = [
datetime.datetime(2023, 2, 10),
datetime.datetime(2023, 5, 18),
datetime.datetime(2023, 6, 6)
]
return [{
'coords': datetimes,
'vals': [0.1, 0.5, 0.2],
'mean': datetimes[1],
'median': datetimes[1],
'min': datetimes[0],
'max': datetimes[-1],
'quantiles': datetimes
}, {
'coords': datetimes,
'vals': [0.2, 0.3, 0.4],
'mean': datetimes[2],
'median': datetimes[2],
'min': datetimes[0],
'max': datetimes[-1],
'quantiles': datetimes
}]

def test_violin_datetime_positions_timedelta_widths():

Check warning on line 34 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:34 column:1} end:{line:34 column:4}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:33 column:1} end:{line:34 column:1}} text:"\n\n"}
fig, ax = plt.subplots()
vpstats = violin_plot_stats()
positions = [datetime.datetime(2020, 1, 1), datetime.datetime(2021, 1, 1)]
widths = [datetime.timedelta(days=10), datetime.timedelta(days=20)]
ax.violin(vpstats, positions=positions, widths=widths)
plt.close(fig)

def test_violin_date_positions_float_widths():

Check warning on line 42 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:42 column:1} end:{line:42 column:4}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:41 column:1} end:{line:42 column:1}} text:"\n\n"}
fig, ax = plt.subplots()
vpstats = violin_plot_stats()
positions = [datetime.date(2020, 1, 1), datetime.date(2021, 1, 1)]
widths = [0.5, 1.0]
ax.violin(vpstats, positions=positions, widths=widths)
plt.close(fig)

def test_violin_mixed_positions_widths():

Check warning on line 50 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:50 column:1} end:{line:50 column:4}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:49 column:1} end:{line:50 column:1}} text:"\n\n"}
fig, ax = plt.subplots()
vpstats = violin_plot_stats()
positions = [datetime.datetime(2020, 1, 1), mdates.date2num(datetime.datetime(2021, 1, 1))]

Check warning on line 53 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Line too long (95 > 88) Raw Output: message:"Line too long (95 > 88)" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:53 column:89} end:{line:53 column:96}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E501" url:"https://docs.astral.sh/ruff/rules/line-too-long"}
widths = [datetime.timedelta(days=3), 2.0]
ax.violin(vpstats, positions=positions, widths=widths)
plt.close(fig)

def test_violin_default_positions_widths():

Check warning on line 58 in lib/matplotlib/tests/test_violinplot_datetime.py

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Expected 2 blank lines, found 1 Raw Output: message:"Expected 2 blank lines, found 1" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/tests/test_violinplot_datetime.py" range:{start:{line:58 column:1} end:{line:58 column:4}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"E302" url:"https://docs.astral.sh/ruff/rules/blank-lines-top-level"} suggestions:{range:{start:{line:57 column:1} end:{line:58 column:1}} text:"\n\n"}
fig, ax = plt.subplots()
vpstats = violin_plot_stats()
ax.violin(vpstats)
plt.close(fig)

Loading