Skip to content
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

Rename classes whose name starts with Test #411

Merged
merged 1 commit into from
Dec 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ def fail_health_check(message, label):
perform_health_check = settings.perform_health_check
perform_health_check &= Settings.default.perform_health_check

from hypothesis.internal.conjecture.data import TestData, Status, \
StopTest
from hypothesis.internal.conjecture.data import ConjectureData, \
Status, StopTest
if not (
Phase.reuse in settings.phases or
Phase.generate in settings.phases
Expand All @@ -328,7 +328,7 @@ def fail_health_check(message, label):
# time to calculate any cached data. This prevents the case
# where the first draw of the health check takes ages because
# of loading unicode data the first time.
data = TestData(
data = ConjectureData(
max_length=settings.buffer_size,
draw_bytes=lambda data, n, distribution:
distribution(health_check_random, n)
Expand All @@ -350,7 +350,7 @@ def fail_health_check(message, label):
filtered_draws < 50 and overruns < 20
):
try:
data = TestData(
data = ConjectureData(
max_length=settings.buffer_size,
draw_bytes=lambda data, n, distribution:
distribution(health_check_random, n)
Expand Down Expand Up @@ -463,12 +463,12 @@ def evaluate_test_data(data):
verbose_report(last_exception[0])
data.mark_interesting()

from hypothesis.internal.conjecture.engine import TestRunner
from hypothesis.internal.conjecture.engine import ConjectureRunner

falsifying_example = None
database_key = str_to_bytes(fully_qualified_name(test))
start_time = time.time()
runner = TestRunner(
runner = ConjectureRunner(
evaluate_test_data,
settings=settings, random=random,
database_key=database_key,
Expand Down Expand Up @@ -518,7 +518,7 @@ def evaluate_test_data(data):
try:
with settings:
test_runner(
TestData.for_buffer(falsifying_example),
ConjectureData.for_buffer(falsifying_example),
reify_and_execute(
search_strategy, test,
print_example=True, is_final=True
Expand Down Expand Up @@ -546,7 +546,7 @@ def evaluate_test_data(data):

try:
test_runner(
TestData.for_buffer(falsifying_example),
ConjectureData.for_buffer(falsifying_example),
reify_and_execute(
search_strategy,
test_is_flaky(test, repr_for_last_exception[0]),
Expand Down Expand Up @@ -621,19 +621,19 @@ def template_condition(data):
last_data[0] = data
if success and not data.frozen:
data.mark_interesting()
from hypothesis.internal.conjecture.engine import TestRunner
from hypothesis.internal.conjecture.data import TestData, Status
from hypothesis.internal.conjecture.engine import ConjectureRunner
from hypothesis.internal.conjecture.data import ConjectureData, Status

start = time.time()
runner = TestRunner(
runner = ConjectureRunner(
template_condition, settings=settings, random=random,
database_key=database_key,
)
runner.run()
note_engine_for_statistics(runner)
run_time = time.time() - start
if runner.last_data.status == Status.INTERESTING:
data = TestData.for_buffer(runner.last_data.buffer)
data = ConjectureData.for_buffer(runner.last_data.buffer)
with BuildContext(data):
return data.draw(search)
if runner.valid_examples <= settings.min_satisfying_examples:
Expand Down
4 changes: 2 additions & 2 deletions src/hypothesis/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ class HypothesisDeprecationWarning(HypothesisException, DeprecationWarning):

class Frozen(HypothesisException):

"""Raised when a mutation method has been called on a TestData object after
freeze() has been called."""
"""Raised when a mutation method has been called on a ConjectureData object
after freeze() has been called."""
4 changes: 2 additions & 2 deletions src/hypothesis/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def default_new_style_executor(data, function):
return function(data)


class TestRunner(object):
class ConjectureRunner(object):

def hypothesis_execute_example_with_data(self, data, function):
return function(data)
Expand All @@ -67,7 +67,7 @@ def hypothesis_execute_example_with_data(self, data, function):
def new_style_executor(runner):
if runner is None:
return default_new_style_executor
if isinstance(runner, TestRunner):
if isinstance(runner, ConjectureRunner):
return runner.hypothesis_execute_example_with_data

old_school = executor(runner)
Expand Down
6 changes: 3 additions & 3 deletions src/hypothesis/internal/conjecture/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def __init__(self, testcounter):
global_test_counter = 0


class TestData(object):
class ConjectureData(object):

@classmethod
def for_buffer(self, buffer):
return TestData(
return ConjectureData(
max_length=len(buffer),
draw_bytes=lambda data, n, distribution:
buffer[data.index:data.index + n]
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(self, max_length, draw_bytes):
def __assert_not_frozen(self, name):
if self.frozen:
raise Frozen(
'Cannot call %s on frozen TestData' % (
'Cannot call %s on frozen ConjectureData' % (
name,))

@property
Expand Down
15 changes: 8 additions & 7 deletions src/hypothesis/internal/conjecture/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
from hypothesis.reporting import debug_report
from hypothesis.internal.compat import hbytes, hrange, Counter, \
text_type, bytes_from_list, to_bytes_sequence, unicode_safe_repr
from hypothesis.internal.conjecture.data import Status, StopTest, TestData
from hypothesis.internal.conjecture.data import Status, StopTest, \
ConjectureData
from hypothesis.internal.conjecture.minimizer import minimize


Expand All @@ -44,7 +45,7 @@ class RunIsComplete(Exception):
pass


class TestRunner(object):
class ConjectureRunner(object):

def __init__(
self, test_function, settings=None, random=None,
Expand All @@ -67,7 +68,7 @@ def __init__(
self.events_to_strings = WeakKeyDictionary()

def new_buffer(self):
self.last_data = TestData(
self.last_data = ConjectureData(
max_length=self.settings.buffer_size,
draw_bytes=lambda data, n, distribution:
distribution(self.random, n)
Expand Down Expand Up @@ -172,7 +173,7 @@ def incorporate_new_buffer(self, buffer):
if sort_key(buffer) >= sort_key(self.last_data.buffer):
return False
assert sort_key(buffer) <= sort_key(self.last_data.buffer)
data = TestData.for_buffer(buffer)
data = ConjectureData.for_buffer(buffer)
self.test_function(data)
if self.consider_new_test_data(data):
self.shrinks += 1
Expand Down Expand Up @@ -283,7 +284,7 @@ def _run(self):
):
self.exit_reason = ExitReason.max_iterations
return
data = TestData.for_buffer(existing)
data = ConjectureData.for_buffer(existing)
self.test_function(data)
data.freeze()
self.last_data = data
Expand Down Expand Up @@ -332,7 +333,7 @@ def _run(self):
self.new_buffer()
mutator = self._new_mutator()
else:
data = TestData(
data = ConjectureData(
draw_bytes=mutator,
max_length=self.settings.buffer_size
)
Expand Down Expand Up @@ -366,7 +367,7 @@ def _run(self):
self.exit_reason = ExitReason.finished
return

data = TestData.for_buffer(self.last_data.buffer)
data = ConjectureData.for_buffer(self.last_data.buffer)
self.test_function(data)
if data.status != Status.INTERESTING:
self.exit_reason = ExitReason.flaky
Expand Down
43 changes: 23 additions & 20 deletions tests/cover/test_conjecture_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
from hypothesis.database import ExampleDatabase
from hypothesis.internal.compat import hbytes, int_from_bytes, \
bytes_from_list
from hypothesis.internal.conjecture.data import Status, TestData
from hypothesis.internal.conjecture.engine import TestRunner
from hypothesis.internal.conjecture.data import Status, ConjectureData
from hypothesis.internal.conjecture.engine import ConjectureRunner

MAX_SHRINKS = 2000


def run_to_buffer(f):
runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
max_examples=5000, max_iterations=10000, max_shrinks=MAX_SHRINKS,
buffer_size=1024,
database=None,
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_can_load_data_from_a_corpus():
def f(data):
if data.draw_bytes(len(value)) == value:
data.mark_interesting()
runner = TestRunner(
runner = ConjectureRunner(
f, settings=settings(database=db), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
Expand All @@ -144,7 +144,7 @@ def tf(data):
if sum(x) >= 500:
shrinks[0] += 1
data.mark_interesting()
runner = TestRunner(tf, settings=settings(
runner = ConjectureRunner(tf, settings=settings(
max_examples=5000, max_iterations=10000, max_shrinks=10,
database=None,
))
Expand All @@ -165,7 +165,7 @@ def tf(data):
if not failed_once[0]:
failed_once[0] = True
data.mark_interesting()
runner = TestRunner(tf)
runner = ConjectureRunner(tf)
runner.run()
assert count == [2]

Expand All @@ -187,7 +187,7 @@ def draw_list(data):
def b(data):
if any(all(d) for d in draw_list(data)):
data.mark_interesting()
l = draw_list(TestData.for_buffer(b))
l = draw_list(ConjectureData.for_buffer(b))
assert len(l) == 1
assert len(l[0]) == 1

Expand All @@ -207,7 +207,7 @@ def f(data):
i = int_from_bytes(data.draw_bytes(2))
data.draw_bytes(i)
data.mark_interesting()
runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
max_examples=5000, max_iterations=10000,
buffer_size=2,
database=None,
Expand All @@ -231,7 +231,7 @@ def f(data):
seen.append(data.draw_bytes(len(value)))
data.mark_invalid()

runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
max_examples=1, max_iterations=max_iterations,
database=db,
), database_key=key)
Expand All @@ -254,7 +254,7 @@ def f(data):
seen.append(data.draw_bytes(1))
data.mark_invalid()

runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
max_examples=1, max_iterations=max_iterations,
database=db,
), database_key=key)
Expand All @@ -274,7 +274,7 @@ def test_stops_after_max_examples_when_reading():
def f(data):
seen.append(data.draw_bytes(1))

runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
max_examples=1,
database=db,
), database_key=key)
Expand All @@ -288,7 +288,7 @@ def test_stops_after_max_examples_when_generating():
def f(data):
seen.append(data.draw_bytes(1))

runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
max_examples=1,
database=None,
))
Expand All @@ -311,7 +311,7 @@ def g(d2):
d2.mark_interesting()
if 0 in result:
d2.mark_invalid()
runner = TestRunner(g, random=rnd)
runner = ConjectureRunner(g, random=rnd)
runner.run()
if runner.last_data.status == Status.INTERESTING:
data.mark_interesting()
Expand All @@ -325,7 +325,8 @@ def f(data):
if any(x):
data.mark_interesting()

runner = TestRunner(f, settings=settings(database=None, timeout=0.2,))
runner = ConjectureRunner(
f, settings=settings(database=None, timeout=0.2,))
start = time.time()
runner.run()
assert time.time() <= start + 1
Expand All @@ -336,7 +337,8 @@ def test_run_with_timeout_while_boring():
def f(data):
time.sleep(0.1)

runner = TestRunner(f, settings=settings(database=None, timeout=0.2,))
runner = ConjectureRunner(
f, settings=settings(database=None, timeout=0.2,))
start = time.time()
runner.run()
assert time.time() <= start + 1
Expand All @@ -350,7 +352,8 @@ def f(data):
seen.add(hbytes(data.draw_bytes(32)))
data.mark_interesting()

runner = TestRunner(f, settings=settings(database=None, max_shrinks=0,))
runner = ConjectureRunner(
f, settings=settings(database=None, max_shrinks=0,))
runner.run()
assert len(seen) == 1

Expand All @@ -362,7 +365,7 @@ def f(data):
seen.add(hbytes(data.draw_bytes(32)))
data.mark_interesting()

runner = TestRunner(f, settings=settings(
runner = ConjectureRunner(f, settings=settings(
database=None, phases=(Phase.reuse, Phase.generate),
))
runner.run()
Expand All @@ -382,7 +385,7 @@ def f(data):
seen.add(hbytes(x))
if hbytes(x) in seen:
data.mark_interesting()
runner = TestRunner(
runner = ConjectureRunner(
f, settings=settings(database=db), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
Expand Down Expand Up @@ -444,14 +447,14 @@ def f(data):
seen.add(x)
if x in seen:
data.mark_interesting()
runner = TestRunner(
runner = ConjectureRunner(
f, settings=settings(database=db, max_shrinks=2 * n), database_key=key)
runner.run()
assert runner.last_data.status == Status.INTERESTING
assert len(seen) == n
assert set(db.fetch(key)) == seen
go = False
runner = TestRunner(
runner = ConjectureRunner(
f, settings=settings(database=db, max_shrinks=2 * n), database_key=key)
runner.run()
assert 0 < len(set(db.fetch(key))) < n
Expand Down
Loading