Skip to content
Snippets Groups Projects
Commit 8b88f0e4 authored by Ximin Luo's avatar Ximin Luo
Browse files

Fix create_limited_print_func

parent 1480faf1
No related branches found
No related tags found
Loading
......@@ -82,16 +82,16 @@ def make_printer(path):
output.close()
def create_limited_print_func(print_func, max_page_size):
count = 0
count = [0]
def fn(val, force=False, count=count):
def fn(val, force=False):
print_func(val)
if force or max_page_size == 0:
return
count += len(val)
if count >= max_page_size:
count[0] += len(val)
if count[0] >= max_page_size:
raise PrintLimitReached()
return fn
......@@ -22,6 +22,7 @@ import re
import pytest
from diffoscope.main import main
from diffoscope.presenters.utils import create_limited_print_func, PrintLimitReached
from .utils.data import cwd_data, get_data
......@@ -137,3 +138,16 @@ def test_html_option_with_stdout(capsys):
out = run(capsys, '--html', '-')
assert extract_body(out) == extract_body(get_data('output.html'))
def test_limited_print():
fake = lambda x: None
with pytest.raises(PrintLimitReached):
p = create_limited_print_func(fake, 5)
p("123456")
with pytest.raises(PrintLimitReached):
p = create_limited_print_func(fake, 5)
p("123")
p("456")
p = create_limited_print_func(fake, 5)
p("123")
p("456", force=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment