From 1218a2876d06a9a162e67348ed61f6f3933d5b07 Mon Sep 17 00:00:00 2001 From: Nicolai Haug Date: Thu, 25 May 2023 00:40:41 +0200 Subject: [PATCH 1/3] Port issue-1305.sli to pytest --- .../sli2py_regressions/test_issue_1305.py | 55 ++++++++++++++++ testsuite/regressiontests/issue-1305.sli | 63 ------------------- 2 files changed, 55 insertions(+), 63 deletions(-) create mode 100644 testsuite/pytests/sli2py_regressions/test_issue_1305.py delete mode 100644 testsuite/regressiontests/issue-1305.sli diff --git a/testsuite/pytests/sli2py_regressions/test_issue_1305.py b/testsuite/pytests/sli2py_regressions/test_issue_1305.py new file mode 100644 index 0000000000..a0f2872d77 --- /dev/null +++ b/testsuite/pytests/sli2py_regressions/test_issue_1305.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# +# test_issue_1305.py +# +# This file is part of NEST. +# +# Copyright (C) 2004 The NEST Initiative +# +# NEST is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# NEST is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with NEST. If not, see . + +""" +Regression test for Issue #1305 (GitHub). + +This set of tests ensures that NEST hcan set small resolutions and deals with +rounding errors correctly. +""" + +import pytest + +import nest + + +@pytest.fixture(autouse=True) +def reset(): + nest.ResetKernel() + + +def test_resolution_rounding_valid(): + """Test setting valid resolution.""" + + target_resolution = 0.102 + nest.set(resolution=target_resolution, tics_per_ms=1000.0) + + abs_diff = abs(nest.resolution - target_resolution) + assert abs_diff < 1e-15 + + +def test_resolution_rounding_invalid(): + """Test setting invalid resolution.""" + + target_resolution = 0.1002 + + with pytest.raises(nest.kernel.NESTError): + nest.set(resolution=target_resolution, tics_per_ms=1000.0) diff --git a/testsuite/regressiontests/issue-1305.sli b/testsuite/regressiontests/issue-1305.sli deleted file mode 100644 index 48977335b1..0000000000 --- a/testsuite/regressiontests/issue-1305.sli +++ /dev/null @@ -1,63 +0,0 @@ -/* - * issue-1305.sli - * - * This file is part of NEST. - * - * Copyright (C) 2004 The NEST Initiative - * - * NEST is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * NEST is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NEST. If not, see . - * - */ - -/** @BeginDocumentation - -Name: testsuite::issue-1305 Ensure that small simulation timesteps can be set without errors. - -Synopsis: (issue-1305) run -> NEST exits if test fails - -Description: -This ticket ensures that NEST can set small resolutions and deals with rounding errors correctly. - -Author: Philipp Weidel, 2019-12-06 based on material by Hans E Plesser, Jafet Diaz -*/ - -(unittest) run -/unittest using - -M_ERROR setverbosity - -% Test setting valid resolution -{ - /target_resolution 0.102 def - - ResetKernel - << /resolution target_resolution /tics_per_ms 1000.0 >> SetKernelStatus - GetKernelStatus /resolution get - target_resolution - sub abs - 1e-15 leq -} assert_or_die - -% Test setting invalid resolution -{ - /target_resolution 0.1002 def - - ResetKernel - 0 << /resolution target_resolution /tics_per_ms 1000.0 >> SetStatus - 0 /resolution get - target_resolution - sub abs - 1e-15 leq -} fail_or_die - From e98e89113591102a95488051ef972bf8e5421220 Mon Sep 17 00:00:00 2001 From: Nicolai Haug <39106781+nicolossus@users.noreply.github.com> Date: Mon, 3 Jul 2023 20:51:42 +0200 Subject: [PATCH 2/3] Fix typo Co-authored-by: janskaar --- testsuite/pytests/sli2py_regressions/test_issue_1305.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/pytests/sli2py_regressions/test_issue_1305.py b/testsuite/pytests/sli2py_regressions/test_issue_1305.py index a0f2872d77..b762cec0d3 100644 --- a/testsuite/pytests/sli2py_regressions/test_issue_1305.py +++ b/testsuite/pytests/sli2py_regressions/test_issue_1305.py @@ -22,7 +22,7 @@ """ Regression test for Issue #1305 (GitHub). -This set of tests ensures that NEST hcan set small resolutions and deals with +This set of tests ensures that NEST can set small resolutions and deals with rounding errors correctly. """ From 32f111fcd83991a2297ca3323519bf1e77a7873b Mon Sep 17 00:00:00 2001 From: Nicolai Haug Date: Tue, 8 Aug 2023 11:46:06 +0200 Subject: [PATCH 3/3] Assert with pytest approx --- testsuite/pytests/sli2py_regressions/test_issue_1305.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testsuite/pytests/sli2py_regressions/test_issue_1305.py b/testsuite/pytests/sli2py_regressions/test_issue_1305.py index b762cec0d3..c5e894dfeb 100644 --- a/testsuite/pytests/sli2py_regressions/test_issue_1305.py +++ b/testsuite/pytests/sli2py_regressions/test_issue_1305.py @@ -42,8 +42,7 @@ def test_resolution_rounding_valid(): target_resolution = 0.102 nest.set(resolution=target_resolution, tics_per_ms=1000.0) - abs_diff = abs(nest.resolution - target_resolution) - assert abs_diff < 1e-15 + assert nest.resolution == pytest.approx(target_resolution) def test_resolution_rounding_invalid():