"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/test_suite/formatting.py" (5 Dec 2019, 5367 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "formatting.py": 4.1.3_vs_5.0.0.

    1 ###############################################################################
    2 #                                                                             #
    3 # Copyright (C) 2007,2011-2012,2019 Edward d'Auvergne                         #
    4 #                                                                             #
    5 # This file is part of the program relax (http://www.nmr-relax.com).          #
    6 #                                                                             #
    7 # This program is free software: you can redistribute it and/or modify        #
    8 # it under the terms of the GNU General Public License as published by        #
    9 # the Free Software Foundation, either version 3 of the License, or           #
   10 # (at your option) any later version.                                         #
   11 #                                                                             #
   12 # This program is distributed in the hope that it will be useful,             #
   13 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   15 # GNU General Public License for more details.                                #
   16 #                                                                             #
   17 # You should have received a copy of the GNU General Public License           #
   18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   19 #                                                                             #
   20 ###############################################################################
   21 
   22 # Python module imports.
   23 import sys
   24 from textwrap import wrap
   25 
   26 
   27 def divider(char, width=100):
   28     """Write out a divider of the given width.
   29 
   30     @param char:    The character to use for the divider.
   31     @type char:     str
   32     @keyword width: The number of characters to use.
   33     @type width:    int
   34     """
   35 
   36     # Write out the divider.
   37     sys.stdout.write(char*width)
   38     sys.stdout.write("\n")
   39 
   40 
   41 def format_test_name(test_name, category=None):
   42     """Generate the compact string representation of the test name.
   43 
   44     @param test_name:   The original TestCase name.
   45     @type test_name:    str
   46     @keyword category:  The test category, one of 'system', 'unit', 'gui', or 'verification'.
   47     @type category:     str
   48     """
   49 
   50     # Change the test name for all but unit tests.
   51     if category != 'unit':
   52         test_name = test_name.split('.')
   53         test_name = "%s.%s" % (test_name[-2], test_name[-1])
   54 
   55     # Handle errors.
   56     elif search('Error', test_name):
   57         pass
   58 
   59     # Modify the unit test name.
   60     else:
   61         # Strip out the leading 'test_suite.unit_tests.' text.
   62         test_name = test_name.replace('test_suite.unit_tests.', '')
   63 
   64         # Split out the module name from the test name.
   65         module_name, test_name = split('.Test_', test_name)
   66 
   67         # Rebuild the test name.
   68         test_name = "module %s, test Test_%s" % (module_name, test_name)
   69 
   70     # Return the test name.
   71     return test_name
   72 
   73 
   74 def subtitle(text):
   75     """Function for printing the subtitles.
   76 
   77     @param text:    The text of the subtitle to be printed.
   78     @type text:     str
   79     """
   80 
   81     # The width of the subtitle string.
   82     width = len(text) + 2
   83 
   84     # Text.
   85     sys.stdout.write("# %s\n" % text)
   86 
   87     # Bottom bar.
   88     sys.stdout.write("#" * width)
   89 
   90     # Spacing.
   91     sys.stdout.write("\n\n")
   92 
   93 
   94 def summary_line(name, passed, width=100):
   95     """Print a summary line.
   96 
   97     @param name:    The name of the test, test category, etc.
   98     @type name:     str
   99     @param passed:  An argument which if True causes '[ OK ]' to be printed and if False causes '[ Failed ]' to be printed.  The special string 'skip' is used to indicate that this has been skipped.
  100     @type passed:   bool or str
  101     @keyword width: The width of the line, excluding the terminal '[ OK ]' or '[ Failed ]'.
  102     @type width:    int
  103     """
  104 
  105     # Passed.
  106     if passed == True:
  107         state = "OK"
  108 
  109     # Skipped.
  110     elif passed == 'skip':
  111         state = "Skipped"
  112 
  113     # Failed.
  114     else:
  115         state = "Failed"
  116 
  117     # Dots.
  118     dots = ''
  119     for j in range(width - len(name) - len(state) - 6):
  120         dots += '.'
  121 
  122     # Write out the line.
  123     sys.stdout.write("%s %s [ %s ]\n" % (name, dots, state))
  124 
  125 
  126 def test_title(name, desc=None, width=100):
  127     """Format and write out a title for the test.
  128 
  129     @param name:    The name of the test.
  130     @type name:     str
  131     @keyword desc:  An optional description for the test.
  132     @type desc:     str
  133     @keyword width: The console width.
  134     @type width:    int
  135     """
  136 
  137     # Output the title.
  138     divider('=', width=width)
  139     sys.stdout.write("Starting test: %s\n" % name)
  140     if desc:
  141         sys.stdout.write("\n")
  142         for line in wrap(desc, width):
  143             sys.stdout.write("%s\n" % line)
  144     divider('-', width=width)
  145 
  146 
  147 def title(text):
  148     """Function for printing the titles.
  149 
  150     @param text:    The text of the title to be printed.
  151     @type text:     str
  152     """
  153 
  154     # The width of the title string.
  155     width = len(text) + 4
  156 
  157     # Top spacing.
  158     sys.stdout.write("\n\n\n\n")
  159 
  160     # Top bar.
  161     sys.stdout.write("#" * width)
  162     sys.stdout.write("\n")
  163 
  164     # Text.
  165     sys.stdout.write("# %s #\n" % text)
  166 
  167     # Bottom bar.
  168     sys.stdout.write("#" * width)
  169 
  170     # Spacing.
  171     sys.stdout.write("\n\n\n")