9 from hypothesis.strategies
import text, integers, composite, sampled_from, booleans
13 def text_lineno(draw):
15 lineno = draw(integers(min_value=1, max_value=t.count(
"\n") + 1))
20 @hypothesis.given(text_lineno())
21 def test_nth_line_ref(self, t_lineno):
23 hypothesis.event(
"lineno = {}".format(lineno))
25 def nth_line_ref(src, lineno):
26 xs = src.split(
"\n")[:lineno]
28 return len(
"\n".join(xs))
31 @hypothesis.given(text(string.printable), booleans(), sampled_from([
'"',
"'"]))
32 def test_replace_string_literal_roundtrip(self, t, raw, quote):
36 r = {r}{quote}placeholder{quote} 37 r2 = {r}{quote}placeholder2{quote} 38 r3 = {r}{quote}placeholder3{quote} 39 """.format(r=
'r' if raw else '', quote=quote * 3)
43 msg =
"program was:\n{}".format(new_prog)
44 self.assertEqual(ns[
'r'], 'placeholder', msg=msg) # noqa: F821
46 self.assertEqual(ns[
'r3'],
'placeholder3', msg=msg)
48 def test_sample(self):
50 single_single('''0''') 75 fn =
'not_a_real_file.py' 76 for lineno, actual
in edits:
77 lineno = history.adjust_lineno(fn, lineno)
79 history.record_edit(fn, lineno, delta)
81 single_single('''a''') 99 def load_tests(loader, tests, ignore):
100 tests.addTests(doctest.DocTestSuite(expecttest))
104 if __name__ ==
'__main__':
def replace_string_literal(src, lineno, new_string)
def ok_for_raw_triple_quoted_string(s, quote)
def assertExpectedInline(self, actual, expect, skip=0)
def nth_line(src, lineno)