Author: Matti Picus <[email protected]>
Branch: py3.5
Changeset: r92865:ff734c1f0ec6
Date: 2017-10-28 19:24 +0300
http://bitbucket.org/pypy/pypy/changeset/ff734c1f0ec6/

Log:    Make tests import even if 'hypothesis' is not available

diff --git a/pypy/interpreter/test/test_interpreter.py 
b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -1,7 +1,6 @@
 import py 
 import sys
 from pypy.interpreter import gateway, module, error
-from hypothesis import given, strategies
 
 class TestInterpreter: 
 
@@ -300,30 +299,6 @@
         assert "TypeError:" in res
         assert "'tuple' object is not a mapping" in res
 
-    @given(strategies.lists(strategies.one_of(strategies.none(),
-                                 strategies.lists(strategies.none()))))
-    def test_build_map_order(self, shape):
-        value = [10]
-        def build_expr(shape):
-            if shape is None:
-                value[0] += 1
-                return '0: %d' % value[0]
-            else:
-                return '**{%s}' % (', '.join(
-                    [build_expr(shape1) for shape1 in shape]),)
-
-        expr = build_expr(shape)[2:]
-        code = """
-        def f():
-            return %s
-        """ % (expr, )
-        res = self.codetest(code, 'f', [])
-        if value[0] == 10:
-            expected = {}
-        else:
-            expected = {0: value[0]}
-        assert res == expected, "got %r for %r" % (res, expr)
-
     def test_build_map_unpack_with_call(self):
         code = """
         def f(a,b,c,d):
@@ -348,6 +323,36 @@
         assert "TypeError:" in resg4
         assert "got multiple values for keyword argument 'a'" in resg4
 
+try:
+    from hypothesis import given, strategies
+except ImportError:
+    pass
+else:
+    class TestHypothesisInterpreter(TestInterpreter): 
+        @given(strategies.lists(strategies.one_of(strategies.none(),
+                                     strategies.lists(strategies.none()))))
+        def test_build_map_order(self, shape):
+            value = [10]
+            def build_expr(shape):
+                if shape is None:
+                    value[0] += 1
+                    return '0: %d' % value[0]
+                else:
+                    return '**{%s}' % (', '.join(
+                        [build_expr(shape1) for shape1 in shape]),)
+
+            expr = build_expr(shape)[2:]
+            code = """
+            def f():
+                return %s
+            """ % (expr, )
+            res = self.codetest(code, 'f', [])
+            if value[0] == 10:
+                expected = {}
+            else:
+                expected = {0: value[0]}
+            assert res == expected, "got %r for %r" % (res, expr)
+
 
 class AppTestInterpreter: 
     def test_trivial(self):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to