pyats.aetest.processors package

Submodules

class pyats.aetest.processors.bases.BaseContextProcessor(index, section, name=None, **kwargs)

Bases: BaseProcessor

Base class for context processors. Users can inherit from this class when creating their context-based processor classes.

__init__

on initialization, the current executing section will be provided to the context class as the only argument.

Behavior:
  • upon init, if an InapplicableSection exception is raised, the current context processor will be skipped.

Parameters:

section (TestItem) – current section item

post_context()
source = <pyats.aetest.base.Source object>
class pyats.aetest.processors.bases.BaseProcessor(*, index, section, **kwargs)

Bases: TestItem

TestItem.__init__

Parameters:
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item

static aborted(reason=None, *, data=None, from_exception=None)

Test Aborted

API to call when the current test item execution is aborted. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static blocked(reason=None, *, data=None, from_exception=None)

Test Blocked

API to call when the current test item execution is blocked. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static errored(reason=None, *, data=None, from_exception=None)

Test Errored

API to call when the current test item execution errored out. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static failed(reason=None, *, data=None, from_exception=None)

Test Failed

API to call when the current test item execution is failed. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static passed(reason=None, *, data=None, from_exception=None)

Test Passed

API to call when the current test item execution is passed. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static passx(reason=None, *, data=None, from_exception=None)

Test Passx

API to call when the current test item execution result is passed with exception. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

static skipped(reason=None, *, data=None, from_exception=None)

Test Skipped

API to call when the current test item execution should be skipped. Terminates current execution.

Parameters:
  • (str) (reason) –

  • (any) (data) –

  • (obj) (goto) –

  • (exception) (from_exception) –

start_report()
stop_report(exc_type=None, exc_value=None, exc_traceback=None)
class pyats.aetest.processors.decorator.ProcessorDecorator(*processors, pre=None, post=None, exception=None)

Bases: object

Defines and uses the AEtest pre/post/exception processor protocol that enables sections to be processed immediately before and after execution. This api is called to affix/get processor information from each section.

Note that this class is not used directly. Rather, users should be calling the @processors decorator instead (set below)

