‘epyunit’ - package

  • epyunit.SubprocUnit: SubprocessUnit , and SProcUnitRules

    Basic classes and functions for unittests.

  • epyunit.SystemCalls: SystemCalls

    The module ‘epyunit.SystemCalls’ provides the controlled execution of subprocesses as units.

    The features are foreseen to support easy setups for unit and regression tests on complex command line options and their combinations. These are in designed to be used in conjunction with with PyUnit, either within Eclipse and PyDev, or from the command line.

    The provided feature set is supported on the platforms: Linux, MacOS, BSD, Solaris, and Windows.

    A quick example call is:

    python -c 'from epyunit.SystemCalls import SystemCalls;x=SystemCalls(**{"proceed":"trace"});x.callit("myscript.sh xOK")'
    

    or:

    python -c 'from epyunit.SystemCalls import SystemCalls;x=SystemCalls(**{"proceed":"trace"});x.callit("myscript.py xOK")'
    

    SECURITY REMARK: Current version supports for subprocesses the ShellMode only. For test environments in R&D this - hopefully - is perfectly OK, else eventual security issues has to be considered.

    The SystemCalls class optionally uses subprocess32 when present, this is recommended. See https://pypi.python.org/pypi/subprocess32/.

  • epyunit.debug.pydevrdc: PyDevRDC

    Support for the automation of cross-process remote debugging with PyDev and Eclipse.

    The module provides helpers for the debugging with the PyDev in the Eclipse IDE. This includes utilities for the cross-process debugging by Remote-Debugging. The PyDevRDC module provides processes started outside the PyDev environment, as well as processes under control of PyDev.

    In case the module epyunit.debug.checkRDbg is not yet loaded, this is done and the provided parameters are passed through to the initial call:

    epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions()
    

    See ‘http://pydev.org/manual_adv_remote_debugger.html

    The following parameters modify the control flow:

    • Module Variables:

      • epyunit.debug.pydevrdc.PYDEVD:

        Provides a pre-allocated controller object for remote debugging by PyDev as Eclipse plugin. Could be extended by custom instances as required. Just requires a simple import statement and could thereafter be controlled by parameters.

    • Environment Variables:

      • PYDEVDSCAN:

        The start directory for search on ‘pydevd.py’. If not set, the default is:

        px = $HOME/eclipse/eclipse
        px = os.path.abspath(px)
        px = os.path.realname(px)
        px = os.path.dirname(px)
        px = os.path.normpath(px)
        
  • epyunit.checkRDbg: checkRDbg

    Provides a slim interface for the initialization and extraction of command line parameters for pydevrdc.

    Extracts rdbg-options and provides values for the main module ‘epyunit.debug.pydevrdc’.

  • epyunit.selftest:

    Selftest for the package ‘epyunit’.

  • epyunit:

Sources

‘epyunit.unittest.subprocess’ - Module

The module ‘epyunit.unittest.subprocess’ provides classes derived from ‘unittest’ for tests of arbitrary subprocesses.

Class: TestExecutable

class epyunit.unittest.subprocess.TestExecutable(*args, **kargs)[source]

Extends TestCase for subprocesses.

Methods

__init__
TestExecutable.__init__(*args, **kargs)[source]

Initializes the test case, passes parameters to ‘unittest.TestCase’.

Args:
**kargs: Parameter specific for the operation,
passed through to setkargs.
Returns:
When successful returns ‘True’.
Raises:
passed through exceptions:
__str__
TestExecutable.__str__()[source]

Prints the current test state.

assertEqual
TestExecutable.assertEqual(exp, cur=None)[source]

Asserts tuple result value of the called process.

Args:
exp: Expected value:
(exit-value, stdout-value, stderr-value)
cur: Current value:

(exit-value, stdout-value, stderr-value)

default:=self.spcache

Returns:
When successful returns the True, else raises an exception.
Raises:
Raises result of assertEqueal.
assertExit
TestExecutable.assertExit(exp, cur=None)[source]

Asserts on the exit value of the called process.

Args:
exp: Expected value:
exit-value
cur: Current value:

exit-value

default:=self.spcache[0]

Returns:
When successful returns the True, else raises an exception.
Raises:
Raises result of assertEqual.
assertExists
TestExecutable.assertExists(fpname)[source]

Asserts on the existance of a filesystem node.

Args:
fpname: Filesystem node.
Returns:
When successful returns the True, else raises an exception.
Raises:
Raises result FileNodeDoesNotExists.
assertStderr
TestExecutable.assertStderr(exp, cur=None)[source]

Asserts a list of provided regexpr on the STDERR of the called process.

Args:
exp: Expected value:
stderr-value
cur: Current value:

stderr-value

default:=self.spcache[2]

Returns:
When successful returns the True, else raises an exception.
Raises:
Raises result of assertEqual.
assertStdout
TestExecutable.assertStdout(exp, cur=None)[source]

Asserts a list of provided regexpr on the STDOUT of the called process.

Args:
exp: Expected value:
stdout-value
cur: Current value:

stdout-value

default:=self.spcache[1]

Returns:
When successful returns the True, else raises an exception.
Raises:
Raises result of assertEqual.
callSubprocess
TestExecutable.callSubprocess(callstr, **kargs)[source]

Calls a subprocess and fetches the result data.

Args:

callstr: Complete call string for subprocess.

**kargs:

Pass-through parameters for ‘SystemCalls.callit()’.

cache:
Caches results.
Returns:

When successful returns the tupel:

returnvalue := (exit-value, stdout-value, stderr-value)
Raises:
passed through exceptions:
setkargs
TestExecutable.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.

Args:

**kargs: Parameters specific for the operations.

cache:
Sets caching of the results for subprocess call.
noparent:
Suppress call of parent class.
rules:
Sets the rules object to be used. See: epyunit.SubprocUnit.SProcUnitRules
spunit:
Sets the subprocess unit. See: epyunit.SubprocUnit.SProcUnit
Returns:
When successful returns ‘True’, else returns either ‘False’, or raises an exception.
Raises:
passed through exceptions:

Exceptions

exception epyunit.unittest.subprocess.TestExecutableException[source]

Application error for called executable.

‘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.

‘epyunit.SystemCalls’ - Module

The module ‘epyunit.SystemCalls’ provides the controlled execution of subprocesses as units.

The features are foreseen to support easy setups for unit and regression tests on complex command line options and their combinations. These are in designed to be used in conjunction with with PyUnit, either within Eclipse and PyDev, or from the command line.

The provided feature set is supported on the platforms: Linux, MacOS, BSD, Solaris, and Windows.

A quick example call is:

python -c 'from epyunit.SystemCalls import SystemCalls;x=SystemCalls(**{"proceed":"trace"});x.callit("myscript.sh xOK")'

or:

python -c 'from epyunit.SystemCalls import SystemCalls;x=SystemCalls(**{"proceed":"trace"});x.callit("myscript.py xOK")'

SECURITY REMARK: Current version supports for subprocesses the ShellMode only. For test environments in R&D this - hopefully - is perfectly OK, else eventual security issues has to be considered.

The SystemCalls class optionally uses subprocess32 when present, this is recommended. See https://pypi.python.org/pypi/subprocess32/.

Class: SystemCalls

class epyunit.SystemCalls.SystemCalls(**kargs)[source]

Wraps system calls for the execution of subprocesses. For supported parameters refer to ‘epyunit.SystemCalls.setkargs()’.

Methods

__init__
SystemCalls.__init__(**kargs)[source]

Prepares the interface for subprocess calls with output cache. The initial setup includes the preparation of the result cache for the response data from stdout and stderr.

Args:

**kargs:
Parameters specific for the operations, passed through to SystemCalls.setkargs [see setkargs].

Returns:

When successful returns ‘True’, else returns either ‘False’, or raises an exception. Success is the complete addition only, thus one failure returns False.

REMARK
When errors occur in buffered mode the output from the called process is possibly not completely cached. In that case switch to ‘dialogue’ mode in order to get an unbuffered console display.

Raises:

passed through exceptions:
callit
SystemCalls.callit(cmdcall, **kargs)[source]

Executes a prepared ‘cmdcall’ synchronous by the a preset function pointer ‘self.myexe’. For the full scope of call parameters including multiple subprocesses use the method [see create].

Args:

cmdcall:

A prepared call, either shell-style call-string, or a list in accordance to the call convention of ‘subprocess’ package. The ‘shell’ parameter is by default set in accordance to the provided type.

**kargs:

Parameters specific for the operations, passed through to SystemCalls.setkargs [see setkargs].

The following are also evaluated instantly within the call prologue:

proceed:

Changes predefined value and dispatches to the subcall.

raw:

Suppress the split of lines for stdout and stderr.

Returns:

Result of call, the format is:

ret[0]::= exit value

ret[1]::= STDOUT as non-processed string.

ret[2]::= STDERR as non-processed string.

REMARK
When errors occur in buffered mode the output from the called process is possibly not completely cached, e.g. in case of exeptions. In that case try switching to ‘dialogue’ mode in order to get an unbuffered console display. This will deliver - hopefully - the complete output.

Raises:

SystemCallsTimeout:

Rised in case of timeout by tmax/tsig. Terminates also the outstanding subprocess.

passed through exceptions:

cancel
SystemCalls.cancel(proc=None)[source]

