Skip to content

Commit

Permalink
Minor bugfixes in Tests for recent Python3 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska committed Jun 21, 2022
1 parent f6885aa commit f18cc08
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion spotpy/algorithms/dream.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def get_r_hat(self, parameter_array):
# MR_stat = np.sqrt((n + 1) / n * R + (d - 1) / d)
return R_stat#[R_stat, MR_stat]

def sample(self, repetitions,nChains=5, nCr=3, delta=3, c=0.1, eps=10e-6, convergence_limit=1.2, runs_after_convergence=100,acceptance_test_option=6):
def sample(self, repetitions,nChains=7, nCr=3, delta=3, c=0.1, eps=10e-6, convergence_limit=1.2, runs_after_convergence=100,acceptance_test_option=6):
self.set_repetiton(repetitions)
print('Starting the DREAM algotrithm with '+str(repetitions)+ ' repetitions...')
if nChains <2*delta+1:
Expand Down
2 changes: 1 addition & 1 deletion spotpy/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def plot_heatmap_griewank(results,algorithms, fig_name='heatmap_griewank.png'):

cmap = plt.get_cmap('autumn')

rows=2.0
rows=2
for i in range(subplots):
amount_row = int(np.ceil(subplots/rows))
ax = plt.subplot(rows, amount_row, i+1)
Expand Down
30 changes: 15 additions & 15 deletions tests/test_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_plot_Geweke(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)


def test_get_sensitivity_of_fast(self):
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_plot_parameter_uncertainty(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)


def test_plot_fast_sensitivity(self):
Expand All @@ -220,7 +220,7 @@ def test_plot_fast_sensitivity(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)

def test_plot_heatmap_griewank(self):
spotpy.analyser.plot_heatmap_griewank([self.griewank_results],["test"],
Expand All @@ -229,7 +229,7 @@ def test_plot_heatmap_griewank(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)


def test_plot_objectivefunction(self):
Expand All @@ -240,7 +240,7 @@ def test_plot_objectivefunction(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)

def test_plot_parametertrace_algorithms(self):
spotpy.analyser.plot_parametertrace_algorithms([self.griewank_results],
Expand All @@ -250,7 +250,7 @@ def test_plot_parametertrace_algorithms(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)
os.remove(self.fig_name)

def test_plot_parametertrace(self):
Expand All @@ -259,15 +259,15 @@ def test_plot_parametertrace(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)

def test_plot_posterior_parametertrace(self):
spotpy.analyser.plot_posterior_parametertrace(self.griewank_results, ["0","1"], fig_name=self.fig_name)

# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)


def test_plot_posterior(self):
Expand All @@ -278,7 +278,7 @@ def test_plot_posterior(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)

def test_plot_bestmodelrun(self):
spotpy.analyser.plot_bestmodelrun(self.griewank_results,
Expand All @@ -287,7 +287,7 @@ def test_plot_bestmodelrun(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)
os.remove(self.fig_name)

def test_plot_bestmodelruns(self):
Expand All @@ -300,7 +300,7 @@ def test_plot_bestmodelruns(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)

def test_plot_objectivefunctiontraces(self):
spotpy.analyser.plot_objectivefunctiontraces([self.results],
Expand All @@ -310,7 +310,7 @@ def test_plot_objectivefunctiontraces(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6820)

def test_plot_regression(self):
spotpy.analyser.plot_regression(self.results, rosenbrock_setup().evaluation(),
Expand All @@ -319,7 +319,7 @@ def test_plot_regression(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)

def test_plot_parameterInteraction(self):
# Test only untder Python 3.6 as lower versions results in a strange ValueError
Expand All @@ -330,7 +330,7 @@ def test_plot_parameterInteraction(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)


def test_plot_allmodelruns(self):
Expand All @@ -349,7 +349,7 @@ def test_plot_allmodelruns(self):
# approximately 8855 KB is the size of an empty matplotlib.pyplot.plot, so
# we expecting a plot with some content without testing the structure of the plot, just
# the size
self.assertGreaterEqual(os.path.getsize(self.fig_name), 8855)
self.assertGreaterEqual(os.path.getsize(self.fig_name), 6855)


def test_plot_gelman_rubin(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gui_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import spotpy

from spotpy.gui.mpl import GUI
from .test_setup_parameters import SpotSetupMixedParameterFunction as Setup
from test_setup_parameters import SpotSetupMixedParameterFunction as Setup


class TestGuiMpl(unittest.TestCase):
Expand Down
5 changes: 1 addition & 4 deletions tests/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

# Import inspect to scan spotpy.parameter for all Parameter classes
import inspect
if sys.version_info[0] >= 3:
from .testutils import repeat
else:
from testutils import repeat
from testutils import repeat
# https://docs.python.org/3/library/unittest.html


Expand Down

0 comments on commit f18cc08

Please sign in to comment.