Skip to content

Instantly share code, notes, and snippets.

@jerith
Created March 13, 2016 16:51
Show Gist options
  • Save jerith/64b8b86f28fe93fe94c5 to your computer and use it in GitHub Desktop.
Save jerith/64b8b86f28fe93fe94c5 to your computer and use it in GitHub Desktop.
test_runicode.py Hypothesisation
diff -r c4d20dd5b286 rpython/rlib/test/test_runicode.py
--- a/rpython/rlib/test/test_runicode.py Sun Mar 13 07:45:49 2016 +0200
+++ b/rpython/rlib/test/test_runicode.py Sun Mar 13 18:48:35 2016 +0200
@@ -4,6 +4,8 @@
import sys, random
from rpython.rlib import runicode
+from hypothesis import given, settings, strategies
+
def test_unichr():
assert runicode.UNICHR(0xffff) == u'\uffff'
@@ -172,6 +174,17 @@
"utf-32 utf-32-be utf-32-le").split():
self.checkdecode(uni, encoding)
+ # Same as above, but uses Hypothesis to generate non-surrogate unicode
+ # characters.
+ @settings(max_examples=10000)
+ @given(strategies.characters(blacklist_categories=["Cs"]))
+ def test_random_hypothesis(self, uni):
+ if sys.version >= "2.7":
+ self.checkdecode(uni, "utf-7")
+ for encoding in ("utf-8 utf-16 utf-16-be utf-16-le "
+ "utf-32 utf-32-be utf-32-le").split():
+ self.checkdecode(uni, encoding)
+
def test_maxunicode(self):
uni = unichr(sys.maxunicode)
if sys.version >= "2.7":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment