def test_can_build_lines_out_of_widgets(mocker): expected_width = 90 mock_term_size(mocker, expected_width) line = pycp.progress.Line() counter = pycp.progress.Counter() percent = pycp.progress.Percent() bar = pycp.progress.Bar() speed = pycp.progress.Speed() bold = Bold() eta = pycp.progress.ETA() blue = Blue() brown = Brown() lightgray = LightGray() reset = Reset() standout = Standout() space = Text(" ") dash = Text(" - ") pipe = Text(" | ") line.set_components([ blue, counter, reset, space, bold, percent, reset, space, lightgray, bar, reset, dash, standout, speed, reset, pipe, brown, eta, reset, ]) out = line.render( index=1, count=3, current_value=20, max_value=100, elapsed=10, ) print(out)
def test_output_does_not_wrap_1(test_dir, capsys, mocker): "Not using --global" a_file = os.path.join(test_dir, "a_file") a_file_back = os.path.join(test_dir, "a_file.back") expected_width = 90 mock_term_size(mocker, expected_width) sys.argv = ["pycp", a_file, a_file_back] pycp_main() out, err = capsys.readouterr() lines = re.split(r"\r|\n", out) for line in lines: assert len(strip_ansi_colors(line)) <= expected_width
def test_output_does_not_wrap_2(test_dir, capsys, mocker): "Using --global" "a_dir -> b_dir (b_dir does not exist)" expected_width = 90 mock_term_size(mocker, expected_width) a_dir = os.path.join(test_dir, "a_dir") b_dir = os.path.join(test_dir, "b_dir") sys.argv = ["pycp", "--global", a_dir, b_dir] pycp_main() out, err = capsys.readouterr() lines = re.split(r"\r|\n", out) for line in lines: assert len(strip_ansi_colors(line)) <= expected_width
def test_output_does_not_wrap_2( test_dir: str, capsys: typing.Any, mocker: typing.Any ) -> None: """ When using --global, each printed line length should be less that the terminal size """ expected_width = 90 mock_term_size(mocker, expected_width) a_dir = os.path.join(test_dir, "a_dir") b_dir = os.path.join(test_dir, "b_dir") sys.argv = ["pycp", "--global", a_dir, b_dir] pycp_main() out, err = capsys.readouterr() lines = re.split(r"\r|\n", out) for line in lines: assert len(strip_ansi_colors(line)) <= expected_width
def test_output_does_not_wrap_1( test_dir: str, capsys: typing.Any, mocker: typing.Any ) -> None: """ When not using --global, each printed line length should be less that the terminal size """ # and we'll trigger this bug: # https://github.com/dmerejkowsky/pycp/issues/29 a_file = os.path.join(test_dir, "a_file") a_file_back = os.path.join(test_dir, "a_file.back") expected_width = 90 mock_term_size(mocker, expected_width) sys.argv = ["pycp", a_file, a_file_back] pycp_main() out, err = capsys.readouterr() lines = re.split(r"\r|\n", out) for line in lines: assert len(strip_ansi_colors(line)) <= expected_width
def test_global_indicator(mocker: typing.Any) -> None: expected_width = 90 mock_term_size(mocker, expected_width) global_indicator = GlobalIndicator() progress = pycp.progress.Progress() progress.index = 2 progress.count = 3 progress.src = "src/foo" progress.dest = "dest/foo" progress.file_size = 100 global_indicator.on_new_file(progress) global_indicator.on_progress(progress) global_indicator.on_file_done() progress.src = "src/bar" progress.dest = "dest/bar" global_indicator.on_new_file(progress) global_indicator.on_progress(progress) global_indicator.on_file_done() global_indicator.on_finish()