Cancels a running process.

displayit
SystemCalls.displayit(ret, **kargs)[source]

Streams result list ‘ret’ in selected format to selected outtarget.

Args:

ret: Data to be displayed.

**kargs:

outtarget: The target of display:

str: return as formatted string

stdout: print to sys.stdout

stderr: print to sys.stderr

out: Output for display, valid:

csv : CSV with sparse records

pass : pass through STDOUT and STDERR from subprocess

repr : Python ‘repr()’

str : Python ‘str()’

xml : XML

default:=self.out

Returns:

When successful returns

outtarget==’str’: returns a printable formatted string

outtarget in (‘stdout’, ‘stderr’,):

‘True’: for success

‘False’: for failure

Raises:

passed through exceptions:
get_proceed
SystemCalls.get_proceed(s)[source]

Verifies valid proceed type.

_mode_batch
_mode_dialogue
SystemCalls._mode_dialogue(cmdcall, **kargs)[source]

Internal call reference for processing an interactive dialogue call.

Supports shell-style parameters only.

For further information refer to ‘console’ option of constructor/setkargs.

setkargs
SystemCalls.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.

Args:

**kargs: Parameter specific for the operation,

bufsize:

The size of the output buffer for the called subprocess, refer to subprocess.Popen. Default value is -1.

cache:=<cache-param=list>

Defines the type and thus target caching of the output of the raw data. The output streams could be combined by defining multiple types:

cache-param-list:=cache-param[,cache-param-list]
cache-param:=(
    {type:pipe}
  | {type:fout,fpname:''}
  | {type:ferr,fpname:''}
  | {type:fouterr,fpname:''}
)

pipe:None

  the Subprocess.PIPE for stdout and stderr

fout:<fpathname>:

  reads stdout into a file

ferr:<fpathname>:

  reads stderr into a file

default := pipe

console (‘cli’,’dialogue’)

ffs (‘batch’,’ui’,’gtk’, ‘qt’)

cli:

Works in batch mode, particularly the stdin, stdout, and stderr streams are caught into a string buffer by the calling process via a pipe. The content is passed after termination of the called sub-process.

dialogue:

Works without buffered io streams. Thus allows for interaction, but not post-processing.

debug:

Sets debug for rule data flow.

emptyiserr:

Treats passed empty call strings as error. The applied ‘subprocess.Popen()’ treats them as success, which may cover errors in generated call strings, particularly in loops.

default := False

env:

Environment to be passed through to the subprocess.

Default := current

errasexcept:

Passes errors as exceptions, transforms the resuls from subprocesses into Exceptions data. Exits the process.

default := False

exectype:

Type of execution.

inproc:

Calls ‘Popen’ directly from within the process.

bythread:

Starts an intermediate thread within current process and executes ‘Popen’.

byfork

Starts an intermediate process by fork and executes ‘Popen’.

forcecmdcall:

Forces type of the command call option passed to ‘Popen’.

  • shell
  • list

inp:

Defines the read-in of the output of called subprocess.

communicate:

Calls Subproces.communicate, blocks until completion of subprocess.

readc:

Reads characters from subprocess, does not accurately synchronize for multiple threads onto one output stream.

Displays each character in real-time.

readl:

Reads characters from subprocess, does accurately synchronize for multiple threads onto one output stream in units of lines.

Displays each line in real-time.

default := communicate

out:

Output for display. Supported types are:

csv:

CSV seperated by ‘;’, with sparse records

pass:

Pass through STDOUT and STDERR from subprocess

repr:

Python ‘repr()’

str:

Python ‘str()’

xml:

XML

passerr:

Passes errors from subprocesses transparently through by stdout, stderr, and exit code. Exits the process.

default := False

proceed (‘print’,’trace’, ‘doit’)

print - trace only

trace - execute and trace

doit - execute

raw:

Pass through strings from STDOUT and STDERR unprocessed. Default is to split the lines into a list for post processing line scope.

rules:

Sets the rules object.

synctype:

Type of call synchronization.

async:

Executes the subprocess asynchronously, this e.g. enables in current implementation for platform independent timeouts.

sync:

Executes synchronously, thus blocks any other execution.

tsig:

Termination signal, default is KILL.

tmax:

Timeout in seconds.

useexit:

Use exit code for error detection of subprocess.

default := True

usestderr:

Use ‘sys.stderr’ output for error detection of subprocess. When set to ‘True’, the presence of a string is treated as error condition.

default := False

verbose:

Sets verbose for rule data flow.

Returns:

When successful returns ‘True’, else returns either ‘False’, or raises an exception. Success is the complete addition only, thus one failure returns False.

Raises:

passed through exceptions:
sub_get_lines
SystemCalls.sub_get_lines(fds, fde, **kargs)[source]

