~drizzle-trunk/drizzle/development

2144.1.1 by patrick crews
Overhaul of code. We can run rabbitmq : ) We now better encapsulate a per-executor working environment = one step closer to --parallel >: ) using subprocess goodness for server control
1
#! /usr/bin/env python
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
2
# -*- mode: python; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
#
5
# Copyright (C) 2009 Sun Microsystems
2121.3.1 by patrick crews
Added licensing text to dbqp files
6
# Copyright (C) 2011 Patrick Crews
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
7
#
8
# Authors:
9
#
10
#  Jay Pipes <joinfu@sun.com>
11
#  Monty Taylor <mordred@sun.com>
2121.3.1 by patrick crews
Added licensing text to dbqp files
12
#  Patrick Crews 
13
#
2121.3.2 by patrick crews
Updated license verbiage
14
# This program is free software; you can redistribute it and/or modify
15
# it under the terms of the GNU General Public License as published by
16
# the Free Software Foundation; either version 2 of the License, or
17
# (at your option) any later version.
18
#
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
# GNU General Public License for more details.
23
#
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
2121.3.1 by patrick crews
Added licensing text to dbqp files
27
#
28
#
29
# This code is modified from the logging module used in the 
30
# drizzle-automation project - https://launchpad.net/drizzle-automation
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
31
32
33
""" Simple replacement for python logging module that doesn't suck """
34
35
import time, sys
36
37
38
class loggingManager():
39
    """ Class to deal with logging
40
        We make a class just because we forsee ourselves being
41
        multi-threaded and it will be nice to have a single
42
        point of control for managing i/o.
43
44
        Also, this is the cleanest way I can think of to deal
45
        with test-reporting (again, multi-threaded and such
46
47
    """
48
49
    def __init__(self, variables):
50
51
        self.log_file = sys.stdout
2088.9.21 by patrick crews
Tweak to report output
52
        self.report_fmt = '{0:<55} {1} {2:>12}'
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
53
        self.report_started = 0  
54
        self.thick_line = '='*80
55
        self.thin_line = '-'*80     
56
57
    def _write_message(self,level, msg):
58
      self.log_file.write("%s %s: %s\n" % (time.strftime("%d %b %Y %H:%M:%S"), level, str(msg)))
59
      self.log_file.flush()
60
61
    def setOutput(self,file_name):
62
      if file_name == 'stdout':
63
        self.log_file= sys.stdout
64
      else:
65
        self.log_file= open(variables['log_file'],'w+')
66
67
    def info(self,msg):
68
      self._write_message("INFO", msg)
69
70
    def warning(self,msg):
71
      self._write_message("WARNING", msg)
72
73
    def error(self,msg):
74
      self._write_message("ERROR", msg)
75
76
    def verbose(self,msg):
77
      self._write_message("VERBOSE", msg)
78
79
    def debug(self,msg):
80
      self._write_message("DEBUG", msg)
81
 
82
    def debug_class(self,codeClass):
83
        self._write_message("DEBUG**",codeClass)
84
        skip_keys = ['skip_keys', 'debug', 'verbose']
85
        for key, item in sorted(vars(codeClass).items()):
86
            if key not in codeClass.skip_keys and key not in skip_keys:
87
                self._write_message("DEBUG**",("%s: %s" %(key, item)))
88
89
90
2088.9.18 by patrick crews
Updates to allow for timing of test cases and reporting and whatnot
91
    def test_report( self, test_name, test_status
92
                   , execution_time, additional_output=None):
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
93
        """ We use this method to deal with writing out the test report
94
95
        """
96
        if not self.report_started:
97
            self.report_started = 1
98
            self.write_report_header()
2088.9.18 by patrick crews
Updates to allow for timing of test cases and reporting and whatnot
99
        test_status = "[ %s ]" %(test_status)
100
        msg = self.report_fmt.format( test_name, test_status
101
                                    , execution_time)
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
102
        self._write_message("", msg)
2148.1.5 by patrick crews
Some code cleanup + bug fix + setting up for parallel - using subprocess module for drizzletest calls >: )
103
        if additional_output and test_status != '[ pass ]':
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
104
            additional_output=additional_output.split('\n')
105
            for line in additional_output:
106
                line = line.strip()
107
                self._write_message("",line)
108
109
    def write_report_header(self):
110
        self.write_thick_line()
2088.9.18 by patrick crews
Updates to allow for timing of test cases and reporting and whatnot
111
        self.test_report("TEST NAME", "RESULT", "TIME (ms)")
2088.9.1 by patrick crews
Updated tree so that test-run.pl and test-run.py may live together in peace for a time
112
        self.write_thick_line()
113
114
    def write_thin_line(self):
115
        self._write_message("",self.thin_line)
116
117
    def write_thick_line(self):
118
        self._write_message("",self.thick_line)
119
120
121
122