‘epyunit.SubprocUnit’ - Module

The module ‘epyunit.SubprocUnit’ provides atoms for unittest on subprocess calls.

The main classes are:

  • SubprocessUnit - Extends SystemCalls for the application of a state decision engine onto the execution results.
  • SProcUnitRules - Stores, manages, and applies the defined rule set for the final result state.

Basic classes and functions for unittests.

Class: SubprocessUnit

class epyunit.SubprocUnit.SubprocessUnit(**kargs)[source]

Wraps and checks results from execution of subprocesses by objects of class ‘SProcUnitRules’.

Methods

__init__

SubprocessUnit.__init__(**kargs)[source]

Prepares the caller interface for subprocess unit tests.

Args:
**kargs: Parameter specific for the operation,
passed through to setkargs.
Returns:
When successful returns ‘True’.
Raises:
passed through exceptions:

apply

SubprocessUnit.apply(res=None)[source]

Applies the linked rule set onto the res-data.

Args:
res: Result data to be filtered by a filter of type
‘epyunit.SProcUnitRules’.
Returns:
When a rule set is present and could be applied successful returns ‘True’, else either ‘False’, or raises an exception.
Raises:
passed through exceptions:

get_proceed

SubprocessUnit.get_proceed(s=None)[source]

Verifies valid proceed type.

Args:
s: Requested type for validation.
Returns:
Supported types.
Raises:
passed through exceptions:

setkargs

SubprocessUnit.setkargs(**kargs)[source]

Sets provided parameters for the subprocess call context.

Applicable for the initial call of self.__init__(), and later modification. Called for each start of a subprocess in order to update optional the specific call context modification.

Calls the parent method by default, could be supressed by option for the update of current objects class only.

Args:

**kargs: Parameters specific for the operations.

noparent: Suppress call of parent class.

rules: Sets the rules object to be used.

Returns:
When successful returns ‘True’, else returns either ‘False’, or raises an exception.
Raises:
passed through exceptions:

setruleset

SubprocessUnit.setruleset(ruleset)[source]

Assigns the ruleset object as current.

Args:
ruleset: The ruleset to be applied as unittest.
Replaces any previous.
Returns:
Returns the previous value of ruleset. If input is not an instance of ‘SProcUnitRules’ returns ‘None’.
Raises:
passed through exceptions:

__str__

SubprocessUnit.__str__()[source]

Prints the current unit parameters including parent.

__repr__

SubprocessUnit.__repr__()[source]

Prints the current representation of unit parameters including parent and ruleset.

Exceptions

exception epyunit.SubprocUnit.SubprocessUnitException[source]

Failure of subprocess call.

Class: SProcUnitRules

class epyunit.SubprocUnit.SProcUnitRules(**kargs)[source]

The ‘epyunit.SubprocUnit.SProcUnitRules’ defines the expected data, and the minimal degree of expectation. Therefore a set of parameters constitute a basic rule set, which matches the provided reference data on the actual response data.

Methods

__init__

SProcUnitRules.__init__(**kargs)[source]

Initializes the ruleset and operational parameters.

For parameters refer to called setrules and setkargs.

apply

SProcUnitRules.apply(ret)[source]

Apply rules on the input ret and weight the result.

The provided match patterns and values are matched onto the input, and the number of matches is counted.

The number of required matches of sub-patterns has to be defined within the regexpr, e.g. by:

'abv{4}[^v]+'

this matches on:

abvvvv
Args:
ret: Tuple received from ‘SystemCalls’.
Returns:
When successful returns ‘True’, else returns either ‘False’, or raises an exception.
Raises:
passed through exceptions:

reset

SProcUnitRules.reset()[source]

A completely empty initial in-place default set for current variables.

setkargs

SProcUnitRules.setkargs(**kargs)[source]

Sets supported parameters.

Applicable for the initial call of self.__init__(), and later modification.

Tolerates unknown keyword parameters, pops own.

Args:

**kargs: Parameter specific for the operation,

debug: Sets debug for rule application.

verbose: Sets verbose for rule application.

Returns:
When successful returns ‘True’, else returns either ‘False’, or raises an exception.
Raises:
passed through exceptions:

setrules

SProcUnitRules.setrules(**predef)[source]

Initialize and reset parameters and previous results.

Args:

**kargs:

setdefault: Sets the predefined default dictionary,
see ‘rules_default’.

debug:

True: see re.DEBUG, when set

False: default:=unset

dotall:

True: see re.DOTALL, when set

False: default:=unset

exitign:

True: Ignores exit at all.

False: Does not ignore exit value.

exittype:

False|’nok’: Success when exit is not 0.

True|’ok’: Success when exit is 0.

‘value’: Success when exit is equal <exit-value>.

exitval=<exit-value>: A specific exit value indicating
success.

ignorecase:

True: see re.IGNORECASE, when set

False: default:=unset

multiline:

True: see re.MULTILINE, when set

False: default:=unset

priotype:

False|’nok’: One failure state sets the whole case
to failure. This is the default.
True|’ok’: One success state sets the whole case
to success.

weight: Choose larger values of counters.

<customcallback>: Custom callback with signature:

customcallback(self,ret)

self: Current instance.

ret: Data provided to apply.

reset: A reset dictionary, see ‘rules_reset’.

result: Required sum of all matches for success,
else failure.
resultnok: Required sum of NOK matches for failure,
else success.
resultok: Required sum of OK matches for success,
else failure.
stderrnok: List of regular expressions for match on

STDERR, indicating failure.

Could contain app-cached precompiled ‘re’.

stderrok: List of regular expressions for match on

STDERR, indicating success.

Could contain app-cached precompiled ‘re’.

stdoutnok: List of regular expressions for match on

STDOUT, indicating failure.

Could contain app-cached precompiled ‘re’.

stdoutok: List of regular expressions for match on

STDOUT, indicating success.

Could contain app-cached precompiled ‘re’.

unicode:

True: see re.UNICODE, when set

False: default:=unset

Returns:
When successful returns ‘True’, else returns either ‘False’, or raises an exception.
Raises:
passed through exceptions:

states

SProcUnitRules.states()[source]

State values of current applied unittest.

The applied parameters are available by ‘repr()’.

Args:
ret: Tuple received from ‘SystemCalls’.
Returns:

Returns the state of the last ‘apply’ operation. this is the result of the ‘filter’ and ‘countres’ described in the manual by the syntax-tree:

r = {
  '_exitcond' = self._exitcond,   # resulting after applied self.exittype
  'exit' = self._exitret, # see _exitcond 
  'stderrnok' = self.stderrnok_matched,
  'stderrok' = self.stderrok_matched,
  'stdoutnok' = self.stdoutnok_matched,
  'stdoutok' = self.stdoutok_matched,

  'result' = self.result_cnt,
  'resultnok' = self.resultnok_cnt,
  'resultok' = self.resultok_cnt,
}
Raises:
passed through exceptions:

__str__

SProcUnitRules.__str__()[source]

Prints current rule set.

__repr__

SProcUnitRules.__repr__()[source]

Represents current rule set.

Exceptions

exception epyunit.SubprocUnit.SProcUnitRulesException[source]

Application error of unittest rules.