Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icontract-hypothesis #7

Open
H00N24 opened this issue Jan 28, 2021 · 3 comments
Open

Icontract-hypothesis #7

H00N24 opened this issue Jan 28, 2021 · 3 comments
Assignees
Labels
new feature New feature or request

Comments

@H00N24
Copy link
Contributor

H00N24 commented Jan 28, 2021

Try icontract-hypothesis

@H00N24 H00N24 added the new feature New feature or request label Jan 28, 2021
@H00N24 H00N24 self-assigned this Jan 28, 2021
@mristin
Copy link

mristin commented Feb 11, 2021

Hi @H00N24,
I am the author of icontract-hypothesis and I randomly stumbled upon this issue while searching something totally unrelated on Internet.

You might have noticed that icontract-hypothesis optimizes only a limited set of filters at the moment (currently only bounds and regular expressions). My plan is to infer many more strategies as rejection sampling is only viable if only edge cases need to be filtered out, which is seldomly the case in practice.

Please let me know if you would like me to shift priorities and look into the search strategies for this particular project. I don't really have a testbed for icontract-hypothesis and my plan was to look at strategies haphazardly, by guessing what people might use in the wild based on what I use in my projects. IME extrapolating from my use cases tends to be wrong. Thus it would be great if we examine the practical examples of contracts from this project, prioritize them somehow and I'll try to figure out how to infer the Hypothesis search strategies from them.

What do you think?

@pschanely this might also be interesting for CrossHair?

@H00N24
Copy link
Contributor Author

H00N24 commented Feb 12, 2021

Hi @mristin,
Thanks for your reply.

Honestly, I don't really have a plan on how to use icont-hyphotesis right now. After the brief look at the README, I thought that looks very interesting, and I should give it a thorough read. So this issue is more like an idea "backlog" for me. Unfortunately, I have quite a lot of work now, so I am unsure when I'll get to it again.

Anyway, after I read more about it, I would love to speak and share ideas on how/when to use it. If you have any thoughts on your own, I would gladly hear them.

@mristin
Copy link

mristin commented Feb 12, 2021

If you have any thoughts on your own, I would gladly hear them.

Here's one simple idea how you can already get started with icontract-hypothesis in your tests: just pick functions which have meaningful post-conditions and handle pretty much all kinds of input, say some_module.some_func.

Write this in your unit tests:

import unittest

import icontract_hypothesis

import some_module

class TestWithIcontractHypothesis(unittest.TestCase):
    def test_with_inferred_strategies():
        icontract_hypothesis.test_with_inferred_strategy(
            some_module.some_func)

Good candidates for such functions are encode/decode pairs:

@icontract.ensure(lambda x, result: x == decode(result))
def encode(x: Something) -> SomeFormat:
    ...

@icontract.ensure(lambda f, result: f == encode(result))
def decode(f: SomeFormat) -> Something:
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants