mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-04 23:09:44 +01:00
* suppress Tqdm when isatty - fixes #2549 * fix tests * unconditionally disable Tqdm if not isatty - fixes https://github.com/iterative/dvc/pull/2550#discussion_r329386950 * add TQDM_DISABLE env var - update tests - add documentation * TQDM_DISABLE => TQDM_ISATTY * tests: mock.patch sys.stderr * TQDM_ISATTY => DVC_ISATTY as per https://github.com/iterative/dvc/pull/2550#discussion_r334565120 * dvc.progress.Tqdm file kwarg - fixes https://github.com/iterative/dvc/pull/2550/files/ad1f245107c405697c4b61fe58a92fc0265c6588#r335706955 * dynamic env DVC_ISATTY - fixes https://github.com/iterative/dvc/pull/2550/files/ad1f245107c405697c4b61fe58a92fc0265c6588#r335811454 * DVC_ISATTY in tests - fixes https://github.com/iterative/dvc/pull/2550/files/ad1f245107c405697c4b61fe58a92fc0265c6588#r335811099 * re-add and abstract `env2bool` to `dvc.utils` - partially reverts commit 524a0df188f566fb3e103f6965f1b6ac9c530886 - fixes https://github.com/iterative/dvc/pull/2550/files/ad1f245107c405697c4b61fe58a92fc0265c6588#r335811639 * env2bool tidy * rename DVC_ISATTY => DVC_IGNORE_ISATTY - fixes https://github.com/iterative/dvc/pull/2550#discussion_r335947382
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import logging
|
|
from dvc.progress import Tqdm
|
|
from dvc.utils import env2bool
|
|
import sys
|
|
import mock
|
|
|
|
|
|
def test_quiet_logging(caplog, capsys):
|
|
with caplog.at_level(logging.CRITICAL, logger="dvc"):
|
|
for _ in Tqdm(range(10)):
|
|
pass
|
|
out_err = capsys.readouterr()
|
|
assert out_err.out == ""
|
|
assert out_err.err == ""
|
|
|
|
|
|
def test_quiet_notty(caplog, capsys):
|
|
with caplog.at_level(logging.INFO, logger="dvc"):
|
|
for _ in Tqdm(range(10)):
|
|
pass
|
|
out_err = capsys.readouterr()
|
|
assert out_err.out == ""
|
|
if env2bool("DVC_IGNORE_ISATTY"):
|
|
assert "0/10" in out_err.err
|
|
else:
|
|
assert out_err.err == ""
|
|
|
|
|
|
def test_default(caplog, capsys):
|
|
with caplog.at_level(logging.INFO, logger="dvc"):
|
|
# simulate interactive terminal
|
|
with mock.patch.object(sys.stderr, "isatty", return_value=True):
|
|
for _ in Tqdm(range(10)):
|
|
pass
|
|
out_err = capsys.readouterr()
|
|
assert out_err.out == ""
|
|
assert "0/10" in out_err.err
|