tests/test-verify-repo-operations.py
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 19 May 2017 11:50:01 -0700
changeset 32553 20c9f3ecc192
parent 28499 8b90367c4cf3
child 43076 2372284d9457
permissions -rw-r--r--
match: handle everything-matching using new alwaysmatcher Having a special matcher that always matches seems to make more sense than making one of the other matchers handle the case. For now, we just use this new matcher when no patterns were provided.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8b90367c4cf3 tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents: 28279
diff changeset
    14
if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'],
8b90367c4cf3 tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents: 28279
diff changeset
    15
                    'slow']):
8b90367c4cf3 tests: make test-verify-repo-operations.py not run by default
Martin von Zweigbergk <martinvonz@google.com>
parents: 28279
diff changeset
    16
    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
    17
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    18
# 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
    19
# Running 'pip install hypothesis pytz' will achieve that.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    20
# 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
    21
try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    22
    from hypothesis.extra.datetime import datetimes
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    23
except ImportError:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    24
    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
    25
    sys.exit(80)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    26
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    27
# 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
    28
# 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
    29
# fix this problem.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    30
try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    31
    import enum
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 (
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
    47
    rule, RuleBasedStateMachine, Bundle, precondition)
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    48
from hypothesis import settings, note, strategies as st
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    49
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
    50
from hypothesis.database import ExampleDatabase
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    51
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    52
testdir = os.path.abspath(os.environ["TESTDIR"])
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    53
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    54
# 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
    55
# 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
    56
# 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
    57
# but is useful to have for development.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    58
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
    59
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    60
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
    61
testtmp = os.environ["TESTTMP"]
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    62
assert os.path.isdir(testtmp)
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
generatedtests = os.path.join(testdir, "hypothesis-generated")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    65
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    66
try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    67
    os.makedirs(generatedtests)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    68
except OSError:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    69
    pass
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    70
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    71
# 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
    72
# 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
    73
# 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
    74
# 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
    75
# name.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    76
file_index = 0
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    77
while True:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    78
    file_index += 1
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    79
    savefile = os.path.join(generatedtests, "test-generated-%d.t" % (
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    80
        file_index,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    81
    ))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    82
    try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    83
        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
    84
        break
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    85
    except OSError as e:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    86
        if e.errno != errno.EEXIST:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    87
            raise
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    88
assert os.path.exists(savefile)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    89
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    90
hgrc = os.path.join(".hg", "hgrc")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    91
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    92
filecharacters = (
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    93
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    94
    "[]^_`;=@{}~ !#$%&'()+,-"
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
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    97
files = st.text(filecharacters, min_size=1).map(lambda x: x.strip()).filter(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
    98
    bool).map(lambda s: s.encode('ascii'))
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
safetext = st.text(st.characters(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   101
    min_codepoint=1, max_codepoint=127,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   102
    blacklist_categories=('Cc', 'Cs')), min_size=1).map(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   103
    lambda s: s.encode('utf-8')
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   104
)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   105
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   106
extensions = st.sampled_from(('shelve', 'mq', 'blackbox',))
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   107
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   108
@contextmanager
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   109
def acceptableerrors(*args):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   110
    """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
   111
    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
   112
    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
   113
    substrings of the error message Mercurial emits."""
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   114
    try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   115
        yield
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   116
    except subprocess.CalledProcessError as e:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   117
        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
   118
            note(e.output)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   119
            raise
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   120
28257
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   121
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
   122
    lambda s: s.encode('ascii')
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   123
)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   124
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   125
class verifyingstatemachine(RuleBasedStateMachine):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   126
    """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
   127
    using Hypothesis's RuleBasedStateMachine.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   128
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   129
    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
   130
    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
   131
    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
   132
    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
   133
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   134
    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
   135
    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
   136
    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
   137
    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
   138
    .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
   139
    exhibit that failure.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   140
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   141
    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
   142
    Hypothesis documentation at
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   143
    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
   144
    details."""
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   145
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   146
    # 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
   147
    # 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
   148
    repos = Bundle('repos')
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   149
    paths = Bundle('paths')
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   150
    contents = Bundle('contents')
