Browse Source

Framework for testing added.

avkonst 12 years ago
parent
commit
8eb84c0da6
6 changed files with 115 additions and 7 deletions
  1. 1 1
      mainline/collect.py
  2. 13 4
      mainline/core/log.py
  3. 1 1
      mainline/export.py
  4. 1 1
      mainline/limit.py
  5. 64 0
      mainline/test.py
  6. 35 0
      mainline/tests/general/test_collect.py

+ 1 - 1
mainline/collect.py

@@ -29,7 +29,7 @@ import core.cmdparser
 
 def main():
     loader = core.loader.Loader()
-    parser =core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- <path 1> ... <path N>")
+    parser =core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [path 1] ... [path N]")
     args = loader.load(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ext'), parser)
     logging.debug("Registered plugins:")
     logging.debug(loader)

+ 13 - 4
mainline/core/log.py

@@ -19,12 +19,19 @@
 
 import core.api
 import logging
+import os
 
 class Plugin(core.api.Plugin, core.api.IConfigurable):
     
-    def declare_configuration(self, parser):
-        parser.add_option("--general.log-level", default=r'INFO', choices=['DEBUG','INFO','WARNING','ERROR'],
-                         help="Defines log level. Possible values are 'DEBUG','INFO','WARNING' or 'ERROR' [default: %default]")
+    def declare_configuration(self, parser, default_value='INFO'):
+        allowed_values = ['DEBUG','INFO','WARNING','ERROR']
+        default_value_cur = default_value
+        if os.environ.has_key('general.log-level') and os.environ['general.log-level'] in allowed_values:
+            default_value_cur = os.environ['general.log-level']
+        parser.add_option("--general.log-level", default=default_value_cur, choices=allowed_values,
+                         help="Defines log level. Possible values are 'DEBUG','INFO','WARNING' or 'ERROR'. "
+                         "Default value is inherited from environment variable 'general.log-level' if set. "
+                         "Otherwise, it is '" + default_value_cur +  "' [default: %default]")
     
     def configure(self, options):
         if options.__dict__['general.log_level'] == 'ERROR':
@@ -38,7 +45,9 @@ class Plugin(core.api.Plugin, core.api.IConfigurable):
         else:
             raise AssertionError("Unhandled choice of log level")
         
-        logging.getLogger().setLevel(log_level)
+        self.level = log_level
+        logging.getLogger().setLevel(self.level)
+        os.environ['general.log-level'] = options.__dict__['general.log_level']
         logging.warn("Logging enabled with " + options.__dict__['general.log_level'] + " level")
 
 

+ 1 - 1
mainline/export.py

@@ -36,7 +36,7 @@ def main():
     log_plugin = core.log.Plugin()
     db_plugin = core.db.post.Plugin()
 
-    parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- <path 1> ... <path N>")
+    parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [path 1] ... [path N]")
     log_plugin.declare_configuration(parser)
     db_plugin.declare_configuration(parser)
     parser.add_option("--general.format", default='xml', choices=['txt', 'xml', 'python'], help="Format of the output data. "

+ 1 - 1
mainline/limit.py

@@ -37,7 +37,7 @@ def main():
     db_plugin = core.db.post.Plugin()
     warn_plugin = core.warn.Plugin()
 
-    parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- <path 1> ... <path N>")
+    parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [path 1] ... [path N]")
     log_plugin.declare_configuration(parser)
     db_plugin.declare_configuration(parser)
     warn_plugin.declare_configuration(parser)

+ 64 - 0
mainline/test.py

@@ -0,0 +1,64 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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, version 3 of the License.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+import logging
+import time
+import subprocess
+import os.path
+import itertools
+
+import core.log
+import core.cmdparser
+
+def main():
+    exit_code = 0
+    log_plugin = core.log.Plugin()
+
+    parser = core.cmdparser.MultiOptionParser(usage="Usage: %prog [options] -- [testgroup-dir-path-1[/testsuite-file-path-1]] ... [...path-N]")
+    log_plugin.declare_configuration(parser, default_value='ERROR')
+
+    (options, args) = parser.parse_args()
+    log_plugin.configure(options)
+    
+    install_dir = os.path.dirname(os.path.abspath(__file__))
+    tests_dir = os.path.join(install_dir, 'tests')
+    os.environ['METRIXPLUSPLUS_INSTALL_DIR'] = install_dir
+    process_data= ["python", "-m", "unittest", "discover", "-v", "-s"]
+    if len(args) == 0 or tests_dir == os.path.abspath(args[0]):
+        for fname in os.listdir(tests_dir):
+            full_path = os.path.join(tests_dir, fname)
+            if os.path.isdir(full_path):
+                exit_code += subprocess.call(itertools.chain(process_data, [full_path]))
+    else:
+        for arg in args:
+            if os.path.isdir(arg):
+                exit_code += subprocess.call(itertools.chain(process_data, [arg]))
+            else:
+                dir_name = os.path.dirname(arg)
+                file_name = os.path.basename(arg)
+                exit_code += subprocess.call(itertools.chain(process_data, [dir_name, "-p", file_name]))
+    return exit_code
+            
+if __name__ == '__main__':
+    ts = time.time()
+    core.log.set_default_format()
+    exit_code = main()
+    logging.warning("Exit code: " + str(exit_code) + ". Time spent: " + str(round((time.time() - ts), 2)) + " seconds. Done")
+    exit(exit_code) # number of reported messages, errors are reported as non-handled exceptions

+ 35 - 0
mainline/tests/general/test_collect.py

@@ -0,0 +1,35 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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, version 3 of the License.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+import unittest
+import subprocess
+import os.path
+
+class TestGeneralCollect(unittest.TestCase):
+
+    def setUp(self):
+        pass
+
+    def test_default(self):
+        ret_code = subprocess.call(['python', os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'collect.py'), '--help'])
+        self.assertEqual(ret_code, 0)
+
+if __name__ == '__main__':
+    unittest.main()