Reads non-blocking from stdout and stderr into a buffer and displays each line immediately.

Args:

fds:

File descriptor for the STDOUT of the called subprocess.

fde:

File descriptor for the STDERR of the called subprocess.

**kargs:

rtd:

Returns:

Raises:

splitLines
SystemCalls.splitLines(oldres)[source]

Converts the raw string fields including ‘ ‘ of a return value into line arrays.

Args:

oldres: The raw result of a previous call.

Returns:

Result of call, the format is:

ret[0]::=exit value

ret[1]::=list of lines from former stdout output, each as
a partial non-processed string.
ret[2]::=list of lines from former stderr output, each as
a partial non-processed string.

Raises:

passed through exceptions:
__str__
SystemCalls.__str__()[source]

Prints preset call parameters.

__repr__
SystemCalls.__repr__()[source]

Prints the current representation of call parameters for subprocesses.

Exceptions

exception epyunit.SystemCalls.SystemCallsException[source]

Common error within epyunit.SystemCalls.

exception epyunit.SystemCalls.SystemCallsExceptionSubprocessError(*args, **kargs)[source]

Error from subprocess.

exception epyunit.SystemCalls.SystemCallsTimeout[source]

Timeout of subprocess epyunit.SystemCalls.

‘epyunit.debug.pydevrdc’ - Module

The PyDev plugin provides for the remote debugging of Python processes. This is also supported for processes started outside the control of the debugger. Here stub code is required in the process started outside the control domain of ‘pydevd.py’. The module ‘epyunit.debug’ supports the localization and load of ‘pydevd.py’ fromvarious versions and locations.

Support for the automation of cross-process remote debugging with PyDev and Eclipse.

The module provides helpers for the debugging with the PyDev in the Eclipse IDE. This includes utilities for the cross-process debugging by Remote-Debugging. The PyDevRDC module provides processes started outside the PyDev environment, as well as processes under control of PyDev.

In case the module epyunit.debug.checkRDbg is not yet loaded, this is done and the provided parameters are passed through to the initial call:

epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions()

See ‘http://pydev.org/manual_adv_remote_debugger.html

The following parameters modify the control flow:

  • Module Variables:

    • epyunit.debug.pydevrdc.PYDEVD:

      Provides a pre-allocated controller object for remote debugging by PyDev as Eclipse plugin. Could be extended by custom instances as required. Just requires a simple import statement and could thereafter be controlled by parameters.

  • Environment Variables:

    • PYDEVDSCAN:

      The start directory for search on ‘pydevd.py’. If not set, the default is:

      px = $HOME/eclipse/eclipse
      px = os.path.abspath(px)
      px = os.path.realname(px)
      px = os.path.dirname(px)
      px = os.path.normpath(px)
      

Module Variables

  • epyunit.Eclipse.PYDEVD:

    Provides a pre-allocated controller object for remote debugging by PyDev as Eclipse plugin. Could be extended by custom instances as required. Just requires a simple import statement and could thereafter be controlled by options.

Environment Variables

  • PYDEVDSCAN:

    The start directory for search on ‘pydevd.py’. If not set, the default is:

    px = $HOME/eclipse/eclipse
    px = os.path.abspath(px)
    px = os.path.realname(px)
    px = os.path.dirname(px)
    px = os.path.normpath(px)
    

    The start directory for search on ‘pydevd.py’. is due to the manual(PyDevRemoteDebugging) located in:

    eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd.py
    

    Apply ‘pyfilesysobjects’ with ‘re’ and ‘glob’ expressions for casual application of a specific version or iteration through the present.

Class: PyDevRDC

class epyunit.debug.pydevrdc.PyDevRDC(**kargs)[source]

Provides automation for remote debugging of external Python process with PyDev.

This particularly provides a prepared environment for cross-process debugging by ‘pydevd’.

Methods

__init__
PyDevRDC.__init__(**kargs)[source]

Create a control stub for a remote debugger.

Search and load ‘pydevd’ for cross-process remote debugging.

Args:

**kargs:

debug:

Debug RDBG itself, developer output.

label=<name>:

An optional label for identifying the currrent instance. The label could be provided as debugging flag.

remotedebug:

Switches remote debugging support On/Off. Dependent of this parameter an internal call of startRemoteDebugExt is performed and a new instance initialized.

rootforscan:

Directory path for the module ‘pydevd.py’, else defaults of ‘scanEclipseForPydevd’.

fpname:

The file path name of the main file for the current process, default:=callname.

label:

The label identifying the current process, default:=callname.

noargv:

Suppresses argv processing completely for the previous arguments. The testflags are still processed.

rdbg:

