Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r91648:b7ddeba4af0d
Date: 2017-06-25 20:25 +0100
http://bitbucket.org/pypy/pypy/changeset/b7ddeba4af0d/

Log:    Add failing extra_test (inspired by CPython's deccheck.py)

diff --git a/extra_tests/test_decimal.py b/extra_tests/test_decimal.py
--- a/extra_tests/test_decimal.py
+++ b/extra_tests/test_decimal.py
@@ -1,4 +1,5 @@
 import pytest
+from hypothesis import given, strategies as st
 
 import pickle
 import sys
@@ -14,6 +15,27 @@
 def module(request):
     yield request.param
 
+# Translate symbols.
+CondMap = {
+        C.Clamped:             P.Clamped,
+        C.ConversionSyntax:    P.ConversionSyntax,
+        C.DivisionByZero:      P.DivisionByZero,
+        C.DivisionImpossible:  P.InvalidOperation,
+        C.DivisionUndefined:   P.DivisionUndefined,
+        C.Inexact:             P.Inexact,
+        C.InvalidContext:      P.InvalidContext,
+        C.InvalidOperation:    P.InvalidOperation,
+        C.Overflow:            P.Overflow,
+        C.Rounded:             P.Rounded,
+        C.Subnormal:           P.Subnormal,
+        C.Underflow:           P.Underflow,
+        C.FloatOperation:      P.FloatOperation,
+}
+
+def check_same_flags(flags_C, flags_P):
+    for signal in flags_C:
+        assert flags_C[signal] == flags_P[CondMap[signal]]
+
 
 def test_C():
     sys.modules["decimal"] = C
@@ -68,3 +90,22 @@
 
 def test_compare_total_mag(module):
     assert module.Decimal(1).compare_total_mag(-2) == -1
+
+@given(st.decimals(), st.decimals())
+def test_lt(d1, d2):
+    ctx_C = C.getcontext()
+    ctx_P = P.getcontext()
+    ctx_C.clear_flags()
+    ctx_P.clear_flags()
+    d1_P = P.Decimal(str(d1))
+    d2_P = P.Decimal(str(d2))
+    try:
+        res_C = d1 < d2
+    except Exception as e:
+        res_C = str(type(e))
+    try:
+        res_P = d1_P < d2_P
+    except Exception as e:
+        res_P = str(type(e))
+    assert res_C == res_P
+    check_same_flags(ctx_C.flags, ctx_P.flags)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to