[PATCH 1 of 5 V4] testing: generate tests operations using Hypothesis

Martin von Zweigbergk martinvonz at google.com
Thu Feb 25 11:55:32 EST 2016


On Thu, Feb 25, 2016 at 2:44 AM, David MacIver <david at drmaciver.com> wrote:
> On 24 February 2016 at 21:16, Martin von Zweigbergk <martinvonz at google.com>
> wrote:
>>
>> When running this test case, I get the following error (not surprisingly).
>>
>> +Traceback (most recent call last):
>> +  File "~/hg/tests/test-verify-repo-operations.py", line 18, in <module>
>> +    from hypothesis.extra.datetime import datetimes
>> +ImportError: No module named hypothesis.extra.datetime
>>
>> I guess we should skip the test if Hypothesis is not installed, just
>> like we do with e.g. test-convert-bzr-*.t.
>>
>
> OK, I'll add something to do that.
>
>>
>> Also, for people like me who don't know much about the Python
>> ecosystem, how do I even install Hypothesis? Do I follow the
>> instructions on
>> http://python-packaging-user-guide.readthedocs.org/en/latest/installing/?
>
>
> Yes. Just run "pip install hypothesis"

After installing hypothesis and pytz, I get the following error. IIUC,
that's some Python 3 module...

+Traceback (most recent call last):
+  File "~/hg/tests/test-verify-repo-operations.py", line 30, in <module>
+    from hypothesis.stateful import (
+  File "/usr/local/lib/python2.7/dist-packages/hypothesis/stateful.py",
line 44, in <module>
+    from hypothesis.internal.conjecture.data import StopTest
+  File "/usr/local/lib/python2.7/dist-packages/hypothesis/internal/conjecture/data.py",
line 19, in <module>
+    from enum import IntEnum
+ImportError: No module named enum

>> > @@ -0,0 +1,381 @@
>> > +from __future__ import print_function, absolute_import
>> > +
>> > +"""Fuzz testing for operations against a Mercurial repository
>> > +
>> > +This uses Hypothesis's stateful testing to generate random repository
>> > +operations and test Mercurial using them, both to see if there are any
>> > +unexpected errors and to compare different versions of it."""
>> > +
>> > +import base64
>> > +from contextlib import contextmanager
>> > +import errno
>> > +import os
>> > +import pipes
>> > +import shutil
>> > +import silenttestrunner
>> > +import subprocess
>> > +
>> > +from hypothesis.extra.datetime import datetimes
>> > +from hypothesis.errors import HypothesisException
>> > +from hypothesis.stateful import rule, RuleBasedStateMachine, Bundle
>> > +import hypothesis.strategies as st
>>
>> nit: Does "from hypothesis import strategies as st" do the same thing?
>> It would be more consistent with the surrounding lines.
>
>
> For no particularly good reason my convention is that modules/packages are
> imported qualified as 'import my.module as mm' and things from modules are
> imported with 'from my import thing'. I'm happy to change it if you prefer
> though.

No need to change (but also see comment from timeless). I'm still
trying to understand Python imports.

>> It seems simpler to drop the "source" parameter and create it in the
>> method instead. What's the reason for the current style? Some
>> requirement from Hypothesis?
>>
>
> This is a requirement from Hypothesis because of how the rules are
> constructed and used. It's ended up a bit awkward here. I'm trying to figure
> out a better API to improve upon this.

No problem, and thanks for thinking about it.


More information about the Mercurial-devel mailing list