Same as ‘–rdbg’, for additional processing see ‘noargv’.

rdbgsrv:

Same as ‘–rdbg’srv, for additional processing see ‘noargv’.

rdbgforward:

Same as ‘–rdbg-forward’, for additional processing see ‘noargv’.

rdbgroot:

Same as ‘–rdbg-root’, for additional processing see ‘noargv’.

rdbgsub:

Same as ‘–rdbg-sub’, for additional processing see ‘noargv’.

testflags:

Flags to force specific behaviour - mostly faulty - in order to test the module itself. So, do not use these if you do not know what these actually do.

These partially fail, but provide a sufficient part of the control flow for the aspect of interest.

ignorePydevd:

Debugging the initial bootstrap of an simulated external process. Ignores present loaded debug support. For debugging of the debug support.

ignorePydevdSysPath:

Debugging the initial bootstrap of an simulated external process. Ignores load by current ‘sys.path’. For debugging of the debug support.

ignorePydevdCallParam:

Debugging the initial bootstrap of an simulated external process. Ignores current parameter for load. For debugging of the debug support.

verbose:

Display data for user parameters.
Returns:
Creates a proxy instance.
Raises:
passed through exceptions:
scanEclipseForPydevd
setDebugParams
PyDevRDC.setDebugParams(**kargs)[source]

Sets the parameters for debug.

Args:
**kargs:

host:

Hostname where the debug server is running.

From pdevd.py: The user may specify another host, if the debug server is not in the same machine (default is the local host).

ignore:

When set to False success is mandatory, else an exception it raised. Set this to True/default, when in production systems.

port:

Port the debug server is listening on. From pdevd.py: Specifies which port to use for communicating with the server (note that the server must be started in the same port). Note: currently it’s hard-coded at 5678 in the client

pydevdpath:

Required path pointing to directory for source of pydevd in PyDev subdirectory tree.

remotedebug:

Switches remote debugging support On/Off.

stderrToServer:

Sets whether stderr is directed to debugserver. From pdevd.py: When this is true, the stderr is passed to the debug server so that they are printed in its console and not in this process console.

stdoutToServer:

Sets whether stdout is directed to debugserver. From pdevd.py: When this is true, the stdout is passed to the debug server.

suspend:

If set to True, stops immediately after settrace() call, else at next valid break-condition. From pdevd.py: Whether a breakpoint should be emulated as soon as this function is called.

trace_only_current_thread:

From pdevd.py: Determines if only the current thread will be traced or all future threads will also have the tracing enabled.
Returns:
The location of pydevd.py
Raises:
AttributeError:
setFork
PyDevRDC.setFork()[source]

Prepares debugging after fork.

startDebug
PyDevRDC.startDebug(**kargs)[source]

Starts remote debugging for PyDev.

stopDebug
PyDevRDC.stopDebug()[source]

Stops remote debugging for PyDev.

__str__
PyDevRDC.__str__()[source]

Prints current remote debug parameters.

__repr__
PyDevRDC.__repr__()[source]

Prints the current representation of remote debug parameters.

Exceptions

exception epyunit.debug.pydevrdc.PyDevRDCException[source]
exception epyunit.debug.pydevrdc.PyDevRDCLoadException[source]

Failed load of ‘pydevd.py’.

exception epyunit.debug.pydevrdc.PyDevRDCServerException[source]

Debug server of PyDev is not running - cannot be reached.

‘epyunit.checkRDbg’ - Module

The ‘checkRDbg’ function check the remote debugging status of the current process, and performs required actions, returns the connection paraeters for the configured peer server:

  • when required loads the debugging facilities and activates current process instance
  • when configured prepares and returns the forwarding parameters for the next levels of nested subprocesses
  • when parameters do not match simply ignores debugging

Function: checkAndRemoveRDbgOptions

‘epyunit.selftest’ - Module

Selftest for the package ‘epyunit’.

epyunit.selftest.selftest(slang=None, **kargs)[source]

Calls some interfaces for basic operational checks.

Args:

slang: The language type of the testscript, current availble:

perl

python

bash

**kargs:

out:

verbose:

debug:

Returns:
None.
Raises:
In case of assertion errors.

Commandline tools

  • API-Wrapper - epyunit.py: [doc] [source]

    Commandline interface, for help on the epyunit call e.g.:

    epyunit.py --help
    

    For quick verification of the setup and basic features call:

    epyunit.py --selftest
    
  • PyDev debug support: [doc] [source]

    ‘pydevd.py’ utilities for Eclipse/PyDev, for help on the epyd call e.g.:

    epyd --help
    
  • epyunit.unittest.subprocess: unittest.subprocess

    The module ‘epyunit.unittest.subprocess’ provides classes derived from ‘unittest’ for tests of arbitrary subprocesses.

  • bash - myscript.sh : test response simulator dummy

    For help on the provided hard-coded repsonses call:

    myscript.sh --help
    
  • Python - myscript.py : test response simulator dummy

    For help on the provided hard-coded repsonses call:

    myscript.py --help
    

