greentea package

A microframework for abstraction.

Submodules

greentea.batch_template module

Expose the template class for entrypoints.

class greentea.batch_template.BaseBatch(parser: greentea.parser.BaseParser)[source]

Bases: object

Provide a template method for entrypoints.

run()[source]

Create a service and run it.

greentea.factory module

Provide factories that create objects.

class greentea.factory.BaseFactory(namespace: argparse.Namespace)[source]

Bases: object

An abstract-factory class.

abstract create_arguments() → dict[source]

Create the arguments for the service.

abstract create_log_configuration() → greentea.log.LogConfiguration[source]

Create an instance to configure the logging system.

abstract create_service() → greentea.service.BaseService[source]

Create a service.

greentea.log module

Configure the logging system for snippets.

class greentea.log.LogConfiguration(verbose: bool, name: str)[source]

Bases: object

Logging configuration.

verbose
Type

bool

name
Type

str

configure() → None[source]

Update the logging level of name logger.

greentea.parser module

Expose base classes for parseing command-line arguments.

class greentea.parser.BaseParser[source]

Bases: object

An abstract class for parsing command-line arguments.

abstract classmethod create_base_parser() → argparse.ArgumentParser[source]

Create a parser that will take the command-line arguments.

abstract create_factory(namespace: argparse.Namespace) → greentea.factory.BaseFactory[source]

Create a factory from a parsed command-line properties.

abstract define_parser() → argparse.ArgumentParser[source]

Define a command.

parse(arguments: Sequence[str]) → greentea.factory.BaseFactory[source]

Interpret the command-line arguments.

Create a factory object to prepare objects required by a service class that extends greentea.service.BaseService.

greentea.service module

Expose the Use case template class.

class greentea.service.BaseService[source]

Bases: object

A template class for an use case.

abstract run(**kwargs) → Any[source]

Execute the use case.

greentea.trace module

Provide methods to trace execution.

class greentea.trace.Invocation(invocation: Tuple[Callable, Tuple, dict], start_time: datetime.datetime)[source]

Bases: object

Record an invocation of a function.

build_end_message(return_value: Any) → str[source]

Create a message that this invocation has ended.

build_start_message() → str[source]

Create a message that represents this invocation.

classmethod create_from(function: Callable, args: Tuple, kwargs: dict)[source]

Record the time when a function is called.

Returns

trace

Return type

Trace

class greentea.trace.TraceLevel(start_level: int = 10, end_level: int = 10)[source]

Bases: object

Represent logging levels for tracing executions.

end(logger: logging.Logger, invocation: greentea.trace.Invocation, return_value: Any) → None[source]

Record that the function has end.

end_level = 10
start(logger: logging.Logger, invocation: greentea.trace.Invocation) → None[source]

Record trace with logger.

start_level = 10
class greentea.trace.Tracer(logger: logging.Logger, trace_level: greentea.trace.TraceLevel)[source]

Bases: object

Record information about a program’s execution.

classmethod create_tracer(logger_name: str = 'trace', format_string: str = '%(levelname)s:%(asctime)s:%(name)s:%(message)s', level: int = 10, trace_level: greentea.trace.TraceLevel = TraceLevel(start_level=10, end_level=10))[source]

Create a tracer named with logger_name.

Returns

tracer

Return type

Tracer

trace(function: Callable)[source]

Provide a function decorator to trace the decorated function.