New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the ability to run a single shrink pass #2033
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RELEASE_TYPE: patch | ||
|
||
This release removes some defunct internal functionality that was only being used | ||
for testing. It should have no user visible impact. |
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 |
---|---|---|
|
@@ -479,14 +479,18 @@ def shrinker(data): | |
# We normally would have populated this in minimize_individual_blocks | ||
shrinker.is_shrinking_block = lambda x: True | ||
|
||
fixate(Shrinker.example_deletion_with_block_lowering)(shrinker) | ||
shrinker.fixate_shrink_passes(["example_deletion_with_block_lowering"]) | ||
|
||
assert list(shrinker.shrink_target.buffer) == [1, 1] | ||
|
||
|
||
def test_deletion_and_lowering_fails_to_shrink(monkeypatch): | ||
monkeypatch.setattr( | ||
Shrinker, "shrink", Shrinker.example_deletion_with_block_lowering | ||
Shrinker, | ||
"shrink", | ||
lambda self: self.fixate_shrink_passes( | ||
["example_deletion_with_block_lowering"] | ||
), | ||
) | ||
# Would normally be added by minimize_individual_blocks, but we skip | ||
# that phase in this test. | ||
|
@@ -761,16 +765,6 @@ def x(data): | |
assert x == hbytes(hbytes([1]) * 10) | ||
|
||
|
||
def fixate(f): | ||
def accept(self): | ||
prev = None | ||
while self.shrink_target is not prev: | ||
prev = self.shrink_target | ||
f(self) | ||
|
||
return accept | ||
|
||
|
||
def test_can_remove_discarded_data(): | ||
@shrinking_from(hbytes([0] * 10) + hbytes([11])) | ||
def shrinker(data): | ||
|
@@ -813,13 +807,6 @@ def shrinker(data): | |
assert shrinker.shrink_target.has_discards | ||
|
||
|
||
def shrink_pass(name): | ||
def run(self): | ||
self.run_shrink_pass(name) | ||
|
||
return run | ||
|
||
|
||
def test_discarding_can_fail(monkeypatch): | ||
@shrinking_from(hbytes([1])) | ||
def shrinker(data): | ||
|
@@ -936,11 +923,8 @@ def shrink(buffer, *passes): | |
def accept(f): | ||
shrinker = shrinking_from(buffer)(f) | ||
|
||
prev = None | ||
while shrinker.shrink_target is not prev: | ||
prev = shrinker.shrink_target | ||
for p in passes: | ||
shrinker.run_shrink_pass(p) | ||
shrinker.fixate_shrink_passes(passes) | ||
|
||
return list(shrinker.buffer) | ||
|
||
return accept | ||
|
@@ -954,10 +938,8 @@ def shrinker(data): | |
if abs(m - n) <= 1 and max(m, n) > 0: | ||
data.mark_interesting() | ||
|
||
# Run minimize_individual_blocks twice so we have both blocks show | ||
# as changed regardless of which order this happens in. | ||
shrinker.minimize_individual_blocks() | ||
shrinker.minimize_individual_blocks() | ||
shrinker.mark_changed(0) | ||
shrinker.mark_changed(1) | ||
shrinker.lower_common_block_offset() | ||
|
||
x = shrinker.shrink_target.buffer | ||
|
@@ -966,7 +948,11 @@ def shrinker(data): | |
|
||
|
||
def test_handle_empty_draws(monkeypatch): | ||
monkeypatch.setattr(Shrinker, "shrink", Shrinker.adaptive_example_deletion) | ||
monkeypatch.setattr( | ||
Shrinker, | ||
"shrink", | ||
lambda self: self.fixate_shrink_passes(["adaptive_example_deletion"]), | ||
) | ||
|
||
@run_to_buffer | ||
def x(data): | ||
|
@@ -1005,17 +991,9 @@ def f(data): | |
assert runner.exit_reason == ExitReason.finished | ||
|
||
|
||
def test_can_reorder_examples(monkeypatch): | ||
monkeypatch.setattr( | ||
ConjectureRunner, | ||
"generate_new_examples", | ||
lambda runner: runner.cached_test_function([1, 0, 1, 1, 0, 1, 0, 0, 0]), | ||
) | ||
|
||
monkeypatch.setattr(Shrinker, "shrink", Shrinker.reorder_examples) | ||
|
||
@run_to_buffer | ||
def x(data): | ||
def test_can_reorder_examples(): | ||
@shrinking_from([1, 0, 1, 1, 0, 1, 0, 0, 0]) | ||
def shrinker(data): | ||
total = 0 | ||
for _ in range(5): | ||
data.start_example(0) | ||
|
@@ -1025,7 +1003,9 @@ def x(data): | |
if total == 2: | ||
data.mark_interesting() | ||
|
||
assert list(x) == [0, 0, 0, 1, 0, 1, 1, 0, 1] | ||
shrinker.fixate_shrink_passes(["reorder_examples"]) | ||
|
||
assert list(shrinker.buffer) == [0, 0, 0, 1, 0, 1, 1, 0, 1] | ||
|
||
|
||
def test_permits_but_ignores_raising_order(monkeypatch): | ||
|
@@ -1058,8 +1038,7 @@ def shrinker(data): | |
if n == 4: | ||
data.mark_interesting() | ||
|
||
for i in range(1, 5): | ||
shrinker.run_shrink_pass(block_program("X" * i)) | ||
shrinker.fixate_shrink_passes([block_program("X" * i) for i in range(1, 5)]) | ||
assert list(shrinker.shrink_target.buffer) == [0, 4] * 5 | ||
|
||
|
||
|
@@ -1128,7 +1107,7 @@ def shrinker(data): | |
if result >= 32768 and cap == 1: | ||
data.mark_interesting() | ||
|
||
shrinker.minimize_individual_blocks() | ||
shrinker.fixate_shrink_passes(["minimize_individual_blocks"]) | ||
assert list(shrinker.shrink_target.buffer) == [1, 1, 0, 1, 0, 0, 1] | ||
|
||
|
||
|
@@ -1272,7 +1251,7 @@ def shrinker(data): | |
if n == 1: | ||
data.mark_interesting() | ||
|
||
shrinker.minimize_individual_blocks() | ||
shrinker.fixate_shrink_passes(["minimize_individual_blocks"]) | ||
assert list(shrinker.shrink_target.buffer) == [0, 1] | ||
|
||
|
||
|
@@ -1285,7 +1264,7 @@ def shrinker(data): | |
else: | ||
data.draw_bits(8) | ||
|
||
shrinker.minimize_individual_blocks() | ||
shrinker.fixate_shrink_passes(["minimize_individual_blocks"]) | ||
|
||
|
||
def test_zero_examples_will_zero_blocks(): | ||
|
@@ -1297,7 +1276,7 @@ def shrinker(data): | |
if n == m == 1: | ||
data.mark_interesting() | ||
|
||
shrinker.run_shrink_pass("zero_examples") | ||
shrinker.fixate_shrink_passes(["zero_examples"]) | ||
assert list(shrinker.shrink_target.buffer) == [1, 0, 1] | ||
|
||
|
||
|
@@ -1314,7 +1293,7 @@ def shrinker(data): | |
data.draw_bits(16) | ||
data.mark_interesting() | ||
|
||
shrinker.minimize_individual_blocks() | ||
shrinker.fixate_shrink_passes(["minimize_individual_blocks"]) | ||
assert list(shrinker.shrink_target.buffer) == [0, 0, 0] | ||
|
||
|
||
|
@@ -1360,7 +1339,7 @@ def shrinker(data): | |
if data.draw_bits(8) == 7: | ||
data.mark_interesting() | ||
|
||
shrinker.run_shrink_pass(block_program("-XX")) | ||
shrinker.fixate_shrink_passes([block_program("-XX")]) | ||
assert list(shrinker.shrink_target.buffer) == [1, 7] | ||
|
||
|
||
|
@@ -1477,7 +1456,7 @@ def shrinker(data): | |
if hbytes(data.buffer) == base_buf: | ||
data.mark_interesting() | ||
|
||
shrinker.minimize_floats() | ||
shrinker.fixate_shrink_passes(["minimize_floats"]) | ||
|
||
assert shrinker.shrink_target.buffer == base_buf | ||
|
||
|
@@ -1539,25 +1518,6 @@ def shrinker(data): | |
assert shrinker.calls <= 60 | ||
|
||
|
||
def test_zero_examples_does_not_try_to_adapt_across_different_sizes(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this test because I couldn't figure out a sensible way to adapt it and it seemed fragile and hyper-specific. |
||
@shrinking_from([1, 0, 0] * 10 + [1]) | ||
def shrinker(data): | ||
for _ in hrange(10): | ||
data.draw_bits(1) | ||
data.draw_bits(16) | ||
if data.draw_bits(1): | ||
data.mark_interesting() | ||
|
||
initial = shrinker.calls | ||
shrinker.zero_examples() | ||
assert shrinker.shrink_target.buffer == hbytes(30) + hbytes([1]) | ||
|
||
# Tried each of the 1-bit blocks, plus the whole example, plus the final | ||
# single-bit block. Did not try to expand regions into the trivial two-byte | ||
# blocks on each side. | ||
assert shrinker.calls == initial + 12 | ||
|
||
|
||
def test_stable_identifiers_match_their_examples(): | ||
def tree(data): | ||
data.start_example(1) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what's causing the coverage failure, so presumably it just needs to be suppressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. I thought the
assert False
was automatically a coverage exclusion. Oh well, easy enough to add the pragma.