forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sagemath#130 from marcelotrevisani/fb-125-disable-…
…output Add possibility to disable output
- Loading branch information
Showing
9 changed files
with
116 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from contextlib import contextmanager | ||
from copy import deepcopy | ||
|
||
from progressbar import ProgressBar | ||
|
||
from grayskull.cli import WIDGET_BAR_DOWNLOAD, CLIConfig | ||
|
||
|
||
def print_msg(msg: str): | ||
if CLIConfig().stdout: | ||
print(msg) | ||
|
||
|
||
@contextmanager | ||
def manage_progressbar(*, max_value: int, prefix: str): | ||
if CLIConfig().stdout: | ||
with ProgressBar( | ||
widgets=deepcopy(WIDGET_BAR_DOWNLOAD), max_value=max_value, prefix=prefix, | ||
) as bar: | ||
yield bar | ||
else: | ||
|
||
class DisabledBar: | ||
def update(self, *args, **kargs): | ||
pass | ||
|
||
yield DisabledBar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from progressbar import ProgressBar | ||
|
||
from grayskull.cli import CLIConfig | ||
from grayskull.cli.stdout import manage_progressbar, print_msg | ||
|
||
|
||
def test_print_stdout(capsys): | ||
CLIConfig().stdout = True | ||
print_msg("TEST-OUTPUT") | ||
captured_out = capsys.readouterr() | ||
assert captured_out.out == "TEST-OUTPUT\n" | ||
|
||
|
||
def test_disabled_print(capsys): | ||
CLIConfig().stdout = False | ||
print_msg("TEST-OUTPUT") | ||
captured_out = capsys.readouterr() | ||
assert captured_out.out == "" | ||
|
||
|
||
def test_progressbar_enable(): | ||
CLIConfig().stdout = True | ||
with manage_progressbar(max_value=100, prefix="prefix-") as bar: | ||
assert isinstance(bar, ProgressBar) | ||
|
||
|
||
def test_progressbar_disable(): | ||
CLIConfig().stdout = False | ||
with manage_progressbar(max_value=100, prefix="prefix-") as bar: | ||
assert not isinstance(bar, ProgressBar) |