author | Martin von Zweigbergk <martinvonz@google.com> |
Wed, 09 Dec 2020 20:22:25 -0800 | |
changeset 46115 | be3d8178251e |
parent 45942 | 89a2afe31e82 |
child 46226 | 0826d684a1b5 |
permissions | -rw-r--r-- |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
1 |
from __future__ import print_function, absolute_import |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
2 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
3 |
"""Fuzz testing for operations against a Mercurial repository |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
4 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
5 |
This uses Hypothesis's stateful testing to generate random repository |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
6 |
operations and test Mercurial using them, both to see if there are any |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
7 |
unexpected errors and to compare different versions of it.""" |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
8 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
9 |
import os |
28499
8b90367c4cf3
tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
28279
diff
changeset
|
10 |
import subprocess |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
11 |
import sys |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
12 |
|
28499
8b90367c4cf3
tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
28279
diff
changeset
|
13 |
# Only run if slow tests are allowed |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
14 |
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], 'slow']): |
28499
8b90367c4cf3
tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
28279
diff
changeset
|
15 |
sys.exit(80) |
8b90367c4cf3
tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
28279
diff
changeset
|
16 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
17 |
# These tests require Hypothesis and pytz to be installed. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
18 |
# Running 'pip install hypothesis pytz' will achieve that. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
19 |
# Note: This won't work if you're running Python < 2.7. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
20 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
21 |
from hypothesis.extra.datetime import datetimes |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
22 |
except ImportError: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
23 |
sys.stderr.write("skipped: hypothesis or pytz not installed" + os.linesep) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
24 |
sys.exit(80) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
25 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
26 |
# If you are running an old version of pip you may find that the enum34 |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
27 |
# backport is not installed automatically. If so 'pip install enum34' will |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
28 |
# fix this problem. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
29 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
30 |
import enum |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
31 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
32 |
assert enum # Silence pyflakes |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
33 |
except ImportError: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
34 |
sys.stderr.write("skipped: enum34 not installed" + os.linesep) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
35 |
sys.exit(80) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
36 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
37 |
import binascii |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
38 |
from contextlib import contextmanager |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
39 |
import errno |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
40 |
import pipes |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
41 |
import shutil |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
42 |
import silenttestrunner |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
43 |
import subprocess |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
44 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
45 |
from hypothesis.errors import HypothesisException |
28258
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
46 |
from hypothesis.stateful import ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
47 |
rule, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
48 |
RuleBasedStateMachine, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
49 |
Bundle, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
50 |
precondition, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
51 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
52 |
from hypothesis import settings, note, strategies as st |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
53 |
from hypothesis.configuration import set_hypothesis_home_dir |
28259
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
54 |
from hypothesis.database import ExampleDatabase |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
55 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
56 |
testdir = os.path.abspath(os.environ["TESTDIR"]) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
57 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
58 |
# We store Hypothesis examples here rather in the temporary test directory |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
59 |
# so that when rerunning a failing test this always results in refinding the |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
60 |
# previous failure. This directory is in .hgignore and should not be checked in |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
61 |
# but is useful to have for development. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
62 |
set_hypothesis_home_dir(os.path.join(testdir, ".hypothesis")) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
63 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
64 |
runtests = os.path.join(os.environ["RUNTESTDIR"], "run-tests.py") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
65 |
testtmp = os.environ["TESTTMP"] |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
66 |
assert os.path.isdir(testtmp) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
67 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
68 |
generatedtests = os.path.join(testdir, "hypothesis-generated") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
69 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
70 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
71 |
os.makedirs(generatedtests) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
72 |
except OSError: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
73 |
pass |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
74 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
75 |
# We write out generated .t files to a file in order to ease debugging and to |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
76 |
# give a starting point for turning failures Hypothesis finds into normal |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
77 |
# tests. In order to ensure that multiple copies of this test can be run in |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
78 |
# parallel we use atomic file create to ensure that we always get a unique |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
79 |
# name. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
80 |
file_index = 0 |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
81 |
while True: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
82 |
file_index += 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
83 |
savefile = os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
84 |
generatedtests, "test-generated-%d.t" % (file_index,) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
85 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
86 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
87 |
os.close(os.open(savefile, os.O_CREAT | os.O_EXCL | os.O_WRONLY)) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
88 |
break |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
89 |
except OSError as e: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
90 |
if e.errno != errno.EEXIST: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
91 |
raise |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
92 |
assert os.path.exists(savefile) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
93 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
94 |
hgrc = os.path.join(".hg", "hgrc") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
95 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
96 |
filecharacters = ( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
97 |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
98 |
"[]^_`;=@{}~ !#$%&'()+,-" |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
99 |
) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
100 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
101 |
files = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
102 |
st.text(filecharacters, min_size=1) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
103 |
.map(lambda x: x.strip()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
104 |
.filter(bool) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
105 |
.map(lambda s: s.encode('ascii')) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
106 |
) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
107 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
108 |
safetext = st.text( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
109 |
st.characters( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
110 |
min_codepoint=1, max_codepoint=127, blacklist_categories=('Cc', 'Cs') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
111 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
112 |
min_size=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
113 |
).map(lambda s: s.encode('utf-8')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
114 |
|
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
115 |
extensions = st.sampled_from( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
116 |
( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
117 |
'shelve', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
118 |
'mq', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
119 |
'blackbox', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
120 |
) |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
121 |
) |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
122 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
123 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
124 |
@contextmanager |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
125 |
def acceptableerrors(*args): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
126 |
"""Sometimes we know an operation we're about to perform might fail, and |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
127 |
we're OK with some of the failures. In those cases this may be used as a |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
128 |
context manager and will swallow expected failures, as identified by |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
129 |
substrings of the error message Mercurial emits.""" |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
130 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
131 |
yield |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
132 |
except subprocess.CalledProcessError as e: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
133 |
if not any(a in e.output for a in args): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
134 |
note(e.output) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
135 |
raise |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
136 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
137 |
|
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
138 |
reponames = st.text("abcdefghijklmnopqrstuvwxyz01234556789", min_size=1).map( |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
139 |
lambda s: s.encode('ascii') |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
140 |
) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
141 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
142 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
143 |
class verifyingstatemachine(RuleBasedStateMachine): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
144 |
"""This defines the set of acceptable operations on a Mercurial repository |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
145 |
using Hypothesis's RuleBasedStateMachine. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
146 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
147 |
The general concept is that we manage multiple repositories inside a |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
148 |
repos/ directory in our temporary test location. Some of these are freshly |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
149 |
inited, some are clones of the others. Our current working directory is |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
150 |
always inside one of these repositories while the tests are running. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
151 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
152 |
Hypothesis then performs a series of operations against these repositories, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
153 |
including hg commands, generating contents and editing the .hgrc file. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
154 |
If these operations fail in unexpected ways or behave differently in |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
155 |
different configurations of Mercurial, the test will fail and a minimized |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
156 |
.t test file will be written to the hypothesis-generated directory to |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
157 |
exhibit that failure. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
158 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
159 |
Operations are defined as methods with @rule() decorators. See the |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
160 |
Hypothesis documentation at |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
161 |
http://hypothesis.readthedocs.org/en/release/stateful.html for more |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
162 |
details.""" |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
163 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
164 |
# A bundle is a reusable collection of previously generated data which may |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
165 |
# be provided as arguments to future operations. |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
166 |
repos = Bundle('repos') |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
167 |
paths = Bundle('paths') |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
168 |
contents = Bundle('contents') |
28256
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
169 |
branches = Bundle('branches') |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
170 |
committimes = Bundle('committimes') |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
171 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
172 |
def __init__(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
173 |
super(verifyingstatemachine, self).__init__() |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
174 |
self.repodir = os.path.join(testtmp, "repos") |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
175 |
if os.path.exists(self.repodir): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
176 |
shutil.rmtree(self.repodir) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
177 |
os.chdir(testtmp) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
178 |
self.log = [] |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
179 |
self.failed = False |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
180 |
self.configperrepo = {} |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
181 |
self.all_extensions = set() |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
182 |
self.non_skippable_extensions = set() |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
183 |
|
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
184 |
self.mkdirp("repos") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
185 |
self.cd("repos") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
186 |
self.mkdirp("repo1") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
187 |
self.cd("repo1") |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
188 |
self.hg("init") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
189 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
190 |
def teardown(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
191 |
"""On teardown we clean up after ourselves as usual, but we also |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
192 |
do some additional testing: We generate a .t file based on our test |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
193 |
run using run-test.py -i to get the correct output. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
194 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
195 |
We then test it in a number of other configurations, verifying that |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
196 |
each passes the same test.""" |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
197 |
super(verifyingstatemachine, self).teardown() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
198 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
199 |
shutil.rmtree(self.repodir) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
200 |
except OSError: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
201 |
pass |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
202 |
ttest = os.linesep.join(" " + l for l in self.log) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
203 |
os.chdir(testtmp) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
204 |
path = os.path.join(testtmp, "test-generated.t") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
205 |
with open(path, 'w') as o: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
206 |
o.write(ttest + os.linesep) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
207 |
with open(os.devnull, "w") as devnull: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
208 |
rewriter = subprocess.Popen( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
209 |
[runtests, "--local", "-i", path], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
210 |
stdin=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
211 |
stdout=devnull, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
212 |
stderr=devnull, |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
213 |
) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
214 |
rewriter.communicate("yes") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
215 |
with open(path, 'r') as i: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
216 |
ttest = i.read() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
217 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
218 |
e = None |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
219 |
if not self.failed: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
220 |
try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
221 |
output = subprocess.check_output( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
222 |
[runtests, path, "--local", "--pure"], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
223 |
stderr=subprocess.STDOUT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
224 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
225 |
assert "Ran 1 test" in output, output |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
226 |
for ext in self.all_extensions - self.non_skippable_extensions: |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
227 |
tf = os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
228 |
testtmp, "test-generated-no-%s.t" % (ext,) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
229 |
) |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
230 |
with open(tf, 'w') as o: |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
231 |
for l in ttest.splitlines(): |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
232 |
if l.startswith(" $ hg"): |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
233 |
l = l.replace( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
234 |
"--config %s=" % (extensionconfigkey(ext),), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
235 |
"", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
236 |
) |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
237 |
o.write(l + os.linesep) |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
238 |
with open(tf, 'r') as r: |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
239 |
t = r.read() |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
240 |
assert ext not in t, t |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
241 |
output = subprocess.check_output( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
242 |
[ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
243 |
runtests, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
244 |
tf, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
245 |
"--local", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
246 |
], |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
247 |
stderr=subprocess.STDOUT, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
248 |
) |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
249 |
assert "Ran 1 test" in output, output |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
250 |
except subprocess.CalledProcessError as e: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
251 |
note(e.output) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
252 |
if self.failed or e is not None: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
253 |
with open(savefile, "wb") as o: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
254 |
o.write(ttest) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
255 |
if e is not None: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
256 |
raise e |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
257 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
258 |
def execute_step(self, step): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
259 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
260 |
return super(verifyingstatemachine, self).execute_step(step) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
261 |
except (HypothesisException, KeyboardInterrupt): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
262 |
raise |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
263 |
except Exception: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
264 |
self.failed = True |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
265 |
raise |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
266 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
267 |
# Section: Basic commands. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
268 |
def mkdirp(self, path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
269 |
if os.path.exists(path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
270 |
return |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
271 |
self.log.append( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
272 |
"$ mkdir -p -- %s" % (pipes.quote(os.path.relpath(path)),) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
273 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
274 |
os.makedirs(path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
275 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
276 |
def cd(self, path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
277 |
path = os.path.relpath(path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
278 |
if path == ".": |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
279 |
return |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
280 |
os.chdir(path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
281 |
self.log.append("$ cd -- %s" % (pipes.quote(path),)) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
282 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
283 |
def hg(self, *args): |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
284 |
extra_flags = [] |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
285 |
for key, value in self.config.items(): |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
286 |
extra_flags.append("--config") |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
287 |
extra_flags.append("%s=%s" % (key, value)) |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
288 |
self.command("hg", *(tuple(extra_flags) + args)) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
289 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
290 |
def command(self, *args): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
291 |
self.log.append("$ " + ' '.join(map(pipes.quote, args))) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
292 |
subprocess.check_output(args, stderr=subprocess.STDOUT) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
293 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
294 |
# Section: Set up basic data |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
295 |
# This section has no side effects but generates data that we will want |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
296 |
# to use later. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
297 |
@rule( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
298 |
target=paths, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
299 |
source=st.lists(files, min_size=1).map(lambda l: os.path.join(*l)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
300 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
301 |
def genpath(self, source): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
302 |
return source |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
303 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
304 |
@rule( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
305 |
target=committimes, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
306 |
when=datetimes(min_year=1970, max_year=2038) | st.none(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
307 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
308 |
def gentime(self, when): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
309 |
return when |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
310 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
311 |
@rule( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
312 |
target=contents, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
313 |
content=st.one_of( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
314 |
st.binary(), st.text().map(lambda x: x.encode('utf-8')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
315 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
316 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
317 |
def gencontent(self, content): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
318 |
return content |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
319 |
|
28256
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
320 |
@rule( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
321 |
target=branches, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
322 |
name=safetext, |
28256
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
323 |
) |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
324 |
def genbranch(self, name): |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
325 |
return name |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
326 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
327 |
@rule(target=paths, source=paths) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
328 |
def lowerpath(self, source): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
329 |
return source.lower() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
330 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
331 |
@rule(target=paths, source=paths) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
332 |
def upperpath(self, source): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
333 |
return source.upper() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
334 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
335 |
# Section: Basic path operations |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
336 |
@rule(path=paths, content=contents) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
337 |
def writecontent(self, path, content): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
338 |
self.unadded_changes = True |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
339 |
if os.path.isdir(path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
340 |
return |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
341 |
parent = os.path.dirname(path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
342 |
if parent: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
343 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
344 |
self.mkdirp(parent) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
345 |
except OSError: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
346 |
# It may be the case that there is a regular file that has |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
347 |
# previously been created that has the same name as an ancestor |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
348 |
# of the current path. This will cause mkdirp to fail with this |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
349 |
# error. We just turn this into a no-op in that case. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
350 |
return |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
351 |
with open(path, 'wb') as o: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
352 |
o.write(content) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
353 |
self.log.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
354 |
( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
355 |
"$ python -c 'import binascii; " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
356 |
"print(binascii.unhexlify(\"%s\"))' > %s" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
357 |
) |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
358 |
% ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
359 |
binascii.hexlify(content), |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
360 |
pipes.quote(path), |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
361 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
362 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
363 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
364 |
@rule(path=paths) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
365 |
def addpath(self, path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
366 |
if os.path.exists(path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
367 |
self.hg("add", "--", path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
368 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
369 |
@rule(path=paths) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
370 |
def forgetpath(self, path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
371 |
if os.path.exists(path): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
372 |
with acceptableerrors( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
373 |
"file is already untracked", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
374 |
): |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
375 |
self.hg("forget", "--", path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
376 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
377 |
@rule(s=st.none() | st.integers(0, 100)) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
378 |
def addremove(self, s): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
379 |
args = ["addremove"] |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
380 |
if s is not None: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
381 |
args.extend(["-s", str(s)]) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
382 |
self.hg(*args) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
383 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
384 |
@rule(path=paths) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
385 |
def removepath(self, path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
386 |
if os.path.exists(path): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
387 |
with acceptableerrors( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
388 |
'file is untracked', |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
389 |
'file has been marked for add', |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
390 |
'file is modified', |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
391 |
): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
392 |
self.hg("remove", "--", path) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
393 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
394 |
@rule( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
395 |
message=safetext, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
396 |
amend=st.booleans(), |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
397 |
when=committimes, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
398 |
addremove=st.booleans(), |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
399 |
secret=st.booleans(), |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
400 |
close_branch=st.booleans(), |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
401 |
) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
402 |
def maybecommit( |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
403 |
self, message, amend, when, addremove, secret, close_branch |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
404 |
): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
405 |
command = ["commit"] |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
406 |
errors = ["nothing changed"] |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
407 |
if amend: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
408 |
errors.append("cannot amend public changesets") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
409 |
command.append("--amend") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
410 |
command.append("-m" + pipes.quote(message)) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
411 |
if secret: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
412 |
command.append("--secret") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
413 |
if close_branch: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
414 |
command.append("--close-branch") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
415 |
errors.append("can only close branch heads") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
416 |
if addremove: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
417 |
command.append("--addremove") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
418 |
if when is not None: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
419 |
if when.year == 1970: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
420 |
errors.append('negative date value') |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
421 |
if when.year == 2038: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
422 |
errors.append('exceeds 32 bits') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
423 |
command.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
424 |
"--date=%s" % (when.strftime('%Y-%m-%d %H:%M:%S %z'),) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
425 |
) |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
426 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
427 |
with acceptableerrors(*errors): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
428 |
self.hg(*command) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
429 |
|
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
430 |
# Section: Repository management |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
431 |
@property |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
432 |
def currentrepo(self): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
433 |
return os.path.basename(os.getcwd()) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
434 |
|
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
435 |
@property |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
436 |
def config(self): |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
437 |
return self.configperrepo.setdefault(self.currentrepo, {}) |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
438 |
|
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
439 |
@rule( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
440 |
target=repos, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
441 |
source=repos, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
442 |
name=reponames, |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
443 |
) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
444 |
def clone(self, source, name): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
445 |
if not os.path.exists(os.path.join("..", name)): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
446 |
self.cd("..") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
447 |
self.hg("clone", source, name) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
448 |
self.cd(name) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
449 |
return name |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
450 |
|
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
451 |
@rule( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
452 |
target=repos, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
453 |
name=reponames, |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
454 |
) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
455 |
def fresh(self, name): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
456 |
if not os.path.exists(os.path.join("..", name)): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
457 |
self.cd("..") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
458 |
self.mkdirp(name) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
459 |
self.cd(name) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
460 |
self.hg("init") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
461 |
return name |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
462 |
|
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
463 |
@rule(name=repos) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
464 |
def switch(self, name): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
465 |
self.cd(os.path.join("..", name)) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
466 |
assert self.currentrepo == name |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
467 |
assert os.path.exists(".hg") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
468 |
|
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
469 |
@rule(target=repos) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
470 |
def origin(self): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
471 |
return "repo1" |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
472 |
|
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
473 |
@rule() |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
474 |
def pull(self, repo=repos): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
475 |
with acceptableerrors( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
476 |
"repository default not found", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
477 |
"repository is unrelated", |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
478 |
): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
479 |
self.hg("pull") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
480 |
|
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
481 |
@rule(newbranch=st.booleans()) |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
482 |
def push(self, newbranch): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
483 |
with acceptableerrors( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
484 |
"default repository not configured", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
485 |
"no changes found", |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
486 |
): |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
487 |
if newbranch: |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
488 |
self.hg("push", "--new-branch") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
489 |
else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
490 |
with acceptableerrors("creates new branches"): |
28257
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
491 |
self.hg("push") |
7ff725db2fdf
testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
28256
diff
changeset
|
492 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
493 |
# Section: Simple side effect free "check" operations |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
494 |
@rule() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
495 |
def log(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
496 |
self.hg("log") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
497 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
498 |
@rule() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
499 |
def verify(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
500 |
self.hg("verify") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
501 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
502 |
@rule() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
503 |
def diff(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
504 |
self.hg("diff", "--nodates") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
505 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
506 |
@rule() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
507 |
def status(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
508 |
self.hg("status") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
509 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
510 |
@rule() |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
511 |
def export(self): |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
512 |
self.hg("export") |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
513 |
|
28256
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
514 |
# Section: Branch management |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
515 |
@rule() |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
516 |
def checkbranch(self): |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
517 |
self.hg("branch") |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
518 |
|
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
519 |
@rule(branch=branches) |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
520 |
def switchbranch(self, branch): |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
521 |
with acceptableerrors( |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
522 |
'cannot use an integer as a name', |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
523 |
'cannot be used in a name', |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
524 |
'a branch of the same name already exists', |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
525 |
'is reserved', |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
526 |
): |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
527 |
self.hg("branch", "--", branch) |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
528 |
|
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
529 |
@rule(branch=branches, clean=st.booleans()) |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
530 |
def update(self, branch, clean): |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
531 |
with acceptableerrors( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
532 |
'unknown revision', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
533 |
'parse error', |
28256
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
534 |
): |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
535 |
if clean: |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
536 |
self.hg("update", "-C", "--", branch) |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
537 |
else: |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
538 |
self.hg("update", "--", branch) |
55325bdf6c13
testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents:
28255
diff
changeset
|
539 |
|
28258
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
540 |
# Section: Extension management |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
541 |
def hasextension(self, extension): |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
542 |
return extensionconfigkey(extension) in self.config |
28258
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
543 |
|
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
544 |
def commandused(self, extension): |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
545 |
assert extension in self.all_extensions |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
546 |
self.non_skippable_extensions.add(extension) |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
547 |
|
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
548 |
@rule(extension=extensions) |
28258
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
549 |
def addextension(self, extension): |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
550 |
self.all_extensions.add(extension) |
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
551 |
self.config[extensionconfigkey(extension)] = "" |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
552 |
|
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
553 |
@rule(extension=extensions) |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
554 |
def removeextension(self, extension): |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
555 |
self.config.pop(extensionconfigkey(extension), None) |
28258
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
556 |
|
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
557 |
# Section: Commands from the shelve extension |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
558 |
@rule() |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
559 |
@precondition(lambda self: self.hasextension("shelve")) |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
560 |
def shelve(self): |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
561 |
self.commandused("shelve") |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
562 |
with acceptableerrors("nothing changed"): |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
563 |
self.hg("shelve") |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
564 |
|
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
565 |
@rule() |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
566 |
@precondition(lambda self: self.hasextension("shelve")) |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
567 |
def unshelve(self): |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
568 |
self.commandused("shelve") |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
569 |
with acceptableerrors("no shelved changes to apply"): |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
570 |
self.hg("unshelve") |
fc7ee50a0d65
testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents:
28257
diff
changeset
|
571 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
572 |
|
28259
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
573 |
class writeonlydatabase(ExampleDatabase): |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
574 |
def __init__(self, underlying): |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
575 |
super(ExampleDatabase, self).__init__() |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
576 |
self.underlying = underlying |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
577 |
|
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
578 |
def fetch(self, key): |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
579 |
return () |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
580 |
|
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
581 |
def save(self, key, value): |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
582 |
self.underlying.save(key, value) |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
583 |
|
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
584 |
def delete(self, key, value): |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
585 |
self.underlying.delete(key, value) |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
586 |
|
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
587 |
def close(self): |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
588 |
self.underlying.close() |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
589 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
590 |
|
28279
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
591 |
def extensionconfigkey(extension): |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
592 |
return "extensions." + extension |
c1fbc92d6238
testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents:
28259
diff
changeset
|
593 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
594 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
595 |
settings.register_profile( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
596 |
'default', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
597 |
settings( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
598 |
timeout=300, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
599 |
stateful_step_count=50, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
600 |
max_examples=10, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43076
diff
changeset
|
601 |
), |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
602 |
) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
603 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
604 |
settings.register_profile( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
605 |
'fast', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
606 |
settings( |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
607 |
timeout=10, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
608 |
stateful_step_count=20, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
609 |
max_examples=5, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
610 |
min_satisfying_examples=1, |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
611 |
max_shrinks=0, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
612 |
), |
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
613 |
) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
614 |
|
28259
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
615 |
settings.register_profile( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
616 |
'continuous', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
617 |
settings( |
28259
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
618 |
timeout=-1, |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
619 |
stateful_step_count=1000, |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
620 |
max_examples=10 ** 8, |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
621 |
max_iterations=10 ** 8, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
622 |
database=writeonlydatabase(settings.default.database), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
28499
diff
changeset
|
623 |
), |
28259
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
624 |
) |
7829d0ba7459
testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents:
28258
diff
changeset
|
625 |
|
28255
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
626 |
settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default')) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
627 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
628 |
verifyingtest = verifyingstatemachine.TestCase |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
629 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
630 |
verifyingtest.settings = settings.default |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
631 |
|
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
632 |
if __name__ == '__main__': |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
633 |
try: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
634 |
silenttestrunner.main(__name__) |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
635 |
finally: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
636 |
# So as to prevent proliferation of useless test files, if we never |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
637 |
# actually wrote a failing test we clean up after ourselves and delete |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
638 |
# the file for doing so that we owned. |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
639 |
if os.path.exists(savefile) and os.path.getsize(savefile) == 0: |
f75f7d39cca3
testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff
changeset
|
640 |
os.unlink(savefile) |