summaryrefslogtreecommitdiff
path: root/tests/template_tests
diff options
context:
space:
mode:
authornessita <124304+nessita@users.noreply.github.com>2024-07-25 16:15:53 -0300
committerGitHub <noreply@github.com>2024-07-25 16:15:53 -0300
commit1b277b45cc4059760072095f3bd6e8a4e4c4d406 (patch)
treed0041f61ab842eb78e1d6c9529980c2cda2172d3 /tests/template_tests
parent0e94f292cda632153f2b3d9a9037eb0141ae9c2e (diff)
Added dedicated test for invalid inputs in floatformat template filter tests.
Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Diffstat (limited to 'tests/template_tests')
-rw-r--r--tests/template_tests/filter_tests/test_floatformat.py43
1 files changed, 39 insertions, 4 deletions
diff --git a/tests/template_tests/filter_tests/test_floatformat.py b/tests/template_tests/filter_tests/test_floatformat.py
index db17622309..145858b75f 100644
--- a/tests/template_tests/filter_tests/test_floatformat.py
+++ b/tests/template_tests/filter_tests/test_floatformat.py
@@ -60,12 +60,8 @@ class FunctionTests(SimpleTestCase):
floatformat(Decimal("123456.123456789012345678901"), 21),
"123456.123456789012345678901",
)
- self.assertEqual(floatformat("foo"), "")
self.assertEqual(floatformat(13.1031, "bar"), "13.1031")
self.assertEqual(floatformat(18.125, 2), "18.13")
- self.assertEqual(floatformat("foo", "bar"), "")
- self.assertEqual(floatformat("¿Cómo esta usted?"), "")
- self.assertEqual(floatformat(None), "")
self.assertEqual(
floatformat(-1.323297138040798e35, 2),
"-132329713804079800000000000000000000.00",
@@ -78,6 +74,45 @@ class FunctionTests(SimpleTestCase):
self.assertEqual(floatformat(1.5e-15, -20), "0.00000000000000150000")
self.assertEqual(floatformat(1.00000000000000015, 16), "1.0000000000000002")
+ def test_invalid_inputs(self):
+ cases = [
+ # Non-numeric strings.
+ None,
+ [],
+ {},
+ object(),
+ "abc123",
+ "123abc",
+ "foo",
+ "error",
+ "¿Cómo esta usted?",
+ # Scientific notation - missing exponent value.
+ "1e",
+ "1e+",
+ "1e-",
+ # Scientific notation - missing base number.
+ "e400",
+ "e+400",
+ "e-400",
+ # Scientific notation - invalid exponent value.
+ "1e^2",
+ "1e2e3",
+ "1e2a",
+ "1e2.0",
+ "1e2,0",
+ # Scientific notation - misplaced decimal point.
+ "1e.2",
+ "1e2.",
+ # Scientific notation - misplaced '+' sign.
+ "1+e2",
+ "1e2+",
+ ]
+ for value in cases:
+ with self.subTest(value=value):
+ self.assertEqual(floatformat(value), "")
+ with self.subTest(value=value, arg="bar"):
+ self.assertEqual(floatformat(value, "bar"), "")
+
def test_force_grouping(self):
with translation.override("en"):
self.assertEqual(floatformat(10000, "g"), "10,000")