Skip to content

Commit

Permalink
Refine the documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Dec 23, 2017
1 parent 2e811ee commit 80cfbc7
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions inform/inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,22 +855,47 @@ class InformantFactory:
specified, the stream to use will be determine by stream policy of
active informer.
Example:
The following generates an informant named *show* that outputs
messages to both standare output and to the logfile. Output to the
standard output is suppressed if *mute* is *True*::
show = InformantFactory(
output=lambda inform: not inform.mute,
log=True,
)
*show* is an informant. Once created, it can be used to give
messages to the user::
show('Hey there!')
Example:
The following generates two informants, *pass*, which prints its
messages in green, and *fail*, which prints its messages in red. Output
to the standard output for both is suppressed if *quiet* is *True*::
>>> from inform import InformantFactory, Inform
>>> passes = InformantFactory(
... output=lambda inform: not inform.quiet,
... log=True,
... message_color='green',
... )
>>> fails = InformantFactory(
... output=lambda inform: not inform.quiet,
... log=True,
... message_color='red',
... )
*pass* and *fail* are both informants. Once created, the can be used to
give messages to the user::
>>> results = [
... (0, 0.005, 0.025),
... (0.5, 0.512, 0.025),
... (1, 0.875, 0.025),
... ]
>>> for expected, measured, tolerance in results:
... if abs(expected - measured) > tolerance:
... report, label = fails, 'FAIL'
... else:
... report, label = passes, 'Pass'
... report(
... label, measured, expected, measured-expected,
... template='{}: measured = {:.3f}V, expected = {:.3f}V, diff = {:.3f}V'
... )
Pass: measured = 0.005V, expected = 0.000V, diff = 0.005V
Pass: measured = 0.512V, expected = 0.500V, diff = 0.012V
FAIL: measured = 0.875V, expected = 1.000V, diff = -0.125V
The passes are rendered in green and the failures in red.
"""

def __init__(
Expand Down

0 comments on commit 80cfbc7

Please sign in to comment.