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

Question: Is it possible to define uuids() so that it only generates uuid4() ? #721

Closed
subokita opened this issue Jul 7, 2017 · 2 comments
Labels
question not sure it's a bug? questions welcome

Comments

@subokita
Copy link

subokita commented Jul 7, 2017

Is it possible to define uuids() so that it only generates uuid4() ?

Since I'm testing some other stuff, I'd like to have the generators only to create uuid4s.

@DRMacIver
Copy link
Member

It isn't, but the UUID strategy isn't terribly complicated, and nor is the standard library code for generating uuid4s so it shouldn't be too hard to roll your own. Something like the following should work (I've not tested it though):

import hypothesis.strategies as st

@st.composite
def uuid4s(draw):
    rng = draw(st.shared(st.randoms(), key='hypothesis.strategies.uuids.generator'))
    return  UUID(int=rng.getrandbits(128), version=4)

A pull request adding UUID version support to hypothesis.strategies would be gratefully accepted if you wanted to make one. :-)

@Zac-HD Zac-HD added the question not sure it's a bug? questions welcome label Jul 23, 2017
@Zac-HD
Copy link
Member

Zac-HD commented Aug 7, 2017

A good first-time contribution:

  • add a version=None keyword argument to hypothesis.strategies.uuids, and pass it through to the call to uuid.UUID.
  • Raise InvalidArgument with a useful message if the version is not in (None, 1, 2, 3, 4, 5).
  • Write a test that Hypothesis can generate UUIDS of each allowed version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question not sure it's a bug? questions welcome
Projects
None yet
Development

No branches or pull requests

3 participants