New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset python helper functions to make them work again #766
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5398d3f
Added regressiontests for python verbosity- and stack checker-functions
hakonsbm 1e81e28
Reset python helper functions to their working order
hakonsbm 8455cc6
Fixed copyright issue
hakonsbm 7b094cb
Fixed deprecated string replacement
hakonsbm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# test_helper_functions.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 <http://www.gnu.org/licenses/>. | ||
|
||
import unittest | ||
import nest | ||
|
||
|
||
class TestHelperFunctions(unittest.TestCase): | ||
|
||
def test_get_verbosity(self): | ||
verbosity = nest.get_verbosity() | ||
self.assertTrue(isinstance(verbosity, int)) | ||
|
||
def test_set_verbosity(self): | ||
levels = [('M_ALL', 0), | ||
('M_DEBUG', 5), | ||
('M_STATUS', 7), | ||
('M_INFO', 10), | ||
('M_DEPRECATED', 18), | ||
('M_WARNING', 20), | ||
('M_ERROR', 30), | ||
('M_FATAL', 40), | ||
('M_QUIET', 100) | ||
] | ||
for level, code in levels: | ||
nest.set_verbosity(level) | ||
verbosity = nest.get_verbosity() | ||
self.assertEqual(verbosity, code) | ||
|
||
def test_stack_checker(self): | ||
def empty_stack(): | ||
nest.sli_run('clear') | ||
|
||
def leave_on_stack(): | ||
nest.sli_push(1) | ||
|
||
check_empty_stack = nest.stack_checker(empty_stack) | ||
check_leave_on_stack = nest.stack_checker(leave_on_stack) | ||
|
||
debug = nest.get_debug() | ||
# We have to set debug to True to check the stack | ||
nest.set_debug(True) | ||
|
||
# This should pass without errors | ||
check_empty_stack() | ||
|
||
try: | ||
self.assertRaises(nest.NESTError, check_leave_on_stack) | ||
except: # Ensure that debug is reset if we get an error. | ||
nest.set_debug(debug) | ||
raise | ||
nest.set_debug(debug) | ||
|
||
|
||
def suite(): | ||
suite = unittest.makeSuite(TestHelperFunctions, 'test') | ||
return suite | ||
|
||
|
||
if __name__ == "__main__": | ||
runner = unittest.TextTestRunner(verbosity=2) | ||
runner.run(suite()) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%
string substitution is deprecated in Py3. Rather use'{} setverbosity'.format(level)