‘myscript.py’ - Module

Testee data simulator.

Simulates hard-coded test results for the test of the tool chain itself, as reference probe for validation of the chain, and for test of base functions in case of derived classes.

Refer also to the probe simulators in other languages, when debug and step into the probe itself is required:

  • myscript.py - Python
  • myscript.sh - bash
  • myscript.pl - Perl
  • ffs.

Functions:

call_A_OK

epyunit.myscript.call_A_OK()[source]
# A: succeed: OK
EXIT:
0
STDOUT:
fromA
arbitrary output
arbitrary signalling OK string
arbitrary output
STDERR:

call_B_NOK

epyunit.myscript.call_B_NOK()[source]
# B: fail: NOK
EXIT:
0
STDOUT:
fromB
arbitrary output
arbitrary output
STDERR:
arbitrary signalling ERROR string

call_C_PRIO

epyunit.myscript.call_C_PRIO()[source]
# C: redundancy resolved by user defined priority: PRIO
EXIT:
0
STDOUT:
fromC
arbitrary output
arbitrary signalling OK string
arbitrary output
STDERR:
arbitrary signalling ERROR string

call_D_EXITOK

epyunit.myscript.call_D_EXITOK()[source]
# D: exit value: EXITOK
EXIT:
0
STDOUT:
fromD
arbitrary output
arbitrary signalling OK string
arbitrary output
STDERR:

call_E_EXITNOK

epyunit.myscript.call_E_EXITNOK()[source]
# E: exit value: EXITNOK
EXIT:
1
STDOUT:
fromE
arbitrary output
arbitrary signalling OK string
arbitrary output
STDERR:

call_F_EXIT7

epyunit.myscript.call_F_EXIT7()[source]
# F: exit value: EXIT7
EXIT:
7
STDOUT:
fromF
arbitrary output
arbitrary signalling NOK string
arbitrary output
STDERR:

call_G_EXIT8

epyunit.myscript.call_G_EXIT8()[source]
# G: exit value: EXIT8
EXIT:
8
STDOUT:
fromG
arbitrary output
arbitrary signalling NOK string
arbitrary output
STDERR:
arbitrary err output
arbitrary err signalling NOK string
arbitrary err output

call_H_EXIT9OK3NOK2

epyunit.myscript.call_H_EXIT9OK3NOK2()[source]
# H: exit value: EXIT9OK3NOK2
EXIT:
9
STDOUT:
fromH
OK
OK
OK
STDERR:
NOK
NOK

call_I_STDERRONLY

epyunit.myscript.call_I_STDERRONLY()[source]
# I: exit value: STDERRONLY
EXIT:
0
STDOUT:
STDERR:
fromI
NOK
NOK

call_DEFAULT

epyunit.myscript.call_DEFAULT()[source]
# DEFAULT: define: here succeed ‘–default-ok’: DEFAULT
EXIT:
123
STDOUT:
arbitrary output
STDERR:

‘epyunit’ - Command line interface

The epyunit commandline interface provides a call wrapper for unit and regression tests of arbitrary executables. The wrapper internally relies on the standard packages ‘PyUnit’ and integrates into Eclipse by ‘PyDev’. Thus unit tests could be applied in particular for shell scripts and intermixed application processes implemented in multiple programming languages. Automation of remote debugging by PyDev is supported.

The interface is minimalistic but allows for almost any required blackbox test including seamless cross-process-debugging of executables.

Less Is More...

In particular blackbox-tests unittests of bash-scripts are provided by a simple call interface for seamless integration into PyDev and Eclipse.

SYNOPSIS:

epyu    [OPTIONS] [--] <testee> [<testee-options>]   # prefered on Linux,BSD,UNIX,MacOS
epyu.py [OPTIONS] [--] <testee> [<testee-options>]   # prefered on Windows

