From 3abc3d2dfa9cbbd9e3655255bfbe140d52ccfc75 Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 21 2017 13:30:02 +0000 Subject: [PATCH 1/3] remove deprecated generator func --- diff --git a/moduleframework/generator.py b/moduleframework/generator.py deleted file mode 100755 index 8de5006..0000000 --- a/moduleframework/generator.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# This Modularity Testing Framework helps you to write tests for modules -# Copyright (C) 2017 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# he Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program 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 this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Authors: Jan Scotka -# - -from __future__ import print_function - -from moduleframework.module_framework import CommonFunctions - - -class TestGenerator(CommonFunctions): - - def __init__(self): - self.loadconfig() - self.output = "" - self.templateClassBefore() - if 'test' in self.config: - for testname in self.config['test']: - self.templateTest(testname, self.config['test'][testname]) - if 'testhost' in self.config: - for testname in self.config['testhost']: - self.templateTest( - testname, - self.config['testhost'][testname], - method="runHost") - - def templateClassBefore(self): - self.output = """#!/usr/bin/python - -import socket -from avocado import main -from moduleframework import module_framework - -if __name__ == '__main__': - main() - -class GeneratedTestsConfig(module_framework.AvocadoTest): - \"\"\" - :avocado: enable - \"\"\" -""" - - def templateTest(self, testname, testlines, method="run"): - self.output = self.output + """ - def test_%s(self): - self.start() -""" % testname - for line in testlines: - # only use shell=True for runHost() calls, otherwise variables etc. - # get expanded too early, i.e. on the host - self.output = self.output + \ - ' self.%s(""" %s """, shell=%r)\n' % ( - method, line, method == "runHost") - print("Added test (runmethod: %s): %s" % (method, testname)) - - -def main(): - config = TestGenerator() - configout = open('generated.py', 'w') - configout.write(config.output) - configout.close() - - -def deprecated_main(): - import sys - print("The 'generator' name is deprecated and will go away eventually, " - "please use\n'mtf-generator' instead!", file=sys.stderr) - main() - - -if __name__ == '__main__': - main() diff --git a/moduleframework/mtf_generator.py b/moduleframework/mtf_generator.py new file mode 100755 index 0000000..f1d3196 --- /dev/null +++ b/moduleframework/mtf_generator.py @@ -0,0 +1,82 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# This Modularity Testing Framework helps you to write tests for modules +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# he Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Authors: Jan Scotka +# + +from __future__ import print_function + +from moduleframework.module_framework import CommonFunctions + + +class TestGenerator(CommonFunctions): + + def __init__(self): + self.loadconfig() + self.output = "" + self.templateClassBefore() + if 'test' in self.config: + for testname in self.config['test']: + self.templateTest(testname, self.config['test'][testname]) + if 'testhost' in self.config: + for testname in self.config['testhost']: + self.templateTest( + testname, + self.config['testhost'][testname], + method="runHost") + + def templateClassBefore(self): + self.output = """#!/usr/bin/python + +import socket +from avocado import main +from moduleframework import module_framework + +if __name__ == '__main__': + main() + +class GeneratedTestsConfig(module_framework.AvocadoTest): + \"\"\" + :avocado: enable + \"\"\" +""" + + def templateTest(self, testname, testlines, method="run"): + self.output = self.output + """ + def test_%s(self): + self.start() +""" % testname + for line in testlines: + # only use shell=True for runHost() calls, otherwise variables etc. + # get expanded too early, i.e. on the host + self.output = self.output + \ + ' self.%s(""" %s """, shell=%r)\n' % ( + method, line, method == "runHost") + print("Added test (runmethod: %s): %s" % (method, testname)) + + +def main(): + config = TestGenerator() + configout = open('generated.py', 'w') + configout.write(config.output) + configout.close() + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 1542f99..3371964 100755 --- a/setup.py +++ b/setup.py @@ -77,8 +77,7 @@ setup( 'console_scripts': [ 'moduleframework-cmd = moduleframework.bashhelper:main', 'modulelint = moduleframework.modulelint:main', - 'mtf-generator = moduleframework.generator:main', - 'generator = moduleframework.generator:deprecated_main', + 'mtf-generator = moduleframework.mtf_generator:main', ] }, setup_requires=[], From 4596c78d052640df32774a819736d0b57bee37e8 Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 21 2017 13:30:23 +0000 Subject: [PATCH 2/3] docs replacing generator with mtf-generator --- diff --git a/docs/api/generator.rst b/docs/api/generator.rst deleted file mode 100644 index 1e5e1f2..0000000 --- a/docs/api/generator.rst +++ /dev/null @@ -1,6 +0,0 @@ -MTF Generator -============= - -.. automodule:: moduleframework.generator - :members: - :undoc-members: diff --git a/docs/api/index.rst b/docs/api/index.rst index f795c6b..6886dc8 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -9,7 +9,7 @@ This section contains the MTF API, auto generated from `the source code`_. module_framework exceptions_debug - generator + mtf_generator compose_info pdc_data dockerlinter diff --git a/docs/api/mtf_generator.rst b/docs/api/mtf_generator.rst new file mode 100644 index 0000000..36efd64 --- /dev/null +++ b/docs/api/mtf_generator.rst @@ -0,0 +1,6 @@ +MTF Generator +============= + +.. automodule:: moduleframework.mtf_generator + :members: + :undoc-members: diff --git a/docs/user_guide/index.rst b/docs/user_guide/index.rst index 5ac4e31..96c0dac 100644 --- a/docs/user_guide/index.rst +++ b/docs/user_guide/index.rst @@ -18,7 +18,9 @@ User Guide .. _sanity tests: https://pagure.io/modularity-testing-framework/blob/master/f/examples/template/sanity_template.py .. _API Index: ../api/index -5. In the directory ``tests`` create a ``Makefile`` as below. Mind to keep the ``generator`` line only if there are multiline Bash snippet tests in the ``tests/config.yaml`` file. +5. In the directory ``tests`` create a ``Makefile`` as below. + + Mind to keep the ``mtf_generator`` line only if there are multiline Bash snippet tests in the ``tests/config.yaml`` file. .. code-block:: makefile @@ -27,7 +29,7 @@ User Guide # all: - generator + mtf_generator $(CMD) 6. In a module's root directory create a ``Makefile``, which contains a secton **test**. For example: From 9df813d096c5c46675d0cebd31e4f3bb4451d6cd Mon Sep 17 00:00:00 2001 From: Irina Gulina Date: Jun 21 2017 13:30:23 +0000 Subject: [PATCH 3/3] fix issue 36 --- diff --git a/docs/user_guide/index.rst b/docs/user_guide/index.rst index 96c0dac..1f09098 100644 --- a/docs/user_guide/index.rst +++ b/docs/user_guide/index.rst @@ -20,7 +20,7 @@ User Guide 5. In the directory ``tests`` create a ``Makefile`` as below. - Mind to keep the ``mtf_generator`` line only if there are multiline Bash snippet tests in the ``tests/config.yaml`` file. + Mind to keep the ``mtf-generator`` line only if there are multiline Bash snippet tests in the ``tests/config.yaml`` file. The ``mtf-generator`` command will convert those multiline Bash snippet tests from the ``tests/config.yaml`` file into Python tests and stores them in the ``tests/generated.py`` file, which will be processed further by avocado. .. code-block:: makefile @@ -29,7 +29,7 @@ User Guide # all: - mtf_generator + mtf-generator $(CMD) 6. In a module's root directory create a ``Makefile``, which contains a secton **test**. For example: