summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/test/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-02-26 17:50:34 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-02-26 17:50:34 +0000
commit2d95ef1f252b2752a3840e84a01d989af9921033 (patch)
treef7a9086dc5fed65ef4cc658a5c5d9742bcc58077 /lib/sqlalchemy/test/util.py
parent11f996da20cf40692a21f6e836655cc36d1857d7 (diff)
downloadsqlalchemy-2d95ef1f252b2752a3840e84a01d989af9921033.tar.gz
- the "scale" argument of the Numeric() type is honored when
coercing a returned floating point value into a string on its way to Decimal - this allows accuracy to function on SQLite, MySQL. [ticket:1717]
Diffstat (limited to 'lib/sqlalchemy/test/util.py')
-rw-r--r--lib/sqlalchemy/test/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/sqlalchemy/test/util.py b/lib/sqlalchemy/test/util.py
index 5be00f906..8a3a0e745 100644
--- a/lib/sqlalchemy/test/util.py
+++ b/lib/sqlalchemy/test/util.py
@@ -39,4 +39,15 @@ def picklers():
for pickle in picklers:
for protocol in -1, 0, 1, 2:
yield pickle.loads, lambda d:pickle.dumps(d, protocol)
+
+
+def round_decimal(value, prec):
+ if isinstance(value, float):
+ return round(value, prec)
+
+ import decimal
+
+ # can also use shift() here but that is 2.6 only
+ return (value * decimal.Decimal("1" + "0" * prec)).to_integral(decimal.ROUND_FLOOR) / \
+ pow(10, prec)
\ No newline at end of file