OPTIONS:

  • appname

    An arbitrary application name to be inserted into record headers.

    --appname=<arbitrary-name-of-app>
    
  • cp

    Classpath for module search, replaces sys.path.
    --cp
    
  • cp-append

    Classpath for module search, appended at the end of sys.path.
    --cp-append
    
  • cp-prepend

    Classpath for module search, inserted at the beginning of sys.path.
    --cp-prepend
    
  • csv

    Prints complete test result CSV format including header.
    --csv
    
  • debug

    Debug entries, does NOT work with ‘python -O ...’. Developer output, aimed for filtering.

    --debug
    -d
    
  • environment

    Include platform info into header.
    --environment
    
  • exitign

    Ignore exit value.
    --exitign=(True|False)
    
  • exittype

    Expect exit value type as success.
    --exittype=(True|False)
    
    • True: Exit value ‘0’ indicates success.
    • False: Exit value ‘!=0’ indicates success.
  • exitval

    Indicates success when exit value is equal to the provided value.

    --exitval=<exit-value>
    
  • help

    This help.
    --help
    -h
    
  • pass

    Pass through the testee results on STDOUT and STDERR. The exit value is interpreted by rules, else the execution state of the framework defines the exit value.

    --pass
    
      exit:   exec-state-of-wrapper-epyunit
      STDOUT: output-from-subprocess
      STDERR: output-from-subprocess
    
  • passall

    Pass through the testee result on STDOUT and STDERR including transparently the received exit value.

    --passall
    
      exit:   exit-of-subprocess
      STDOUT: output-from-subprocess
      STDERR: output-from-subprocess
    
  • priotype

    In case of present failure and success conditions,
    --priotype=(True|False)
    
      default := False
    
    • True: The success conditions dominate, if present at least one.
    • False: the failure condition dominates. if present at least one.
  • rdbg

    Activates remote debugging with PyDev plugin of Eclipse. Optionally the host and port number of the server process could be changed.

    --rdbg[=host[:port]]
    
      host := (ip-add|dns-name)
      port := (port-number)
    
      default := localhost:5678
    
  • rdbg-forward

    Forward the ‘–rdbg’ option to subprocesses for nested debugging of process chains.

    --rdbg-forward=(<forwarding-levels>|all|label)
    
      <forwarding-levels>: Number of levels to be forwarded, 0==None.
    
      all: all nested subprocesses
    
      label: An arbitrary label defined at initialization of the
          debug instance. Debugging is enabled when these match.
    
      default:=0: No forwarding.
    
  • raw

    Enables ‘raw’, equal to passall.
    --raw
    
  • redebug

    Enables ‘re.DEBUG’
    --redebug
    
  • redotall

    Enables ‘re.DOTALL’
    --redotall
    
  • reignorecase

    Enables ‘re.IGNORECASE’.
    --reignorecase
    
  • remultiline

    Enables ‘re.MULTILINE’.
    --remultiline
    
  • repr

    Prints complete test result by Python call of ‘repr()’.
    --repr
    
  • result

    The treshold of the total matched results for changing the overall state to success.

    --result=#total-results
    
      #total-results = #total-failure-results + #total-success-results
    
  • resultnok

    The treshold of the total matched failure results for changing the overall state to success.

    --resultnok=#total-failure-results
    
  • resultok

    The treshold of the total matched success results for changing the overall state to success.

    --resultok=#total-success-results
    
  • reunicode

    Enables ‘re.UNICODE’.
    --reunicode
    
  • selftest

    Performs a basic functional selftest by executing the basic examples based on ‘myscript.<slang>’ or <custom-simulator>.

    --selftest
    

    For the possible resource simulator calls see ‘–slang’.

  • slang

    Defines the resource simulatorPerforms a basic functional selftest by executing the basic examples based on ‘myscript.sh’. All options and arguments are applied during the tests.

    --slang[=(bash|perl|python|<custom-simulator>)]
    
    The following platform dependent defaults are applied by default:
    BSD:     python
    Cygwin:  python
    Linux:   python
    MacOS:   python
    Windows: python
    
    Where the following scripts are assigned to the following provided language tags:
    bash:    epyunit/myscript.sh
    perl:    epyunit/myscript.pl
    python:  epyunit/myscript.py
    

    Additional are going to follow. In addition any executable compliant to the options of the predefined could be called by:

    custom-simulator: "file path name to any compatible executable"
    
  • stderrnok

    Matched string ‘<nok-string>’ on stderr indicates success.
    --stderrnok=<nok-string>
    
    <nok-string>:=(literal|regexpr)
    literal := string-literal
    regexpr := regular-expression-re-module
    
  • stdoutnok

    Matched string ‘<nok-string>’ on stdout indicates success.
    --stdoutnok=<nok-string>
    
    <nok-string>:=(literal|regexpr)
    literal := string-literal
    regexpr := regular-expression-re-module
    
  • stderrok

    Matched string ‘<ok-string>’ on stderr indicates success.
    --stderrok=<ok-string>
    
    <ok-string>:=(literal|regexpr)
    literal := string-literal
    regexpr := regular-expression-re-module
    
  • stdoutok

    Matched string ‘<ok-string>’ on stdout indicates success.
    --stdoutok=<ok-string>
    
    <ok-string>:=(literal|regexpr)
    literal := string-literal
    regexpr := regular-expression-re-module
    
  • str

    Prints complete test result by Python call of ‘str()’.
    --str
    
  • subproc

    Change the framework for the subprocess call.
    --subproc
    

    Starts the subprocess by:

    ‘epyunit.SystemCalls’

    instead of the default:

    ‘epyunit.SubprocessUnit’

  • subunit

    Change the framework for the subprocess call.
    --subunit
    

    Starts the subprocess by default:

    ‘epyunit.SubprocessUnit’

  • test-id

    Prints the test-id with the formats ‘csv’, and ‘xml’. Too be applied in case of multiple test case calls.

    --test-id=<arbitrary-identifier-for-record-header>
    
  • timestamp

    Includes date and time into record header.
    --timestamp
    
  • Version

    Current version - detailed.
    --Version
    -Version
    
  • verbose

    Verbose, some relevant states for basic analysis. When ‘–selftest’ is set, repetition raises the display level.

    --verbose
    -v
    
  • version

    Current version - terse.
    --version
    -version
    
  • xml

    Prints complete test result XML format.
    --xml
    

