Skip to content

Commit a0c6a66

Browse files
committed
adaptive tolerances in tests
1 parent 63aff59 commit a0c6a66

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

probscale/tests/test_probscale.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
from probscale.probscale import _minimal_norm
1515

1616

17-
PYTHON27 = sys.version_info.major == 2
18-
TOLERANCE = 22
17+
PY27 = sys.version_info.major == 2
18+
if PY27:
19+
TOLERANCE = 25
20+
else:
21+
TOLERANCE = 15
1922

2023

2124
@pytest.fixture
@@ -77,7 +80,6 @@ def test_minimal_norm_cdf(mn, mn_input):
7780
baseline_dir='baseline_images/test_probscale',
7881
tolerance=TOLERANCE
7982
)
80-
@pytest.mark.skipif(PYTHON27, reason="legacy python")
8183
def test_the_scale_default():
8284
fig, ax = plt.subplots(figsize=(4, 8))
8385
ax.set_yscale('prob')
@@ -99,7 +101,7 @@ def test_the_scale_not_as_pct():
99101

100102
@pytest.mark.mpl_image_compare(
101103
baseline_dir='baseline_images/test_probscale',
102-
tolerance=13
104+
tolerance=TOLERANCE
103105
)
104106
@pytest.mark.skipif(stats is None, reason="scipy not installed")
105107
def test_the_scale_beta():

probscale/tests/test_viz.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import numpy
55
import matplotlib.pyplot as plt
66

7-
PY2K = sys.version_info.major == 2
8-
if PY2K: # pragma: no cover
7+
PY27 = sys.version_info.major == 2
8+
if PY27: # pragma: no cover
99
import mock
10+
TOLERANCE = 15
1011
else:
1112
from unittest import mock
13+
TOLERANCE = 12
1214
import pytest
1315
import numpy.testing as nptest
1416

@@ -519,23 +521,23 @@ def test__fit_ci(plot_data, fitlogs, known_lo, known_hi):
519521
nptest.assert_allclose(yhat_hi, known_hi, rtol=0.001)
520522

521523

522-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
524+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
523525
def test_probplot_prob(plot_data):
524526
fig, ax = plt.subplots()
525527
fig = viz.probplot(plot_data, ax=ax, problabel='Test xlabel', datascale='log')
526528
assert isinstance(fig, plt.Figure)
527529
return fig
528530

529531

530-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
532+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
531533
def test_probplot_qq(plot_data):
532534
fig, ax = plt.subplots()
533535
fig = viz.probplot(plot_data, ax=ax, plottype='qq', datalabel='Test label',
534536
datascale='log', scatter_kws=dict(color='r'))
535537
return fig
536538

537539

538-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
540+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
539541
@pytest.mark.skipif(stats is None, reason="no scipy")
540542
def test_probplot_qq_dist(plot_data):
541543
fig, ax = plt.subplots()
@@ -545,7 +547,7 @@ def test_probplot_qq_dist(plot_data):
545547
return fig
546548

547549

548-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
550+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
549551
def test_probplot_pp(plot_data):
550552
fig, ax = plt.subplots()
551553
scatter_kws = dict(color='b', linestyle='--', markeredgecolor='g', markerfacecolor='none')
@@ -555,7 +557,7 @@ def test_probplot_pp(plot_data):
555557
return fig
556558

557559

558-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
560+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
559561
def test_probplot_prob_bestfit(plot_data):
560562
fig, ax = plt.subplots()
561563
fig = viz.probplot(plot_data, ax=ax, datalabel='Test xlabel', bestfit=True,
@@ -564,7 +566,7 @@ def test_probplot_prob_bestfit(plot_data):
564566
return fig
565567

566568

567-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
569+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
568570
def test_probplot_qq_bestfit(plot_data):
569571
fig, ax = plt.subplots()
570572
fig = viz.probplot(plot_data, ax=ax, plottype='qq', bestfit=True,
@@ -573,7 +575,7 @@ def test_probplot_qq_bestfit(plot_data):
573575
return fig
574576

575577

576-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
578+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
577579
def test_probplot_pp_bestfit(plot_data):
578580
fig, ax = plt.subplots()
579581
scatter_kws = {'marker': 's', 'color': 'red'}
@@ -585,23 +587,23 @@ def test_probplot_pp_bestfit(plot_data):
585587
return fig
586588

587589

588-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
590+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
589591
def test_probplot_prob_probax_y(plot_data):
590592
fig, ax = plt.subplots()
591593
fig = viz.probplot(plot_data, ax=ax, datalabel='Test xlabel', datascale='log', probax='y')
592594
assert isinstance(fig, plt.Figure)
593595
return fig
594596

595597

596-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
598+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
597599
def test_probplot_qq_probax_y(plot_data):
598600
fig, ax = plt.subplots()
599601
fig = viz.probplot(plot_data, ax=ax, plottype='qq', problabel='Test label', probax='y',
600602
datascale='log', scatter_kws=dict(color='r'))
601603
return fig
602604

603605

604-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
606+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
605607
def test_probplot_pp_probax_y(plot_data):
606608
fig, ax = plt.subplots()
607609
scatter_kws = dict(color='b', linestyle='--', markeredgecolor='g', markerfacecolor='none')
@@ -610,7 +612,7 @@ def test_probplot_pp_probax_y(plot_data):
610612
return fig
611613

612614

613-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
615+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
614616
def test_probplot_prob_bestfit_probax_y(plot_data):
615617
fig, ax = plt.subplots()
616618
fig = viz.probplot(plot_data, ax=ax, datalabel='Test xlabel', bestfit=True,
@@ -619,15 +621,15 @@ def test_probplot_prob_bestfit_probax_y(plot_data):
619621
return fig
620622

621623

622-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
624+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
623625
def test_probplot_qq_bestfit_probax_y(plot_data):
624626
fig, ax = plt.subplots()
625627
fig = viz.probplot(plot_data, ax=ax, plottype='qq', bestfit=True, problabel='Test label',
626628
datascale='log', probax='y', estimate_ci=True)
627629
return fig
628630

629631

630-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
632+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
631633
def test_probplot_pp_bestfit_probax_y(plot_data):
632634
fig, ax = plt.subplots()
633635
scatter_kws = {'marker': 's', 'color': 'red'}
@@ -638,7 +640,7 @@ def test_probplot_pp_bestfit_probax_y(plot_data):
638640
return fig
639641

640642

641-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
643+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
642644
@pytest.mark.skipif(stats is None, reason="no scipy")
643645
def test_probplot_beta_dist_best_fit_y(plot_data):
644646
fig, (ax1, ax2) = plt.subplots(ncols=2)
@@ -656,7 +658,7 @@ def test_probplot_beta_dist_best_fit_y(plot_data):
656658
return fig
657659

658660

659-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
661+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
660662
@pytest.mark.skipif(stats is None, reason="no scipy")
661663
def test_probplot_beta_dist_best_fit_x(plot_data):
662664
fig, (ax1, ax2) = plt.subplots(nrows=2)
@@ -702,7 +704,7 @@ def test__set_prob_limits_x(probax, N, minval, maxval):
702704
ax.set_ylim.assert_called_once_with(bottom=minval, top=maxval)
703705

704706

705-
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=10)
707+
@pytest.mark.mpl_image_compare(baseline_dir=BASELINE_DIR, tolerance=TOLERANCE)
706708
def test_probplot_color_and_label(plot_data):
707709
fig, ax = plt.subplots()
708710
fig = viz.probplot(plot_data, ax=ax, color='pink', label='A Top-Level Label')

0 commit comments

Comments
 (0)