Author: Armin Rigo <ar...@tunes.org>
Branch: reverse-debugger
Changeset: r94573:e74b65718f40
Date: 2018-05-14 14:03 +0200
http://bitbucket.org/pypy/pypy/changeset/e74b65718f40/

Log:    Don't explode if 'hypothesis' cannot be imported

diff --git a/pypy/interpreter/test/test_reverse_debugging.py 
b/pypy/interpreter/test/test_reverse_debugging.py
--- a/pypy/interpreter/test/test_reverse_debugging.py
+++ b/pypy/interpreter/test/test_reverse_debugging.py
@@ -2,7 +2,6 @@
 from pypy.interpreter.reverse_debugging import *
 from pypy.interpreter import reverse_debugging
 from rpython.rlib import revdb
-from hypothesis import given, strategies, example
 
 
 class FakeCode:
@@ -15,28 +14,34 @@
         self.co_filename = co_filename
 
 
-@given(strategies.binary())
-@example("\x01\x02\x03\x04"
-         "\x00\xFF\x20\x30\x00\xFF\x00\x40"
-         "\xFF\x00\x0A\x0B\xFF\x00\x0C\x00")
-def test_build_co_revdb_linestarts(lnotab):
-    if len(lnotab) & 1:
-        lnotab = lnotab + '\x00'   # make the length even
-    code = FakeCode("?" * sum(map(ord, lnotab[0::2])), lnotab)
-    lstart = build_co_revdb_linestarts(code)
-    assert lstart is code.co_revdb_linestarts
+try:
+    from hypothesis import given, strategies, example
+except ImportError:
+    pass
+else:
+    @given(strategies.binary())
+    @example("\x01\x02\x03\x04"
+             "\x00\xFF\x20\x30\x00\xFF\x00\x40"
+             "\xFF\x00\x0A\x0B\xFF\x00\x0C\x00")
+    def test_build_co_revdb_linestarts(lnotab):
+        if len(lnotab) & 1:
+            lnotab = lnotab + '\x00'   # make the length even
+        code = FakeCode("?" * sum(map(ord, lnotab[0::2])), lnotab)
+        lstart = build_co_revdb_linestarts(code)
+        assert lstart is code.co_revdb_linestarts
 
-    expected_starts = set()
-    for addr, lineno in dis.findlinestarts(code):
-        expected_starts.add(addr)
+        expected_starts = set()
+        for addr, lineno in dis.findlinestarts(code):
+            expected_starts.add(addr)
 
-    next_start = len(code.co_code)
-    for index in range(len(code.co_code), -1, -1):
-        if index in expected_starts:
-            next_start = index
-        assert lstart[index] == chr(next_start - index
-                                    if next_start - index <= 255
-                                    else 255)
+        next_start = len(code.co_code)
+        for index in range(len(code.co_code), -1, -1):
+            if index in expected_starts:
+                next_start = index
+            assert lstart[index] == chr(next_start - index
+                                        if next_start - index <= 255
+                                        else 255)
+
 
 class FakeFrame:
     def __init__(self, code):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to