labthings_fastapi.example_things

Example Thing subclasses, used for testing and demonstration purposes.

Most of these are broken in some way and used for testing. These should be moved into the unit tests.

Classes

MyThing

An example Thing with a few affordances.

ThingWithBrokenAffordances

A Thing that raises exceptions in actions/properties.

ThingThatCantInstantiate

A Thing that raises an exception in __init__.

ThingThatCantStart

A Thing that raises an exception in __enter__.

Package Contents

class labthings_fastapi.example_things.MyThing

Bases: labthings_fastapi.thing.Thing

An example Thing with a few affordances.

anaction(repeats: Annotated[int, Field(description='The number of times to try the action')], undocumented: int, title: Annotated[str, Field(description='the title of the invocation')] = 'Untitled', attempts: Annotated[list[str] | None, Field(description='Names for each attempt - I suggest final, Final, FINAL.')] = None) dict[str, str]

Quite a complicated action.

This action has lots of parameters and is designed to confuse my schema generator. I hope it doesn’t!

I might even use some Markdown here:

  • If this renders, it supports lists

  • With at least two items.

There is also a parameter and return block to satisfy docstring validators. This may be preferable to annotations on the arguments.

Parameters:
  • repeats – How many times to do it.

  • undocumented – There’s no description on this field’s type hint.

  • title – A human-readable title.

  • attempts – A list of names of attempts.

Returns:

A dictionary with strings as keys and values.

make_a_dict(extra_key: str | None = None, extra_value: str | None = None) dict[str, str | None]

Do something that returns a dict.

Parameters:
  • extra_key – An additional key.

  • extra_value – An additional value.

Returns:

a dictionary.

increment_counter()

Increment the counter property.

This action doesn’t do very much - all it does, in fact, is increment the counter (which may be read using the counter property).

slowly_increase_counter(increments: int = 60, delay: float = 1)

Increment the counter slowly over a minute.

Parameters:
  • increments – how many times to increment.

  • delay – the wait time between increments.

counter
foo
action_without_arguments() None

Do something that takes no arguments.

action_with_only_kwargs(**kwargs: dict) None

Do something that takes **kwargs.

Parameters:

**kwargs – Keyword arguments.

class labthings_fastapi.example_things.ThingWithBrokenAffordances

Bases: labthings_fastapi.thing.Thing

A Thing that raises exceptions in actions/properties.

broken_action()

Do something that raises an exception.

Raises:

RuntimeError – every time.

broken_property()

Raise an exception when the property is accessed.

Raises:

RuntimeError – every time.

class labthings_fastapi.example_things.ThingThatCantInstantiate

Bases: labthings_fastapi.thing.Thing

A Thing that raises an exception in __init__.

Fail to initialise.

Raises:

RuntimeError – every time.

class labthings_fastapi.example_things.ThingThatCantStart

Bases: labthings_fastapi.thing.Thing

A Thing that raises an exception in __enter__.

__enter__()

Fail to start the thing.

Raises:

RuntimeError – every time.

__exit__(exc_t: Any, exc_v: Any, exc_tb: Any)

Don’t leave the thing as we never entered.

Parameters:
  • exc_t – Exception type.

  • exc_v – Exception value.

  • exc_tb – Traceback.