summaryrefslogtreecommitdiff
path: root/gr-utils/modtool/tests/test_modtool.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/modtool/tests/test_modtool.py')
-rw-r--r--gr-utils/modtool/tests/test_modtool.py125
1 files changed, 80 insertions, 45 deletions
diff --git a/gr-utils/modtool/tests/test_modtool.py b/gr-utils/modtool/tests/test_modtool.py
index 37b39f9314..a022275f19 100644
--- a/gr-utils/modtool/tests/test_modtool.py
+++ b/gr-utils/modtool/tests/test_modtool.py
@@ -20,7 +20,7 @@ try:
except:
skip_pylint_test = True
-try: # for debugging, full path must be given
+try: # for debugging, full path must be given
from gnuradio.modtool.core import ModToolNewModule
from gnuradio.modtool.core import ModToolAdd
from gnuradio.modtool.core import ModToolDisable
@@ -35,15 +35,18 @@ except:
from modtool.core import ModToolException
from modtool.core import ModToolMakeYAML
from modtool.core import ModToolRename
- from modtool.core import ModToolRemove
+ from modtool.core import ModToolRemove
+
class TestModToolCore(unittest.TestCase):
""" The tests for the modtool core """
+
def __init__(self, *args, **kwargs):
super(TestModToolCore, self).__init__(*args, **kwargs)
self.f_add = False
self.f_newmod = False
- self.srcdir = path.abspath(path.join(path.dirname(path.realpath(__file__)), '../templates/gr-newmod'))
+ self.srcdir = path.abspath(path.join(path.dirname(
+ path.realpath(__file__)), '../templates/gr-newmod'))
@classmethod
def setUpClass(cls):
@@ -59,7 +62,7 @@ class TestModToolCore(unittest.TestCase):
""" create a new module and block before every test """
try:
warnings.simplefilter("ignore", ResourceWarning)
- args = {'module_name':'howto',
+ args = {'module_name': 'howto',
'directory': self.test_dir,
'srcdir': self.srcdir}
ModToolNewModule(**args).run()
@@ -67,8 +70,8 @@ class TestModToolCore(unittest.TestCase):
self.f_newmod = True
else:
try:
- args = {'blockname':'square_ff', 'block_type':'general',
- 'lang':'cpp', 'directory': self.test_dir + '/gr-howto',
+ args = {'blockname': 'square_ff', 'block_type': 'general',
+ 'lang': 'cpp', 'directory': self.test_dir + '/gr-howto',
'add_python_qa': True}
ModToolAdd(**args).run()
except (TypeError, ModToolException):
@@ -78,7 +81,7 @@ class TestModToolCore(unittest.TestCase):
""" removes the created module """
# Required, else the new-module directory command
# in setup will throw exception after first test
- ## cannot remove if directory is not created
+ # cannot remove if directory is not created
if not self.f_newmod:
rmdir = self.test_dir + '/gr-howto'
shutil.rmtree(rmdir)
@@ -86,8 +89,8 @@ class TestModToolCore(unittest.TestCase):
def test_newmod(self):
""" Tests for the API function newmod """
## Tests for proper exceptions ##
- test_dict = { 'directory': self.test_dir,
- 'srcdir': self.srcdir}
+ test_dict = {'directory': self.test_dir,
+ 'srcdir': self.srcdir}
# module name not specified
self.assertRaises(ModToolException, ModToolNewModule(**test_dict).run)
test_dict['module_name'] = 'howto'
@@ -110,7 +113,7 @@ class TestModToolCore(unittest.TestCase):
self.assertTrue(path.exists(path.join(module_dir, 'CMakeLists.txt')))
## The check for object instantiation ##
- test_obj = ModToolNewModule(srcdir = self.srcdir)
+ test_obj = ModToolNewModule(srcdir=self.srcdir)
# module name not specified
with self.assertRaises(ModToolException) as context_manager:
test_obj.run()
@@ -120,9 +123,10 @@ class TestModToolCore(unittest.TestCase):
self.assertRaises(ModToolException, test_obj.run)
test_obj.info['modname'] = 'test1'
test_obj.run()
- self.assertTrue(path.isdir(self.test_dir+'/gr-test1'))
- self.assertTrue(path.isdir(self.test_dir+'/gr-test1/lib'))
- self.assertTrue(path.exists(self.test_dir+'/gr-test1/CMakeLists.txt'))
+ self.assertTrue(path.isdir(self.test_dir + '/gr-test1'))
+ self.assertTrue(path.isdir(self.test_dir + '/gr-test1/lib'))
+ self.assertTrue(path.exists(
+ self.test_dir + '/gr-test1/CMakeLists.txt'))
@unittest.skipIf(skip_pylint_test, 'pylint dependency missing, skip test')
def test_pylint_newmod(self):
@@ -131,15 +135,17 @@ class TestModToolCore(unittest.TestCase):
## pylint tests ##
python_dir = path.join(module_dir, 'python', 'test')
py_module = path.join(python_dir, 'mul_ff.py')
- (pylint_stdout, pylint_stderr) = py_run(py_module+' --errors-only --disable=E0602', return_std=True)
+ (pylint_stdout, pylint_stderr) = py_run(py_module +
+ ' --errors-only --disable=E0602', return_std=True)
print(pylint_stdout.getvalue(), end='')
py_module = path.join(python_dir, 'qa_mul_ff.py')
- (pylint_stdout, pylint_stderr) = py_run(py_module+' --errors-only', return_std=True)
+ (pylint_stdout, pylint_stderr) = py_run(
+ py_module + ' --errors-only', return_std=True)
print(pylint_stdout.getvalue(), end='')
def test_add(self):
""" Tests for the API function add """
- ## skip tests if newmod command wasn't successful
+ # skip tests if newmod command wasn't successful
if self.f_newmod:
raise unittest.SkipTest("setUp for API function 'add' failed")
module_dir = path.join(self.test_dir, 'gr-howto')
@@ -176,10 +182,14 @@ class TestModToolCore(unittest.TestCase):
## Some tests for checking the created directory, sub-directories and files ##
test_dict['skip_lib'] = False
ModToolAdd(**test_dict).run()
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'qa_add_ff.cc')))
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'add_ff_impl.cc')))
- self.assertTrue(path.exists(path.join(module_dir, 'grc', 'howto_add_ff.block.yml')))
- self.assertTrue(path.exists(path.join(module_dir, 'include', 'gnuradio', 'howto', 'add_ff.h')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'qa_add_ff.cc')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'add_ff_impl.cc')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'grc', 'howto_add_ff.block.yml')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'include', 'gnuradio', 'howto', 'add_ff.h')))
## The check for object instantiation ##
test_obj = ModToolAdd()
@@ -193,14 +203,17 @@ class TestModToolCore(unittest.TestCase):
test_obj.info['blockname'] = 'mul_ff'
test_obj.add_py_qa = True
test_obj.run()
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'mul_ff.py')))
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'qa_mul_ff.py')))
- self.assertTrue(path.exists(path.join(module_dir, 'grc', 'howto_mul_ff.block.yml')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'mul_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'qa_mul_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'grc', 'howto_mul_ff.block.yml')))
@unittest.skipIf(skip_pylint_test, 'pylint dependency missing, skip test')
def test_pylint_add(self):
""" Pylint tests for API function add """
- ## skip tests if newmod command wasn't successful
+ # skip tests if newmod command wasn't successful
if self.f_newmod:
raise unittest.SkipTest("setUp for API function 'add' failed")
module_dir = path.join(self.test_dir, 'gr-howto')
@@ -217,16 +230,20 @@ class TestModToolCore(unittest.TestCase):
test_obj.info['blockname'] = 'mul_ff'
test_obj.add_py_qa = True
test_obj.run()
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'mul_ff.py')))
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'qa_mul_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'mul_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'qa_mul_ff.py')))
## pylint tests ##
python_dir = path.join(module_dir, 'python', 'howto')
py_module = path.join(python_dir, 'mul_ff.py')
- (pylint_stdout, pylint_stderr) = py_run(py_module+' --errors-only --disable=E0602', return_std=True)
+ (pylint_stdout, pylint_stderr) = py_run(py_module +
+ ' --errors-only --disable=E0602', return_std=True)
print(pylint_stdout.getvalue(), end='')
py_module = path.join(python_dir, 'qa_mul_ff.py')
- (pylint_stdout, pylint_stderr) = py_run(py_module+' --errors-only', return_std=True)
+ (pylint_stdout, pylint_stderr) = py_run(
+ py_module + ' --errors-only', return_std=True)
print(pylint_stdout.getvalue(), end='')
def test_rename(self):
@@ -247,7 +264,8 @@ class TestModToolCore(unittest.TestCase):
test_dict['new_name'] = '//#'
# Invalid new block name!
expected_message = "Invalid new block name '//#': names can only contain letters, numbers and underscores"
- self.assertRaisesRegex(ModToolException, expected_message, ModToolRename(**test_dict).run)
+ self.assertRaisesRegex(
+ ModToolException, expected_message, ModToolRename(**test_dict).run)
test_dict['new_name'] = 'non-alpha-chars-like-hyphen-are-not-allowed'
# Invalid new block name!
@@ -260,20 +278,28 @@ class TestModToolCore(unittest.TestCase):
## Some tests for checking the renamed files ##
test_dict['new_name'] = 'div_ff'
ModToolRename(**test_dict).run()
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'div_ff_impl.h')))
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'div_ff_impl.cc')))
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'qa_div_ff.py')))
- self.assertTrue(path.exists(path.join(module_dir, 'grc', 'howto_div_ff.block.yml')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'div_ff_impl.h')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'div_ff_impl.cc')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'qa_div_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'grc', 'howto_div_ff.block.yml')))
## The check for object instantiation ##
test_obj = ModToolRename()
test_obj.info['oldname'] = 'div_ff'
test_obj.info['newname'] = 'sub_ff'
test_obj.run()
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'sub_ff_impl.h')))
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'sub_ff_impl.cc')))
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'qa_sub_ff.py')))
- self.assertTrue(path.exists(path.join(module_dir, 'grc', 'howto_sub_ff.block.yml')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'sub_ff_impl.h')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'sub_ff_impl.cc')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'qa_sub_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'grc', 'howto_sub_ff.block.yml')))
def test_remove(self):
""" Tests for the API function remove """
@@ -289,18 +315,26 @@ class TestModToolCore(unittest.TestCase):
## Some tests to check blocks are not removed with different blocknames ##
test_dict['blockname'] = 'div_ff'
ModToolRemove(**test_dict).run()
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'square_ff_impl.h')))
- self.assertTrue(path.exists(path.join(module_dir, 'lib', 'square_ff_impl.cc')))
- self.assertTrue(path.exists(path.join(module_dir, 'python', 'howto', 'qa_square_ff.py')))
- self.assertTrue(path.exists(path.join(module_dir, 'grc', 'howto_square_ff.block.yml')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'square_ff_impl.h')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'lib', 'square_ff_impl.cc')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'python', 'howto', 'qa_square_ff.py')))
+ self.assertTrue(path.exists(
+ path.join(module_dir, 'grc', 'howto_square_ff.block.yml')))
## Some tests for checking the non-existence of removed files ##
test_dict['blockname'] = 'square_ff'
ModToolRemove(**test_dict).run()
- self.assertTrue(not path.exists(path.join(module_dir, 'lib', 'square_ff_impl.h')))
- self.assertTrue(not path.exists(path.join(module_dir, 'lib', 'square_ff_impl.cc')))
- self.assertTrue(not path.exists(path.join(module_dir, 'python', 'howto', 'qa_square_ff.py')))
- self.assertTrue(not path.exists(path.join(module_dir, 'grc', 'howto_square_ff.block.yml')))
+ self.assertTrue(not path.exists(
+ path.join(module_dir, 'lib', 'square_ff_impl.h')))
+ self.assertTrue(not path.exists(
+ path.join(module_dir, 'lib', 'square_ff_impl.cc')))
+ self.assertTrue(not path.exists(
+ path.join(module_dir, 'python', 'howto', 'qa_square_ff.py')))
+ self.assertTrue(not path.exists(
+ path.join(module_dir, 'grc', 'howto_square_ff.block.yml')))
def test_makeyaml(self):
""" Tests for the API function makeyaml """
@@ -332,5 +366,6 @@ class TestModToolCore(unittest.TestCase):
test_dict['blockname'] = 'square_ff'
ModToolDisable(**test_dict).run()
+
if __name__ == '__main__':
unittest.main()