ARGUMENTS:

  • [–]

    To be used when ambigous options and/or arguments exist, the first match terminates the evaluatoin of the wrapper options.

    [--]
    
  • testee

    The wrapped testee, see EXAMPLES.
    <testee>
    
  • testee-options

    Options of the testee, see EXAMPLES.
    [<testee-options>]
    

DESCRIPTION:

The call interface ‘epyunit’ provides the commandline interface for the unit test wrapper classes.

The call is simply a prefix to the actual testee including it’s options. The wrapper itself provides various criteria for the indication of the success and/or failure of the test case. Therefore correlation of stdout, stderr, and exit values is provided.

The following categories of parameter are provided:

  • Adjusting the decision process:

ENVIRONMENT:

  • PYTHON OPTIONS: -O, -OO: Eliminates ‘__debug__’ code.

EXAMPLES:

Some simple call examples are:
epyunit -- myscript.sh EXITOK
epyunit -- myscript.sh EXITNOK
epyunit -- myscript.sh EXIT8
A call example for cross-process-border remote debugging:
epyunit --rdbg -- epyunit --rdbg -- myscript.sh EXITNOK
0.                1.                2.
  1. Start outmost process from command line and attach it to PyDev by stub.

    epyunit --rdbg
    
  2. Start level-01 subprocess outermost process and attach it to PyDev by stub.

    epyunit --rdbg -- epyunit --rdbg
    
  3. Start level-02 subprocess, here a shell script from level-2 subprocess, and attach it to PyDev by stub.

    epyunit --rdbg -- epyunit --rdbg -- myscript.sh EXITNOK
    

Additional examples could be found within the source code, unit tests, and UseCases.

‘epyd’ - Command line interface for pydevd.py

SYNOPSIS:

epyd [OPTIONS]

OPTIONS:

.

–force

Force selected parameters, ignore standard constraints.

–package

Package the current ‘pysrc’ into a deployment archive for remote debugging.

REMARK: current implementation packages the complete ‘pysrc’ subdirectory, which actually seems not to be required.

–package-type=(zip|tar.gz)

Type of archive.

–package-path=<filepathname-package>

The file pathname for the package to create.
–package-print
Prints the path name of the created package to stdout.

-d –debug

Debug entries, does NOT work with ‘python -O ...’. Developer output, aimed for filtering.

-h –help

This help.

-Version –Version

Current version - detailed.

-v –verbose

Verbose.

-version –version

Current version - terse.

ARGUMENTS:

none.

DESCRIPTION:

The epyd commandline interface provides a helpers for the preparation of remote debugging.

ENVIRONMENT:

  • PYTHON OPTIONS: -O, -OO: Eliminates ‘__debug__’ code.

EXAMPLES:

Some simple call examples are:
epyunit -- myscript.sh EXITOK
epyunit -- myscript.sh EXITNOK
epyunit -- myscript.sh EXIT8
A call example for cross-process-border remote debugging:
epyunit --rdbg -- epyunit --rdbg -- myscript.sh EXITNOK
0.                1.                2.
  1. Start outmost process from command line and attach it to PyDev by stub.

    epyunit --rdbg
    
  2. Start level-01 subprocess outermost process and attach it to PyDev by stub.

    epyunit --rdbg -- epyunit --rdbg
    
  3. Start level-02 subprocess, here a shell script from level-2 subprocess, and attach it to PyDev by stub.

    epyunit --rdbg -- epyunit --rdbg -- myscript.sh EXITNOK
    

Additional examples could be found within the source code, unit tests, and UseCases.

COPYRIGHT:

Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez Copyright (C)2015-2016 Arno-Can Uestuensoez