1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
27
28
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
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
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
92
93
94
95
96