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

Variables in generators #23

Open
beloglazov opened this issue Aug 15, 2012 · 3 comments
Open

Variables in generators #23

beloglazov opened this issue Aug 15, 2012 · 3 comments
Milestone

Comments

@beloglazov
Copy link

Hi Karol,

I'd like to generate two lists of the same length, which I thought might look something like this:

    @qc
    def test(
        length=int_(min=0, max=10),
        list1=list_(
            of=int_(min=0),
            min_length=length, max_length=length),
        list2=list_(
            of=str_(of='abc123-', min_length=36, max_length=36),
            min_length=length, max_length=length)
    ):
        pass

However, currently it doesn't work. Would it be possible to implement such a feature?

Thanks,
Anton

@Xion
Copy link
Owner

Xion commented Aug 15, 2012

This is the issue that I have actually faced myself and found quite cumbersome indeed. I'd probably like something similar to how py.test handles its funcargs:

def pytest_funcarg__foo(request):
    return something

def pytest_funcarg__bar(request):
    bar = request.getfuncargvalue('bar')
    return other_thing(using=bar)


def test(foo, bar):
   # ...

Of course, pyqcy has no equivalent of request object, but it could probably be done in some more implicit way, like:

@qc
def test(
        length=int_(min=0, max=10),
        list1=list_(
            of=int_(min=0),
            min_length=var('length'), max_length=var('length')),
        list2=list_(
            of=str_(of='abc123-', min_length=36, max_length=36),
            min_length=var('length'), max_length=var('length'))
    ):
        pass

There are few challenges with this approach, though, mostly in resolving the inter-variable dependencies correctly (possibly detecting circular ones). It's nothing really impossible, however :)

@beloglazov
Copy link
Author

I think the approach you suggested in sufficient. Although it's challenging, as you mentioned, it would be nice to see it implemented.

BTW, what do you think about adding another parameter to the sequence generators called 'length', which could be used for fixed length sequences instead of using a pair of min and max?

@Xion
Copy link
Owner

Xion commented Aug 16, 2012

It could work. But length is important parameter when it comes to implementing the all-too-awesome "shrink" operation, so I need to consider how any change here would affect that future implementation of shrink. Actually, though, it might make it easier, for length is essentially an equivalent of size from original Haskell's Arbitrary typeclass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants