diff options
| author | Claude Paroz <claude@2xlibre.net> | 2013-03-31 22:29:35 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-03-31 22:39:01 +0200 |
| commit | 3ff3212713403c5bb8c5b067d2f00d62cf111036 (patch) | |
| tree | bf35334eddfd7f89dd8b97c5ac57f45380d227a8 /tests | |
| parent | 4a1d425cfe88983b34b1ecd3ad2aa9993af84467 (diff) | |
Fixed #19220 -- Prevented decimals to be displayed in scientific notation
Thanks nebstrebor for the report and antofik for the patch.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/backends/tests.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 340ee82f29..a426926cef 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals import datetime +from decimal import Decimal import threading from django.conf import settings @@ -11,6 +12,7 @@ from django.db import (backend, connection, connections, DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, transaction) from django.db.backends.signals import connection_created from django.db.backends.postgresql_psycopg2 import version as pg_version +from django.db.backends.util import format_number from django.db.models import Sum, Avg, Variance, StdDev from django.db.utils import ConnectionHandler from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature, @@ -794,3 +796,42 @@ class DBConstraintTestCase(TransactionTestCase): intermediary_model.objects.create(from_object_id=obj.id, to_object_id=12345) self.assertEqual(obj.related_objects.count(), 1) self.assertEqual(intermediary_model.objects.count(), 2) + + +class BackendUtilTests(TestCase): + + def test_format_number(self): + """ + Test the format_number converter utility + """ + def equal(value, max_d, places, result): + self.assertEqual(format_number(Decimal(value), max_d, places), result) + + equal('0', 12, 3, + '0.000') + equal('0', 12, 8, + '0.00000000') + equal('1', 12, 9, + '1.000000000') + equal('0.00000000', 12, 8, + '0.00000000') + equal('0.000000004', 12, 8, + '0.00000000') + equal('0.000000008', 12, 8, + '0.00000001') + equal('0.000000000000000000999', 10, 8, + '0.00000000') + equal('0.1234567890', 12, 10, + '0.1234567890') + equal('0.1234567890', 12, 9, + '0.123456789') + equal('0.1234567890', 12, 8, + '0.12345679') + equal('0.1234567890', 12, 5, + '0.12346') + equal('0.1234567890', 12, 3, + '0.123') + equal('0.1234567890', 12, 1, + '0.1') + equal('0.1234567890', 12, 0, + '0') |
