Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. from hypothesis.extra.django import TestCase as HypothesisTestCase
  2. from hypothesis.extra.django.models import models as hypothesis_models
  3. from hypothesis import given, settings, Verbosity
  4. from hypothesis import strategies as st
  5.  
  6. from django.contrib.auth.models import Group
  7.  
  8. class Tests(HypothesisTestCase):
  9. # Fails
  10. @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
  11. @given(st.data())
  12. def test_sets(self, data):
  13. self.assertEqual(0, Group.objects.count())
  14. groups = data.draw(st.sets(hypothesis_models(Group)))
  15. self.assertEqual(len(groups), Group.objects.count())
  16.  
  17. # Succeeds
  18. @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
  19. @given(st.data())
  20. def test_lists(self, data):
  21. self.assertEqual(0, Group.objects.count())
  22. groups = data.draw(st.lists(hypothesis_models(Group), unique=True))
  23. self.assertEqual(len(groups), Group.objects.count())
  24.  
  25. # Succeeds
  26. @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
  27. @given(st.data())
  28. def test_setted_lists(self, data):
  29. self.assertEqual(0, Group.objects.count())
  30. groups = data.draw(st.lists(hypothesis_models(Group), unique=True))
  31. self.assertEqual(len(set(groups)), Group.objects.count())
  32.  
  33. # Succeeds
  34. @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
  35. @given(st.data())
  36. def test_lists_unique_by_pk(self, data):
  37. self.assertEqual(0, Group.objects.count())
  38. groups = data.draw(st.lists(hypothesis_models(Group), unique_by=lambda x: x.pk))
  39. self.assertEqual(len(groups), Group.objects.count())
  40.  
  41. # Fails
  42. @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
  43. @given(st.data())
  44. def test_lists_mapped_to_set(self, data):
  45. self.assertEqual(0, Group.objects.count())
  46. groups = data.draw(st.lists(hypothesis_models(Group), unique=True).map(set))
  47. self.assertEqual(len(groups), Group.objects.count())
  48.  
  49. # Fails
  50. @settings(max_examples=100000, timeout=600, verbosity=Verbosity.debug)
  51. @given(st.data())
  52. def test_lists_mapped_to_set_unique_by_pk(self, data):
  53. self.assertEqual(0, Group.objects.count())
  54. groups = data.draw(st.lists(hypothesis_models(Group), unique_by=lambda x: x.pk).map(set))
  55. self.assertEqual(len(groups), Group.objects.count())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement