Skip to content

Commit

Permalink
add errors stream_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed May 9, 2024
1 parent 76ad03c commit 82880c7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Inform — Print & Logging Utilities
==================================

|build status| |downloads| |rtd status| |coverage| |pypi version| |anaconda version| |python version|
|downloads| |build status| |coverage| |rtd status| |pypi version| |anaconda version| |python version|

:Author: Ken Kundert
:Version: 1.29
Expand Down
4 changes: 3 additions & 1 deletion inform/inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
# stderr is used on final termination message
'header': lambda i, so, se: se if i.severity else so,
# stderr is used on all messages that include headers
'errors': lambda i, so, se: se if i.is_error else so,
# stderr is used on all errors
}
BAR_CHARS = '▏▎▍▌▋▊▉█'
NUM_BAR_CHARS = len(BAR_CHARS)
Expand Down Expand Up @@ -1355,7 +1357,7 @@ def columns(
The minimum number of spaces between columns. Default is 2.
min_col_width (int):
The minimum number of spaces between columns. Default is 1.
The minimum width of a column. Default is 1.
**Example**::
Expand Down
47 changes: 42 additions & 5 deletions tests/test_inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,55 @@ def test_possess():
'hey now!',
'hey now!',
]
wrn = [
'Aiko aiko all day',
'jockomo feeno na na nay',
'jockomo feena nay.',
]
err = [
"My spy dog saw you spy dog sittin' by the fi-yo.",
]
display(*out)
warn(*wrn, sep=', ')
error(*err, sep=', ')

assert msg.errors_accrued() == 1
assert errors_accrued(True) == 1
assert strip(stdout) == '\n'.join([
' '.join(out),
])
assert strip(stderr) == '\n'.join([
'warning: ' + ', '.join(wrn),
'error: ' + ', '.join(err)
])

def test_bower():
with messenger(stream_policy='errors') as (msg, stdout, stderr, logfile):
out = [
'hey now!',
'hey now!',
]
wrn = [
'Aiko aiko all day',
'jockomo feeno na na nay',
'jockomo feena nay.',
]
err = [
"My spy dog saw you spy dog sittin' by the fi-yo.",
]
display(*out)
warn(*err, sep=', ')
warn(*wrn, sep=', ')
error(*err, sep=', ')

assert msg.errors_accrued() == 0
assert errors_accrued(True) == 0
assert strip(stdout) == ' '.join(out)
assert strip(stderr) == 'warning: ' + ', '.join(err)
assert msg.errors_accrued() == 1
assert errors_accrued(True) == 1
assert strip(stdout) == '\n'.join([
' '.join(out),
'warning: ' + ', '.join(wrn)
])
assert strip(stderr) == '\n'.join([
'error: ' + ', '.join(err)
])

def test_unbuckle():
with messenger() as (msg, stdout, stderr, logfile):
Expand Down

0 comments on commit 82880c7

Please sign in to comment.