Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
8b88f0e4
Commit
8b88f0e4
authored
7 years ago
by
Ximin Luo
Browse files
Options
Downloads
Patches
Plain Diff
Fix create_limited_print_func
parent
1480faf1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diffoscope/presenters/utils.py
+4
-4
4 additions, 4 deletions
diffoscope/presenters/utils.py
tests/test_presenters.py
+14
-0
14 additions, 0 deletions
tests/test_presenters.py
with
18 additions
and
4 deletions
diffoscope/presenters/utils.py
+
4
−
4
View file @
8b88f0e4
...
...
@@ -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
This diff is collapsed.
Click to expand it.
tests/test_presenters.py
+
14
−
0
View file @
8b88f0e4
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment