Package qm :: Package test :: Package classes :: Module pickle_result_stream :: Class PickleResultStream
[hide private]
[frames] | no frames]

Class PickleResultStream

source code

                 object --+            
                          |            
        extension.Extension --+        
                              |        
     result_stream.ResultStream --+    
                                  |    
file_result_stream.FileResultStream --+
                                      |
                                     PickleResultStream

A 'PickleResultStream' writes out results as Python pickles.

See also 'PickleResultReader', which does the reverse.

Nested Classes [hide private]

Inherited from extension.Extension: Type, __metaclass__

Instance Methods [hide private]
 
__init__(self, arguments=None, **args)
Construct a new 'Extension'.
source code
 
_ResetPickler(self) source code
 
_WriteAnnotationPtr(self) source code
 
WriteAnnotation(self, key, value)
Output an annotation for this run.
source code
 
WriteResult(self, result)
Output a test result.
source code

Inherited from result_stream.ResultStream: Summarize, WriteAllAnnotations

Inherited from extension.Extension: GetClassName, GetExplicitArguments, MakeDomDocument, MakeDomElement, Write, __getattr__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  _max_pinned_results = 1000
A limit on how many `Result's to pin in memory at once.
  _format_version = 1
The version number of the format we write.
  arguments = [<<class 'qm.fields.IntegerField'> protocol_version>]
A list of the arguments to the extension class.
  _is_binary_file = 1
If true, the file written is a binary file.
  _argument_dictionary = {'expected_outcomes': <<class 'qm.field...
A map from argument names to 'Field' instances.
  _argument_list = [<<class 'qm.fields.PythonField'> expected_ou...
A list of all the 'Field's in this class.
  protocol_version = 1

Inherited from file_result_stream.FileResultStream: file, filename

Inherited from result_stream.ResultStream: expected_outcomes, kind

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, arguments=None, **args)
(Constructor)

source code 

Construct a new 'Extension'.

'args': Keyword arguments providing values for Extension parameters. The values should be appropriate for the corresponding fields. Derived classes must pass along any unrecognized keyword arguments to this method so that additional arguments can be added in the future without necessitating changes to derived classes.

This method will place all of the arguments into this objects instance dictionary.

Derived classes may override this method, but should call this method during their processing.

Overrides: object.__init__
(inherited documentation)

WriteAnnotation(self, key, value)

source code 

Output an annotation for this run.

Subclasses should override this if they want to store/display annotations; the default implementation simply discards them.

'key' -- the key value as a string.

'value' -- the value of this annotation as a string.

Overrides: result_stream.ResultStream.WriteAnnotation
(inherited documentation)

WriteResult(self, result)

source code 

Output a test result.

Subclasses must override this method; the default implementation raises a 'NotImplementedError'.

'result' -- A 'Result'.

Overrides: result_stream.ResultStream.WriteResult
(inherited documentation)

Class Variable Details [hide private]

_max_pinned_results

A limit on how many `Result's to pin in memory at once.

Pickling an object normally pins it in memory; this is necessary to ensure correct behaviour when pickling multiple references to the same object. We know that `Result's can't refer to each other, so this pinning is useless overhead; however, clearing the cache at every call to `WriteResult' slows down both pickling and unpickling by about a factor of two. As a solution, any given `PickleResultStream', will clear its cache after `_max_pinned_results' calls to WriteResult. This cache-clearing technique causes a very minor slowdown on small result streams, and a substantial speedup on large result streams.

Value:
1000

_format_version

The version number of the format we write.

This is bumped every time the format is changed, to make sure that we can retain backwards compatibility.

"Version 0" contains no version number, and is simply a bunch of 'Result's pickled one after another.

"Version 1", and all later versions, contain a pickled version number as the first thing in the file. In version 1, this is followed by a 4-byte unsigned integer in network byte order giving the address of the first annotation, followed by the file proper. The file proper is composed of a bunch of pickled 'Result's, followed by a pickled sentinel value (None), followed by a 4-byte unsigned integer in network-byte order, followed by the beginning of a new pickle whose first item is a annotation tuple, and following items are more 'Result's, and then another sentinel value, and so on. An annotation tuple is a tuple of n items, the first of which is a string tagging the type of annotation, and the rest of which have an interpretation that depends on the tag found. The only tag currently defined is "annotation", which is followed by two string elements giving respectively the key and the value. The 4-byte integers always point to the file address of the next such integer, except for the last, which has a value of 0; they are used to quickly find all annotations.

Value:
1

_argument_dictionary

A map from argument names to 'Field' instances.

A map from the names of arguments for this class to the corresponding 'Field'.

Value:
{'expected_outcomes': <<class 'qm.fields.PythonField'> expected_outcom\
es>,
 'file': <<class 'qm.fields.PythonField'> file>,
 'filename': <<class 'qm.fields.TextField'> filename>,
 'protocol_version': <<class 'qm.fields.IntegerField'> protocol_versio\
n>}

_argument_list

A list of all the 'Field's in this class.

This list combines the complete list of 'arguments'. 'Field's appear in the order reached by a pre-order breadth-first traversal of the hierarchy, starting from the most derived class.

Value:
[<<class 'qm.fields.PythonField'> expected_outcomes>,
 <<class 'qm.fields.IntegerField'> protocol_version>,
 <<class 'qm.fields.PythonField'> file>,
 <<class 'qm.fields.TextField'> filename>]