Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from hypothesis.extra.django import TestCase as HypothesisTestCase
- from hypothesis.extra.django.models import models as hypothesis_models
- from hypothesis import given, settings, Verbosity
- from hypothesis import strategies as st
- from django.contrib.auth.models import Group
- class Tests(HypothesisTestCase):
- # Fails
- @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
- @given(st.data())
- def test_sets(self, data):
- self.assertEqual(0, Group.objects.count())
- groups = data.draw(st.sets(hypothesis_models(Group)))
- self.assertEqual(len(groups), Group.objects.count())
- # Succeeds
- @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
- @given(st.data())
- def test_lists(self, data):
- self.assertEqual(0, Group.objects.count())
- groups = data.draw(st.lists(hypothesis_models(Group), unique=True))
- self.assertEqual(len(groups), Group.objects.count())
- # Succeeds
- @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
- @given(st.data())
- def test_setted_lists(self, data):
- self.assertEqual(0, Group.objects.count())
- groups = data.draw(st.lists(hypothesis_models(Group), unique=True))
- self.assertEqual(len(set(groups)), Group.objects.count())
- # Succeeds
- @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
- @given(st.data())
- def test_lists_unique_by_pk(self, data):
- self.assertEqual(0, Group.objects.count())
- groups = data.draw(st.lists(hypothesis_models(Group), unique_by=lambda x: x.pk))
- self.assertEqual(len(groups), Group.objects.count())
- # Fails
- @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
- @given(st.data())
- def test_lists_mapped_to_set(self, data):
- self.assertEqual(0, Group.objects.count())
- groups = data.draw(st.lists(hypothesis_models(Group), unique=True).map(set))
- self.assertEqual(len(groups), Group.objects.count())
- # Fails
- @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
- @given(st.data())
- def test_lists_mapped_to_set_unique_by_pk(self, data):
- self.assertEqual(0, Group.objects.count())
- groups = data.draw(st.lists(hypothesis_models(Group), unique_by=lambda x: x.pk).map(set))
- self.assertEqual(len(groups), Group.objects.count())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement