Peach :: Generators :: dictionary :: GeneratorListGroupMaster :: Class GeneratorListGroupMaster
[hide private]

Class GeneratorListGroupMaster

source code


Provides a mechanism to create in effect a group of GeneratorList2's that will progress and increment together drivin by the master of the group. This Generator is the Group Master generator and controls the slaves of the group.

This generator comes in handy when you have two bits of data that are logically linked but in separate places. An example would be a length of data being generated. Both values are parameters and generated separaetly but a test calls for performing different length tests against different data being generated (zero length data and 100 bytes of data say) which would be a subset of the noramally generated data.

Example:

>>> groupNormalBlock = Group()
>>> groupForeachBlock = Group()
>>> groupDoLength = Group()
>>> groupForeachBlockDoLength = GroupForeachDo(groupForeachBlock, groupDoLength)
>>> 
>>> genBlock = GeneratorListGroupMaster(None, [
...     groupNormalBlock,
...     groupForeachBlockDoLength
...     ], [
...     
...     # Our normal tests
...     GeneratorList(groupNormalBlock, [
...             Static('A'),
...             Static('BB'),
...             ]),
...     
...     # For each of these do all the length tests
...     GeneratorList(groupForeachBlock, [
...             Static(''),
...             Static('PEACH' * 10),
...             ]),
...     ])
>>>
>>> genLength = GeneratorListGroupSlave([
...             None,
...     None,
...     ], [
...     # generated value for the normal block tests
...     BlockSize(genBlock),
...
...     # actual length tests
...     GeneratorList(groupDoLength, [
...             NumberVariance(None, BlockSize(genBlock), 20),
...             BadNumbers(),
...             ])
...     ], genBlock)
>>>
>>> print genBlock.getValue()
A
>>> print genLength.getValue()
1
>>> genBlock.next()
>>> print genBlock.getValue()
BB
>>> print genLength.getValue()
2
>>> genBlock.next()
>>> print genBlock.getValue()
>>> print genLength.getValue()
-20
Instance Methods [hide private]
 
__init__(self, group, groupList, list, slaves=None, name=None)
Base constructor, please call me!
source code
 
next(self)
Next value.
source code
 
reset(self)
Called to reset the generator to its initial state.
source code
 
addSlave(self, slave) source code

Inherited from GeneratorList2: setGroups

Inherited from GeneratorList: getList, getRawValue, setList

Inherited from generator.Generator: __iter__, getGroup, getName, getTransformer, getValue, identity, setGroup, setName, setTransformer

Static Methods [hide private]

Inherited from GeneratorList2: unittest

Class Variables [hide private]
  _slaves = []
  _completed = False
Method Details [hide private]

__init__(self, group, groupList, list, slaves=None, name=None)
(Constructor)

source code 

Base constructor, please call me!

Parameters:
  • group (Group) - Group this Generator belongs to
  • groupList (list) - List of Groups to use on generators
  • list (list) - List of Generators to iterate through
  • name (String) - [optional] Name for this Generator. Used for debugging.
Overrides: generator.Generator.__init__

next(self)

source code 

Next value. OVERRIDE

From Python docs on next():

The intention of the protocol is that once an iterator's next() method raises StopIteration, it will continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken. (This constraint was added in Python 2.3; in Python 2.2, various iterators are broken according to this rule.)

For Generators, please use the GeneratorCompleted exception instead of StopIteration (its a subclass).

Overrides: generator.Generator.next
(inherited documentation)

reset(self)

source code 

Called to reset the generator to its initial state. OVERRIDE

Overrides: generator.Generator.reset
(inherited documentation)