pyats.reporter package

Submodules

class pyats.reporter.base.AsyncReporterConnection(path=None, sock=None, loop=None, reader=None, writer=None)

Bases: object

Initializes an AsyncReporterConnection with either a path to a unix socket, or an already connected async reader/writer pair. Can only accept reader/writer when already in a running event loop.

close()

Close unix connection

async recv()

Receive a few bytes to determine the advertised size of incoming message, then continue receiving until all bytes have been received. Return this data after unpickling.

async send(data)

Pickles data and sends pickled data with a prefix of the size of the data being sent.

class pyats.reporter.base.ReporterConnection(path=None, sock=None)

Bases: object

Initialize ReporterConnection either with a path to a unix socket, or with an already connected socket

close()

Close socket

recv()

Receive a few bytes to determine the advertised size of incoming message, then continue receiving until all bytes have been received. Return this data after unpickling.

send(data)

Pickles data and sends pickled data with a prefix of the size of the data being sent.

class pyats.reporter.client.ReportClient(socketpath, ppid=None)

Bases: object

ReportClient allows easy execution of API calls to the ReportServer. Function calls to ReportClient are automatically pickled and sent to the ReportServer for execution.

close()

Cleanup socket

connect(timeout=25)

Attempt to connect to the server via the file socket defined in init.

disable_forked()

Disable automatic reconnect to parent server when a child process is forked.

enable_forked()

Enable automatic reconnect to parent server when a child process is forked.

static forked(instance)
async subscribe(callback)

Subscribe to the server and handle all updates with a callback

exception pyats.reporter.exceptions.ConnectionBrokenError

Bases: ConnectionError

exception pyats.reporter.exceptions.ConnectionClosedError

Bases: ConnectionError

exception pyats.reporter.exceptions.DuplicateIDError

Bases: ValueError

exception pyats.reporter.exceptions.ExistingClientError

Bases: LookupError

exception pyats.reporter.exceptions.InvalidRequestError

Bases: RuntimeError

exception pyats.reporter.exceptions.MessageReceiveError

Bases: ConnectionError

exception pyats.reporter.exceptions.ServerNotStartedError

Bases: RuntimeError

exception pyats.reporter.exceptions.SignalError

Bases: BaseException

exception pyats.reporter.exceptions.UnhandledContextError

Bases: TypeError

exception pyats.reporter.exceptions.UnregisteredClientError

Bases: LookupError

class pyats.reporter.server.ClientNode(conn, pid, ppid)

Bases: object

ClientNode represents a single client connected to the ReportServer, and stores the context stack for that client to ensure that the APIs not called in an incorrect order.

get_ctx()
pop_ctx()
push_ctx(ctx)
class pyats.reporter.server.ClientTree

Bases: dict

ClientTree stores all of the clients connected to the ReportServer and their relations to each other for propagating reporting contexts between processes.

class pyats.reporter.server.LogLineCounter(file_path, exception_queue=None)

Bases: object

Tracks the number of lines relative to the number of bytes for a given log file. The log file is kept open to prevent wasted time

close()
count(logs)
join()
pattern = re.compile('(\\r\\n|\\n|\\r)')
class pyats.reporter.server.ReportServer(runtimedir)

Bases: object

ReportServer runs in a seperate process as a unix-socket server to aggregate any reporting data. Clients connect via unix-socket and send relevant information about a section. The ReportServer builds a tree structure to store all this information in the appropriate context, and generates a yaml report file from this structure.

add_detail(client, kwargs)

Adds a detail entry to the current context. Often an exception, or some other important information.

add_extra(client, data, list_extend=True)

Add extra information to current context.

add_running_extra(client, kwargs)

Add extra information to all running contexts.

add_testsuite_extra(client, kwargs)

Add extra information to the testsuite.

generate_report(client, kwargs)

Write YAML dump of testsuite to results.yaml file

get_section(client, kwargs)

Get info about a specific section.

get_section_ctx(client, kwargs)

Get info about a specific section context

get_testsuite(client, kwargs)

Give entire testsuite to the client. Testsuite may be None if it has not been started.

ping()

Function for testing client/server connection

register_client(client_conn, kwargs)

Register a new client connecting to the server

remove_section(client, kwargs)

Remove a specific section from the TestSuite.

start_plugin(client, kwargs)

Starts a plugin context. This will fetch or create the parent task or testsuite as defined by the plugin type.

start_section(client, kwargs)

Starts a Section context. Can only be started within a Task context or another Section context. These represent Testcases, common sections, test methods, common subsections, steps.

start_server(timeout=10)

Starts the server process

start_task(client, kwargs)