28256
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   151
    branches = Bundle('branches')
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   152
    committimes = Bundle('committimes')
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   153
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   154
    def __init__(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   155
        super(verifyingstatemachine, self).__init__()
28257
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   156
        self.repodir = os.path.join(testtmp, "repos")
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   157
        if os.path.exists(self.repodir):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   158
            shutil.rmtree(self.repodir)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   159
        os.chdir(testtmp)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   160
        self.log = []
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   161
        self.failed = False
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   162
        self.configperrepo = {}
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   163
        self.all_extensions = set()
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   164
        self.non_skippable_extensions = set()
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   165
28257
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   166
        self.mkdirp("repos")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   167
        self.cd("repos")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   168
        self.mkdirp("repo1")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   169
        self.cd("repo1")
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   170
        self.hg("init")
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 teardown(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   173
        """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
   174
        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
   175
        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
   176
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   177
        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
   178
        each passes the same test."""
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   179
        super(verifyingstatemachine, self).teardown()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   180
        try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   181
            shutil.rmtree(self.repodir)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   182
        except OSError:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   183
            pass
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   184
        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
   185
        os.chdir(testtmp)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   186
        path = os.path.join(testtmp, "test-generated.t")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   187
        with open(path, 'w') as o:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   188
            o.write(ttest + os.linesep)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   189
        with open(os.devnull, "w") as devnull:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   190
            rewriter = subprocess.Popen(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   191
                [runtests, "--local", "-i", path], stdin=subprocess.PIPE,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   192
                stdout=devnull, stderr=devnull,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   193
            )
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   194
            rewriter.communicate("yes")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   195
            with open(path, 'r') as i:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   196
                ttest = i.read()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   197
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   198
        e = None
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   199
        if not self.failed:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   200
            try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   201
                output = subprocess.check_output([
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   202
                    runtests, path, "--local", "--pure"
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   203
                ], stderr=subprocess.STDOUT)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   204
                assert "Ran 1 test" in output, output
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   205
                for ext in (
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   206
                    self.all_extensions - self.non_skippable_extensions
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   207
                ):
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   208
                    tf = os.path.join(testtmp, "test-generated-no-%s.t" % (
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   209
                        ext,
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   210
                    ))
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   211
                    with open(tf, 'w') as o:
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   212
                        for l in ttest.splitlines():
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   213
                            if l.startswith("  $ hg"):
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   214
                                l = l.replace(
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   215
                                    "--config %s=" % (
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   216
                                        extensionconfigkey(ext),), "")
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   217
                            o.write(l + os.linesep)
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   218
                    with open(tf, 'r') as r:
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   219
                        t = r.read()
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   220
                        assert ext not in t, t
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   221
                    output = subprocess.check_output([
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   222
                        runtests, tf, "--local",
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   223
                    ], stderr=subprocess.STDOUT)
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   224
                    assert "Ran 1 test" in output, output
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   225
            except subprocess.CalledProcessError as e:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   226
                note(e.output)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   227
        if self.failed or e is not None:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   228
            with open(savefile, "wb") as o:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   229
                o.write(ttest)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   230
        if e is not None:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   231
            raise e
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   232
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   233
    def execute_step(self, step):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   234
        try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   235
            return super(verifyingstatemachine, self).execute_step(step)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   236
        except (HypothesisException, KeyboardInterrupt):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   237
            raise
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   238
        except Exception:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   239
            self.failed = True
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   240
            raise
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   241
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   242
    # Section: Basic commands.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   243
    def mkdirp(self, path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   244
        if os.path.exists(path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   245
            return
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   246
        self.log.append(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   247
            "$ mkdir -p -- %s" % (pipes.quote(os.path.relpath(path)),))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   248
        os.makedirs(path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   249
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   250
    def cd(self, path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   251
        path = os.path.relpath(path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   252
        if path == ".":
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   253
            return
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   254
        os.chdir(path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   255
        self.log.append("$ cd -- %s" % (pipes.quote(path),))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   256
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   257
    def hg(self, *args):
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   258
        extra_flags = []
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   259
        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
   260
            extra_flags.append("--config")
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   261
            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
   262
        self.command("hg", *(tuple(extra_flags) + args))
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   263
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   264
    def command(self, *args):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   265
        self.log.append("$ " + ' '.join(map(pipes.quote, args)))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   266
        subprocess.check_output(args, stderr=subprocess.STDOUT)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   267
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   268
    # Section: Set up basic data
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   269
    # 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
   270
    # to use later.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   271
    @rule(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   272
        target=paths,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   273
        source=st.lists(files, min_size=1).map(lambda l: os.path.join(*l)))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   274
    def genpath(self, source):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   275
        return source
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   276
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   277
    @rule(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   278
        target=committimes,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   279
        when=datetimes(min_year=1970, max_year=2038) | st.none())
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   280
    def gentime(self, when):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   281
        return when
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
    @rule(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   284
        target=contents,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   285
        content=st.one_of(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   286
            st.binary(),
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   287
            st.text().map(lambda x: x.encode('utf-8'))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   288
        ))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   289
    def gencontent(self, content):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   290
        return content
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   291
28256
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   292
    @rule(
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   293
        target=branches,
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   294
        name=safetext,
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   295
    )
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   296
    def genbranch(self, name):
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   297
        return name
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   298
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   299
    @rule(target=paths, source=paths)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   300
    def lowerpath(self, source):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   301
        return source.lower()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   302
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   303
    @rule(target=paths, source=paths)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   304
    def upperpath(self, source):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   305
        return source.upper()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   306
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   307
    # Section: Basic path operations
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   308
    @rule(path=paths, content=contents)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   309
    def writecontent(self, path, content):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   310
        self.unadded_changes = True
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   311
        if os.path.isdir(path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   312
            return
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   313
        parent = os.path.dirname(path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   314
        if parent:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   315
            try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   316
                self.mkdirp(parent)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   317
            except OSError:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   318
                # 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
   319
                # 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
   320
                # 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
   321
                # 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
   322
                return
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   323
        with open(path, 'wb') as o:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   324
            o.write(content)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   325
        self.log.append((
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   326
            "$ python -c 'import binascii; "
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   327
            "print(binascii.unhexlify(\"%s\"))' > %s") % (
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   328
                binascii.hexlify(content),
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   329
                pipes.quote(path),
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
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   332
    @rule(path=paths)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   333
    def addpath(self, path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   334
        if os.path.exists(path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   335
            self.hg("add", "--", path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   336
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   337
    @rule(path=paths)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   338
    def forgetpath(self, path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   339
        if os.path.exists(path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   340
            with acceptableerrors(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   341
                "file is already untracked",
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   342
            ):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   343
                self.hg("forget", "--", path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   344
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   345
    @rule(s=st.none() | st.integers(0, 100))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   346
    def addremove(self, s):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   347
        args = ["addremove"]
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   348
        if s is not None:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   349
            args.extend(["-s", str(s)])
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   350
        self.hg(*args)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   351
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   352
    @rule(path=paths)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   353
    def removepath(self, path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   354
        if os.path.exists(path):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   355
            with acceptableerrors(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   356
                'file is untracked',
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   357
                'file has been marked for add',
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   358
                'file is modified',
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   359
            ):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   360
                self.hg("remove", "--", path)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   361
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   362
    @rule(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   363
        message=safetext,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   364
        amend=st.booleans(),
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   365
        when=committimes,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   366
        addremove=st.booleans(),
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   367
        secret=st.booleans(),
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   368
        close_branch=st.booleans(),
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   369
    )
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   370
    def maybecommit(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   371
        self, message, amend, when, addremove, secret, close_branch
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   372
    ):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   373
        command = ["commit"]
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   374
        errors = ["nothing changed"]
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   375
        if amend:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   376
            errors.append("cannot amend public changesets")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   377
            command.append("--amend")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   378
        command.append("-m" + pipes.quote(message))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   379
        if secret:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   380
            command.append("--secret")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   381
        if close_branch:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   382
            command.append("--close-branch")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   383
            errors.append("can only close branch heads")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   384
        if addremove:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   385
            command.append("--addremove")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   386
        if when is not None:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   387
            if when.year == 1970:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   388
                errors.append('negative date value')
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   389
            if when.year == 2038:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   390
                errors.append('exceeds 32 bits')
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   391
            command.append("--date=%s" % (
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   392
                when.strftime('%Y-%m-%d %H:%M:%S %z'),))
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
        with acceptableerrors(*errors):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   395
            self.hg(*command)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   396
28257
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   397
    # Section: Repository management
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   398
    @property
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   399
    def currentrepo(self):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   400
        return os.path.basename(os.getcwd())
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   401
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   402
    @property
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   403
    def config(self):
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   404
        return self.configperrepo.setdefault(self.currentrepo, {})
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   405
28257
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   406
    @rule(
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   407
        target=repos,
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   408
        source=repos,
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   409
        name=reponames,
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   410
    )
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   411
    def clone(self, source, name):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   412
        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
   413
            self.cd("..")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   414
            self.hg("clone", source, name)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   415
            self.cd(name)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   416
        return name
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   417
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   418
    @rule(
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   419
        target=repos,
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   420
        name=reponames,
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   421
    )
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   422
    def fresh(self, name):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   423
        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
   424
            self.cd("..")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   425
            self.mkdirp(name)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   426
            self.cd(name)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   427
            self.hg("init")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   428
        return name
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   429
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   430
    @rule(name=repos)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   431
    def switch(self, name):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   432
        self.cd(os.path.join("..", name))
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   433
        assert self.currentrepo == name
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   434
        assert os.path.exists(".hg")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   435
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   436
    @rule(target=repos)
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   437
    def origin(self):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   438
        return "repo1"
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   439
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   440
    @rule()
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   441
    def pull(self, repo=repos):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   442
        with acceptableerrors(
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   443
            "repository default not found",
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   444
            "repository is unrelated",
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   445
        ):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   446
            self.hg("pull")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   447
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   448
    @rule(newbranch=st.booleans())
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   449
    def push(self, newbranch):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   450
        with acceptableerrors(
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   451
            "default repository not configured",
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   452
            "no changes found",
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   453
        ):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   454
            if newbranch:
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   455
                self.hg("push", "--new-branch")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   456
            else:
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   457
                with acceptableerrors(
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   458
                    "creates new branches"
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   459
                ):
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   460
                    self.hg("push")
7ff725db2fdf testing: test multiple repositories with Hypothesis
David R. MacIver <david@drmaciver.com>
parents: 28256
diff changeset
   461
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   462
    # Section: Simple side effect free "check" operations
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   463
    @rule()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   464
    def log(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   465
        self.hg("log")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   466
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   467
    @rule()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   468
    def verify(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   469
        self.hg("verify")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   470
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   471
    @rule()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   472
    def diff(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   473
        self.hg("diff", "--nodates")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   474
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   475
    @rule()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   476
    def status(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   477
        self.hg("status")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   478
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   479
    @rule()
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   480
    def export(self):
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   481
        self.hg("export")
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   482
28256
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   483
    # Section: Branch management
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   484
    @rule()
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   485
    def checkbranch(self):
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   486
        self.hg("branch")
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   487
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   488
    @rule(branch=branches)
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   489
    def switchbranch(self, branch):
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   490
        with acceptableerrors(
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   491
            '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
   492
            'cannot be used in a name',
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   493
            '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
   494
            'is reserved',
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   495
        ):
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   496
            self.hg("branch", "--", branch)
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   497
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   498
    @rule(branch=branches, clean=st.booleans())
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   499
    def update(self, branch, clean):
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   500
        with acceptableerrors(
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   501
            'unknown revision',
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   502
            'parse error',
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   503
        ):
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   504
            if clean:
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   505
                self.hg("update", "-C", "--", branch)
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   506
            else:
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   507
                self.hg("update", "--", branch)
55325bdf6c13 testing: expand Hypothesis tests with branch commands
David R. MacIver <david@drmaciver.com>
parents: 28255
diff changeset
   508
28258
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   509
    # Section: Extension management
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   510
    def hasextension(self, extension):
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   511
        return extensionconfigkey(extension) in self.config
28258
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   512
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   513
    def commandused(self, extension):
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   514
        assert extension in self.all_extensions
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   515
        self.non_skippable_extensions.add(extension)
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   516
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   517
    @rule(extension=extensions)
28258
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   518
    def addextension(self, extension):
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   519
        self.all_extensions.add(extension)
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   520
        self.config[extensionconfigkey(extension)] = ""
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   521
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   522
    @rule(extension=extensions)
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   523
    def removeextension(self, extension):
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   524
        self.config.pop(extensionconfigkey(extension), None)
28258
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   525
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   526
    # Section: Commands from the shelve extension
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   527
    @rule()
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   528
    @precondition(lambda self: self.hasextension("shelve"))
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   529
    def shelve(self):
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   530
        self.commandused("shelve")
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   531
        with acceptableerrors("nothing changed"):
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   532
            self.hg("shelve")
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   533
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   534
    @rule()
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   535
    @precondition(lambda self: self.hasextension("shelve"))
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   536
    def unshelve(self):
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   537
        self.commandused("shelve")
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   538
        with acceptableerrors("no shelved changes to apply"):
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   539
            self.hg("unshelve")
fc7ee50a0d65 testing: allow Hypothesis to enable extensions
David R. MacIver <david@drmaciver.com>
parents: 28257
diff changeset
   540
28259
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   541
class writeonlydatabase(ExampleDatabase):
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   542
    def __init__(self, underlying):
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   543
        super(ExampleDatabase, self).__init__()
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   544
        self.underlying = underlying
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   545
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   546
    def fetch(self, key):
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   547
        return ()
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   548
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   549
    def save(self, key, value):
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   550
        self.underlying.save(key, value)
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   551
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   552
    def delete(self, key, value):
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   553
        self.underlying.delete(key, value)
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   554
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   555
    def close(self):
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   556
        self.underlying.close()
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   557
28279
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   558
def extensionconfigkey(extension):
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   559
    return "extensions." + extension
c1fbc92d6238 testing: allow Hypothesis tests to disable extensions
David R. MacIver <david@drmaciver.com>
parents: 28259
diff changeset
   560
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   561
settings.register_profile(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   562
    'default',  settings(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   563
        timeout=300,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   564
        stateful_step_count=50,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   565
        max_examples=10,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   566
    )
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   567
)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   568
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   569
settings.register_profile(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   570
    'fast',  settings(
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   571
        timeout=10,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   572
        stateful_step_count=20,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   573
        max_examples=5,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   574
        min_satisfying_examples=1,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   575
        max_shrinks=0,
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   576
    )
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   577
)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   578
28259
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   579
settings.register_profile(
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   580
    'continuous', settings(
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   581
        timeout=-1,
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   582
        stateful_step_count=1000,
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   583
        max_examples=10 ** 8,
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   584
        max_iterations=10 ** 8,
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   585
        database=writeonlydatabase(settings.default.database)
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
)
7829d0ba7459 testing: add a 'continuous' profile
David R. MacIver <david@drmaciver.com>
parents: 28258
diff changeset
   588
28255
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   589
settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   590
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   591
verifyingtest = verifyingstatemachine.TestCase
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   592
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   593
verifyingtest.settings = settings.default
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   594
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   595
if __name__ == '__main__':
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   596
    try:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   597
        silenttestrunner.main(__name__)
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   598
    finally:
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   599
        # 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
   600
        # 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
   601
        # the file for doing so that we owned.
f75f7d39cca3 testing: generate tests operations using Hypothesis
David R. MacIver <david@drmaciver.com>
parents:
diff changeset
   602
        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
   603
            os.unlink(savefile)