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

Source Code for Module qm.test.file_result_reader

 1  ######################################################################## 
 2  # 
 3  # File:   file_result_reader.py 
 4  # Author: Nathaniel Smith 
 5  # Date:   2003-06-23 
 6  # 
 7  # Contents: 
 8  #   FileResultReader 
 9  # 
10  # Copyright (c) 2003 by CodeSourcery, LLC.  All rights reserved.  
11  # 
12  # For license terms see the file COPYING. 
13  # 
14  ######################################################################## 
15   
16  ######################################################################## 
17  # Imports 
18  ######################################################################## 
19   
20  from qm.fields import TextField, PythonField 
21  from qm.common import QMException 
22  from qm.test.result_reader import ResultReader 
23  import sys 
24   
25  ######################################################################## 
26  # Classes 
27  ######################################################################## 
28   
29 -class FileResultReader(ResultReader):
30 """A 'FileResultReader' gets its input from a file. 31 32 A 'FileResultReader' is an abstract base class for other result 33 reader classes that read results from a single file. The file 34 from which results should be read can be specified using either 35 the 'filename' argument or the 'file' argument. The latter is for 36 use by QMTest internally.""" 37
38 - class InvalidFile(QMException):
39 """An 'InvalidFile' exception indicates an incorrect file format. 40 41 If the constructor for a 'FileResultStream' detects an invalid 42 file, it must raise an instance of this exception.""" 43 44 pass
45 46 47 48 arguments = [ 49 TextField( 50 name = "filename", 51 title = "File Name", 52 description = """The name of the file. 53 54 All results will be read from the file indicated. If no 55 filename is specified, or the filename specified is "-", 56 the standard input will be used.""", 57 verbatim = "true", 58 default_value = ""), 59 PythonField( 60 name = "file"), 61 ] 62 63 _is_binary_file = 0 64 """If true, results are stored in a binary format. 65 66 This flag can be overridden by derived classes.""" 67
68 - def __init__(self, arguments = None, **args):
69 """Construct a new 'FileResultReader'. 70 71 'arguments' -- As for 'ResultReader'. 72 73 If the file provided is not in the input format expected by this 74 result reader, the derived class '__init__' function must raise 75 an 'InvalidStream' exception.""" 76 77 super(FileResultReader, self).__init__(arguments, **args) 78 79 if not self.file: 80 if self.filename and self.filename != "-": 81 if self._is_binary_file: 82 mode = "rb" 83 else: 84 mode = "r" 85 self.file = open(self.filename, mode, 0) 86 else: 87 self.file = sys.stdin
88 89 90 ######################################################################## 91 # Local Variables: 92 # mode: python 93 # indent-tabs-mode: nil 94 # fill-column: 72 95 # End: 96