Starts a Task Context. Can only be started inside the TestSuite context.

start_testsuite(client, kwargs)

Starts the TestSuite context. There can only be one for the entirety of the job run.

stop_open_contexts(client, kwargs)

Stops all contexts, but leave clients alive.

stop_plugin(client, kwargs)

Stops a plugin context

stop_section(client, kwargs)

Stops a Section context.

stop_server(client=None, kwargs=None, timeout=30)

Terminate the server process. Can be called from parent process directly, or as an API call.

stop_task(client, kwargs)

Stops a Task context.

stop_testsuite(client, kwargs)

Stops the TestSuite context. Can only be stopped after all other contexts are stopped.

subscribe_client(client_conn, kwargs)

Subscribes the client to start receiving push updates from the server

unsubscribe_client(client_conn, kwargs)

Unsubscribes the client to stop receiving push updates from the server

pyats.reporter.server.signal_catcher(signum, frame)

Raises a SignalError when catching a handled signal. SignalError inherits from BaseException so it is not handled by general Exception handlers.

pyats.reporter.testsuite.AttrDict_representer(dumper, data)
class pyats.reporter.testsuite.JSONDumper(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: JSONEncoder

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

default(obj)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class pyats.reporter.testsuite.Plugin(**kwargs)

Bases: ReportObjectBase

add_section(**kwargs)
roll_up()
start(**kwargs)
stop(**kwargs)
class pyats.reporter.testsuite.ReportHeader(report)

Bases: object

as_dict()
class pyats.reporter.testsuite.ReportObjectBase(id, seq_num, parent=None, type=None)

Bases: object

add_detail(detail)
dump_json()
dump_yaml()
property fullid
property idlist
roll_up()
start(**kwargs)
stop(**kwargs)
to_dict()
classmethod to_yaml(dumper, data)
update(data)
update_extra(data, list_extend=True)
pyats.reporter.testsuite.ResultCounter_representer(dumper, data)
class pyats.reporter.testsuite.Section(**kwargs)

Bases: ReportObjectBase

add_section(**kwargs)
start(**kwargs)
stop(**kwargs)
class pyats.reporter.testsuite.Task(**kwargs)

Bases: ReportObjectBase

add_plugin(**kwargs)
add_section(**kwargs)
property result
roll_up()
stop(**kwargs)
pyats.reporter.testsuite.TestResult_representer(dumper, data)
class pyats.reporter.testsuite.TestSuite(**kwargs)

Bases: ReportObjectBase

add_plugin(**kwargs)
add_task(**kwargs)
property result
roll_up()
stop(**kwargs)
property testscripts
class pyats.reporter.testsuite.YAMLDumper(stream, default_style=None, default_flow_style=False, canonical=None, indent=None, width=None, allow_unicode=None, line_break=None, encoding=None, explicit_start=None, explicit_end=None, version=None, tags=None, sort_keys=True)

Bases: SafeDumper

ignore_aliases(data)
increase_indent(flow=False, indentless=False)
yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function float_representer>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'pyats.datastructures.attrdict.AttrDict'>: <function AttrDict_representer>, <class 'pyats.reporter.testsuite.Plugin'>: <bound method ReportObjectBase.to_yaml of <class 'pyats.reporter.testsuite.Plugin'>>, <class 'pyats.reporter.testsuite.Section'>: <bound method ReportObjectBase.to_yaml of <class 'pyats.reporter.testsuite.Section'>>, <class 'pyats.reporter.testsuite.Task'>: <bound method ReportObjectBase.to_yaml of <class 'pyats.reporter.testsuite.Task'>>, <class 'pyats.reporter.testsuite.TestSuite'>: <bound method ReportObjectBase.to_yaml of <class 'pyats.reporter.testsuite.TestSuite'>>, <class 'pyats.results.counter.ResultCounter'>: <function ResultCounter_representer>, <class 'pyats.results.result.TestResult'>: <function TestResult_representer>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'str'>: <function str_representer>, <class 'tuple'>: <function SafeRepresenter.represent_list>, <class 'type'>: <function type_representer>, None: <function unknown_representer>}
pyats.reporter.testsuite.float_representer(dumper, data)
pyats.reporter.testsuite.str_representer(dumper, data)
pyats.reporter.testsuite.type_representer(dumper, data)
pyats.reporter.testsuite.unknown_representer(dumper, data)
class pyats.reporter.xmlreport.XMLReport(logsdir, testsuite)

Bases: object

generate_xml(client, kwargs)

Generate the ResultsDetails.xml and ResultsSummary.xml files needed by many other services.

pyats.reporter.xmlreport.escape(string)
pyats.reporter.xmlreport.escape_data(data)