Package qm :: Package test :: Module file_result_stream
[hide private]
[frames] | no frames]

Source Code for Module qm.test.file_result_stream

 1  ######################################################################## 
 2  # 
 3  # File:   file_result_stream.py 
 4  # Author: Mark Mitchell 
 5  # Date:   04/13/2003 
 6  # 
 7  # Contents: 
 8  #   FileResultStream 
 9  # 
10  # Copyright (c) 2003 by CodeSourcery, LLC.  All rights reserved.  
11  # 
12  ######################################################################## 
13   
14  ######################################################################## 
15  # Imports 
16  ######################################################################## 
17   
18  import qm.common 
19  import qm.fields 
20  from   qm.test.result_stream import ResultStream 
21  import sys 
22   
23  ######################################################################## 
24  # Classes 
25  ######################################################################## 
26   
27 -class FileResultStream(ResultStream):
28 """A 'FileResultStream' writes its output to a file. 29 30 A 'FileResultStream' is an abstract base class for other result 31 stream classes that store results in a single file. The file to 32 which results should be written can be specified using either the 33 'filename' argument or the 'file' argument. The latter is for use 34 by QMTest internally.""" 35 36 arguments = [ 37 qm.fields.TextField( 38 name = "filename", 39 title = "File Name", 40 description = """The name of the file. 41 42 All results will be written to the file indicated. If no 43 filename is specified, or the filename specified is "-", 44 the standard output will be used.""", 45 verbatim = "true", 46 default_value = ""), 47 qm.fields.PythonField( 48 name = "file"), 49 ] 50 51 _is_binary_file = 0 52 """If true, the file written is a binary file. 53 54 This flag can be overridden by derived classes.""" 55
56 - def __init__(self, arguments = None, **args):
57 58 ResultStream.__init__(self, arguments, **args) 59 60 if not self.file: 61 if self.filename and self.filename != "-": 62 # Open the file in unbuffered mode so that results will be 63 # written out immediately. 64 if self._is_binary_file: 65 mode = "wb" 66 else: 67 mode = "w" 68 self.file = open(self.filename, mode, 0) 69 # Child processes do not need to write to the results 70 # file. 71 qm.common.close_file_on_exec(self.file) 72 else: 73 self.file = sys.stdout
74