Processor Protocol:

  • preprocessors are stored as a list in attr ‘__processors__.pre`

  • postprocessors are stored as a list in attr ‘__processors__.post`

  • exceptionprocessors are stored as a list in attr ‘__processors__.exception`

  • processor objects must be callable

  • processor objects must require no arguments, or only 1 arguments named ‘section’

  • exceptionprocessors objects require 4 arguments named ‘section’, ‘exc_type’, ‘exc_value’, and ‘exc_traceback’

  • preprocessor objects returning ‘False’ will cause the section to be skipped.

  • preprocessor objects containing AssertionError will cause the section to be skipped.

  • exceptionprocessors objects returning ‘True’ will cause the exception to be suppressed.

  • processor objects containing Exceptions will cause the section to be errored, and skipped in the case of pre-processor.

built-in __init__

Parameters:
  • (list) (exception) –

  • (list)

  • (list)

  • (list)

classmethod add(section, **kwargs)

add processors

Function to be called to dynamically add pre/post/exception processors to a given section. This adds more pre/post/exception processrs to the given section.

Examples

>>> aetest.processors.add(Testcase, pre=[func_A], post=[func_B],
...                                 exception=[func_C])
Parameters:
  • (object) (section) –

  • (list) (context) –

  • (list)

  • (list)

  • (list)

classmethod affix(section, context=(), **kwargs)

affix processors

Function to be called to dynamically attach pre/post/exception processors to a given section. This is the same as @processors decorator , but is intended to be used within testscripts as an api call, rather than a decorator.

This function, when called, replaces any existing pre/post/exception processors attached to the provided section.

Examples

>>> aetest.processors.affix(Testcase, pre=[func_A], post=[func_B],
...                                   exception=[func_C])
Parameters:
  • (object) (section) –

  • (list) (context) –

  • (list)

  • (list)

  • (list)

static context(func, name=None)

decorator to be used to decorate a generator-based context manager function to become a context processor.

Example

@aetest.processors.context def context_processor(section):

print(‘before section’: section.uid) yield print(‘after section’: section.uid)

classmethod exception(*processors, name=None)

exception decorator

Shortcut decorator to defining exception-processors directly using *varargs style input. This is functionally equivalent to @processors(exception=[]).

Examples

>>> @aetest.processors.exception(func_A, func_B)
... class Testcase(aetest.Testcase):
...     pass
Parameters:

(varargs) (processors) –

classmethod get(section, type_='context', incl_globals=False)

get processors

Function to be called to return the list of pre/post/exception processors currently attached to a function/section.

Examples

>>> aetest.processors.get(Testcase, type_ = 'pre')
>>> aetest.processors.get(Testcase, type_ = 'post')
>>> aetest.processors.get(Testcase, type_ = 'exception')
Parameters:
  • (object) (section) –

  • (str) (type) – ‘context’

  • (bool) (incl_globals) – type as well. Default to False

Return type:

list of processor objects

static noreport(func)

decorator used to disable reporting for a processor

Example

@aetest.processors.noreport def my_processor(section):

classmethod post(*processors, name=None)

post decorator

Shortcut decorator to defining post-processors directly using *varargs style input. This is functionally equivalent to @processors(post=[]).

Examples

>>> @aetest.processors.post(func_A, func_B)
... class Testcase(aetest.Testcase):
...     pass
Parameters:

(varargs) (processors) –

classmethod pre(*processors, name=None)

pre decorator

Shortcut decorator to defining pre-processors directly using *varargs style input. This is functionally equivalent to @processors(pre=[]).

Examples

>>> @aetest.processors.pre(func_A, func_B)
... class Testcase(aetest.Testcase):
...     pass
Parameters:

(varargs) (processors) –

static report(func)

decorator used to mark a processor for reporting

Example

@aetest.processors.report def my_processor(section):

pyats.aetest.processors.decorator.discover_global_processors(module)

discover_global_processors parameters

checks all attributes of a given object (TestScript) and returns the user defined list of processors (dictionary ‘processors’). This API is intended to be called by TestScript to discover any global processors defined in the script module.

Parameters:

(object) (obj) –

Return type:

all discovered processors wrapped in ProcessorStore() class

exception pyats.aetest.processors.exceptions.InapplicableSection

Bases: Exception

Exception to be raised by processor if it determines that it shouldn’t be run for the given section

class pyats.aetest.processors.handler.ProcessorHandler(section)

Bases: object

Context manager class designed to run handlers embedded for each script object. Requires that the section is an instance of TestItem (so that signal APIs can be properly called).

  • runs all pre/post processors for the given object

  • if pre-processors fail, post-processors are not run

  • errors & failures are handled using TestItem.<result> apis.

Example

>>> with ProcessorHandler(section):
...     section()
exception(type_, value, traceback)

Internal function, executes any ExceptionProcessors and ContextProcessors[__exit__] attached to the given section, in order to handle the raised exception from this section. Should be called by executer only. Called before the executer has set any section result.

Note

ContextProcessors[__exit__] will be executed here if the section raises an exception, otherwise they will be called after the section result is set with the rest of the PostProcessors.

start()

Internal function, executes any PreProcessors attached to the given section, handles errors & common behaviors. This should be called by executer only.

  • If any PreProcessor returns False, the section’s result will be updated to Skipped.

  • If any signal is raised, the section’s result will be updated according to the signal

  • If any error is caught, the section’s result will be updated to Errored.

stop()

Internal function, executes any PostProcessors and ContextProcessors[__exit__] attached to the given section. This should be called by executer only. Called after the executer has set the section result.

Note

ContextProcessors[__exit__] are only executed here if an exception was not raised, otherwise they will be executed before the result of the section is set.

pyats.aetest.processors.skips.skip(reason='skip decorator')

skip decorator

Decorator to provide shortcut to skip a section unconditionally. Optionally accepts a message to print as reason.

Examples

>>> @aetest.skip('just cause!')
... class Testcase(aetest.Testcase)
Parameters:

(str) (reason) –

pyats.aetest.processors.skips.skipIf(condition, reason='skipIf condition == True')

skipIf decorator

Decorator to provide shortcut to skip a section if the provided condition is True. Optionally accepts a message to print as reason.

Examples

>>> @aetest.skipIf(True, 'just cause!')
... class Testcase(aetest.Testcase)
Parameters:
  • (bool) (condition) –

  • (str) (reason) –

pyats.aetest.processors.skips.skipIf_affix(section, condition, reason='skipIf condition == True', *args, **kwargs)
pyats.aetest.processors.skips.skipUnless(condition, reason='skipUnless condition == False')

skipUnless decorator

Decorator to provide shortcut to skip a section unless condition is True. Optionally accepts a message to print as reason.

Examples

>>> @aetest.skipUnless(False, 'just cause!')
... class Testcase(aetest.Testcase)
Parameters:

(str) (reason) –

pyats.aetest.processors.skips.skipUnless_affix(section, condition, reason='skipUnless condition == False', *args, **kwargs)
pyats.aetest.processors.skips.skip_affix(section, reason='skip decorator', *args, **kwargs)
class pyats.aetest.processors.store.ProcessorStore(context=None, pre=None, post=None, exception=None)

Bases: object

built-in __init__

Parameters:
  • (list) (exception) –

  • (list)

  • (list)

  • (list)

clear()

copy

similar to dict.clear() api

copy()

similar to dict.copy() api

extend(**processors)

prepend

extends current list of processors with the given processors

get(name, default=None)

similar to dict.get() api.

items()

similar to dict.items() api

prepend(**processors)

inserts given processors into the front of all current list of processors.

update(data)

similar to dict.update() api

class pyats.aetest.processors.wrappers.BaseFuncProcessor(*args, func, index, section, name=None, **kwargs)

Bases: BaseProcessor

Base class used to wrap function based processors

TestItem.__init__

Parameters:
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item

processor_type = 'Processor'
class pyats.aetest.processors.wrappers.ExceptionProcessor(*args, func, index, section, name=None, **kwargs)

Bases: BaseFuncProcessor

Class that wraps function-based exception-processors

TestItem.__init__

Parameters:
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item

class pyats.aetest.processors.wrappers.GeneratorContextProcessor(*args, func, index, section, name=None, report=None, parameters={}, **kwargs)

Bases: BaseFuncProcessor

class that wraps function-based context processors using the contextmanger

TestItem.__init__

Parameters:
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item

post_context()
class pyats.aetest.processors.wrappers.PostProcessor(*args, func, index, section, name=None, **kwargs)

Bases: BaseFuncProcessor

Class that wraps function-based post-processors

TestItem.__init__

Parameters:
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item

class pyats.aetest.processors.wrappers.PreProcessor(*args, func, index, section, name=None, **kwargs)

Bases: BaseFuncProcessor

Class that wraps function-based pre-processors

TestItem.__init__

Parameters:
  • (str) (description) –

  • (str)

  • (obj) (parent) –

  • (dict) (parameters) –

  • (kwargs) (kwargs) – test item