summaryrefslogtreecommitdiff
path: root/tests/db_functions/math
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2022-02-03 20:24:19 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-07 20:37:05 +0100
commit9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch)
treef0506b668a013d0063e5fba3dbf4863b466713ba /tests/db_functions/math
parentf68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff)
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'tests/db_functions/math')
-rw-r--r--tests/db_functions/math/test_abs.py21
-rw-r--r--tests/db_functions/math/test_acos.py25
-rw-r--r--tests/db_functions/math/test_asin.py25
-rw-r--r--tests/db_functions/math/test_atan.py25
-rw-r--r--tests/db_functions/math/test_atan2.py17
-rw-r--r--tests/db_functions/math/test_ceil.py25
-rw-r--r--tests/db_functions/math/test_cos.py21
-rw-r--r--tests/db_functions/math/test_cot.py21
-rw-r--r--tests/db_functions/math/test_degrees.py25
-rw-r--r--tests/db_functions/math/test_exp.py21
-rw-r--r--tests/db_functions/math/test_floor.py25
-rw-r--r--tests/db_functions/math/test_ln.py21
-rw-r--r--tests/db_functions/math/test_log.py19
-rw-r--r--tests/db_functions/math/test_mod.py17
-rw-r--r--tests/db_functions/math/test_pi.py1
-rw-r--r--tests/db_functions/math/test_power.py29
-rw-r--r--tests/db_functions/math/test_radians.py25
-rw-r--r--tests/db_functions/math/test_round.py59
-rw-r--r--tests/db_functions/math/test_sign.py29
-rw-r--r--tests/db_functions/math/test_sin.py21
-rw-r--r--tests/db_functions/math/test_sqrt.py25
-rw-r--r--tests/db_functions/math/test_tan.py21
22 files changed, 268 insertions, 250 deletions
diff --git a/tests/db_functions/math/test_abs.py b/tests/db_functions/math/test_abs.py
index a9e0175e84..e56b13f2a2 100644
--- a/tests/db_functions/math/test_abs.py
+++ b/tests/db_functions/math/test_abs.py
@@ -9,15 +9,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class AbsTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_abs=Abs('normal')).first()
+ obj = IntegerModel.objects.annotate(null_abs=Abs("normal")).first()
self.assertIsNone(obj.null_abs)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-0.8'), n2=Decimal('1.2'))
- obj = DecimalModel.objects.annotate(n1_abs=Abs('n1'), n2_abs=Abs('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-0.8"), n2=Decimal("1.2"))
+ obj = DecimalModel.objects.annotate(n1_abs=Abs("n1"), n2_abs=Abs("n2")).first()
self.assertIsInstance(obj.n1_abs, Decimal)
self.assertIsInstance(obj.n2_abs, Decimal)
self.assertEqual(obj.n1, -obj.n1_abs)
@@ -25,7 +24,7 @@ class AbsTests(TestCase):
def test_float(self):
obj = FloatModel.objects.create(f1=-0.5, f2=12)
- obj = FloatModel.objects.annotate(f1_abs=Abs('f1'), f2_abs=Abs('f2')).first()
+ obj = FloatModel.objects.annotate(f1_abs=Abs("f1"), f2_abs=Abs("f2")).first()
self.assertIsInstance(obj.f1_abs, float)
self.assertIsInstance(obj.f2_abs, float)
self.assertEqual(obj.f1, -obj.f1_abs)
@@ -34,9 +33,9 @@ class AbsTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=12, normal=0, big=-45)
obj = IntegerModel.objects.annotate(
- small_abs=Abs('small'),
- normal_abs=Abs('normal'),
- big_abs=Abs('big'),
+ small_abs=Abs("small"),
+ normal_abs=Abs("normal"),
+ big_abs=Abs("big"),
).first()
self.assertIsInstance(obj.small_abs, int)
self.assertIsInstance(obj.normal_abs, int)
@@ -47,7 +46,7 @@ class AbsTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Abs):
- DecimalModel.objects.create(n1=Decimal('-1.5'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-0.5'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("-1.5"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-0.5"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__abs__gt=1).get()
- self.assertEqual(obj.n1, Decimal('-1.5'))
+ self.assertEqual(obj.n1, Decimal("-1.5"))
diff --git a/tests/db_functions/math/test_acos.py b/tests/db_functions/math/test_acos.py
index b5cac88eea..fe77866320 100644
--- a/tests/db_functions/math/test_acos.py
+++ b/tests/db_functions/math/test_acos.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class ACosTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_acos=ACos('normal')).first()
+ obj = IntegerModel.objects.annotate(null_acos=ACos("normal")).first()
self.assertIsNone(obj.null_acos)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-0.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_acos=ACos('n1'), n2_acos=ACos('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-0.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_acos=ACos("n1"), n2_acos=ACos("n2")
+ ).first()
self.assertIsInstance(obj.n1_acos, Decimal)
self.assertIsInstance(obj.n2_acos, Decimal)
self.assertAlmostEqual(obj.n1_acos, Decimal(math.acos(obj.n1)))
@@ -26,7 +27,9 @@ class ACosTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-0.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_acos=ACos('f1'), f2_acos=ACos('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_acos=ACos("f1"), f2_acos=ACos("f2")
+ ).first()
self.assertIsInstance(obj.f1_acos, float)
self.assertIsInstance(obj.f2_acos, float)
self.assertAlmostEqual(obj.f1_acos, math.acos(obj.f1))
@@ -35,9 +38,9 @@ class ACosTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=0, normal=1, big=-1)
obj = IntegerModel.objects.annotate(
- small_acos=ACos('small'),
- normal_acos=ACos('normal'),
- big_acos=ACos('big'),
+ small_acos=ACos("small"),
+ normal_acos=ACos("normal"),
+ big_acos=ACos("big"),
).first()
self.assertIsInstance(obj.small_acos, float)
self.assertIsInstance(obj.normal_acos, float)
@@ -48,7 +51,7 @@ class ACosTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, ACos):
- DecimalModel.objects.create(n1=Decimal('0.5'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-0.9'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("0.5"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-0.9"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__acos__lt=2).get()
- self.assertEqual(obj.n1, Decimal('0.5'))
+ self.assertEqual(obj.n1, Decimal("0.5"))
diff --git a/tests/db_functions/math/test_asin.py b/tests/db_functions/math/test_asin.py
index ddbadb12a6..8a2e78ed43 100644
--- a/tests/db_functions/math/test_asin.py
+++ b/tests/db_functions/math/test_asin.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class ASinTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_asin=ASin('normal')).first()
+ obj = IntegerModel.objects.annotate(null_asin=ASin("normal")).first()
self.assertIsNone(obj.null_asin)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('0.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_asin=ASin('n1'), n2_asin=ASin('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("0.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_asin=ASin("n1"), n2_asin=ASin("n2")
+ ).first()
self.assertIsInstance(obj.n1_asin, Decimal)
self.assertIsInstance(obj.n2_asin, Decimal)
self.assertAlmostEqual(obj.n1_asin, Decimal(math.asin(obj.n1)))
@@ -26,7 +27,9 @@ class ASinTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-0.5, f2=0.87)
- obj = FloatModel.objects.annotate(f1_asin=ASin('f1'), f2_asin=ASin('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_asin=ASin("f1"), f2_asin=ASin("f2")
+ ).first()
self.assertIsInstance(obj.f1_asin, float)
self.assertIsInstance(obj.f2_asin, float)
self.assertAlmostEqual(obj.f1_asin, math.asin(obj.f1))
@@ -35,9 +38,9 @@ class ASinTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=0, normal=1, big=-1)
obj = IntegerModel.objects.annotate(
- small_asin=ASin('small'),
- normal_asin=ASin('normal'),
- big_asin=ASin('big'),
+ small_asin=ASin("small"),
+ normal_asin=ASin("normal"),
+ big_asin=ASin("big"),
).first()
self.assertIsInstance(obj.small_asin, float)
self.assertIsInstance(obj.normal_asin, float)
@@ -48,7 +51,7 @@ class ASinTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, ASin):
- DecimalModel.objects.create(n1=Decimal('0.1'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("0.1"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__asin__gt=1).get()
- self.assertEqual(obj.n1, Decimal('1.0'))
+ self.assertEqual(obj.n1, Decimal("1.0"))
diff --git a/tests/db_functions/math/test_atan.py b/tests/db_functions/math/test_atan.py
index a14e7de581..32e73e235a 100644
--- a/tests/db_functions/math/test_atan.py
+++ b/tests/db_functions/math/test_atan.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class ATanTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_atan=ATan('normal')).first()
+ obj = IntegerModel.objects.annotate(null_atan=ATan("normal")).first()
self.assertIsNone(obj.null_atan)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_atan=ATan('n1'), n2_atan=ATan('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_atan=ATan("n1"), n2_atan=ATan("n2")
+ ).first()
self.assertIsInstance(obj.n1_atan, Decimal)
self.assertIsInstance(obj.n2_atan, Decimal)
self.assertAlmostEqual(obj.n1_atan, Decimal(math.atan(obj.n1)))
@@ -26,7 +27,9 @@ class ATanTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_atan=ATan('f1'), f2_atan=ATan('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_atan=ATan("f1"), f2_atan=ATan("f2")
+ ).first()
self.assertIsInstance(obj.f1_atan, float)
self.assertIsInstance(obj.f2_atan, float)
self.assertAlmostEqual(obj.f1_atan, math.atan(obj.f1))
@@ -35,9 +38,9 @@ class ATanTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_atan=ATan('small'),
- normal_atan=ATan('normal'),
- big_atan=ATan('big'),
+ small_atan=ATan("small"),
+ normal_atan=ATan("normal"),
+ big_atan=ATan("big"),
).first()
self.assertIsInstance(obj.small_atan, float)
self.assertIsInstance(obj.normal_atan, float)
@@ -48,7 +51,7 @@ class ATanTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, ATan):
- DecimalModel.objects.create(n1=Decimal('3.12'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-5'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("3.12"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-5"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__atan__gt=0).get()
- self.assertEqual(obj.n1, Decimal('3.12'))
+ self.assertEqual(obj.n1, Decimal("3.12"))
diff --git a/tests/db_functions/math/test_atan2.py b/tests/db_functions/math/test_atan2.py
index ce9dd53187..59779e52b7 100644
--- a/tests/db_functions/math/test_atan2.py
+++ b/tests/db_functions/math/test_atan2.py
@@ -8,35 +8,34 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class ATan2Tests(TestCase):
-
def test_null(self):
IntegerModel.objects.create(big=100)
obj = IntegerModel.objects.annotate(
- null_atan2_sn=ATan2('small', 'normal'),
- null_atan2_nb=ATan2('normal', 'big'),
- null_atan2_bn=ATan2('big', 'normal'),
+ null_atan2_sn=ATan2("small", "normal"),
+ null_atan2_nb=ATan2("normal", "big"),
+ null_atan2_bn=ATan2("big", "normal"),
).first()
self.assertIsNone(obj.null_atan2_sn)
self.assertIsNone(obj.null_atan2_nb)
self.assertIsNone(obj.null_atan2_bn)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-9.9'), n2=Decimal('4.6'))
- obj = DecimalModel.objects.annotate(n_atan2=ATan2('n1', 'n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-9.9"), n2=Decimal("4.6"))
+ obj = DecimalModel.objects.annotate(n_atan2=ATan2("n1", "n2")).first()
self.assertIsInstance(obj.n_atan2, Decimal)
self.assertAlmostEqual(obj.n_atan2, Decimal(math.atan2(obj.n1, obj.n2)))
def test_float(self):
FloatModel.objects.create(f1=-25, f2=0.33)
- obj = FloatModel.objects.annotate(f_atan2=ATan2('f1', 'f2')).first()
+ obj = FloatModel.objects.annotate(f_atan2=ATan2("f1", "f2")).first()
self.assertIsInstance(obj.f_atan2, float)
self.assertAlmostEqual(obj.f_atan2, math.atan2(obj.f1, obj.f2))
def test_integer(self):
IntegerModel.objects.create(small=0, normal=1, big=10)
obj = IntegerModel.objects.annotate(
- atan2_sn=ATan2('small', 'normal'),
- atan2_nb=ATan2('normal', 'big'),
+ atan2_sn=ATan2("small", "normal"),
+ atan2_nb=ATan2("normal", "big"),
).first()
self.assertIsInstance(obj.atan2_sn, float)
self.assertIsInstance(obj.atan2_nb, float)
diff --git a/tests/db_functions/math/test_ceil.py b/tests/db_functions/math/test_ceil.py
index 86fe084185..23c3bcd84a 100644
--- a/tests/db_functions/math/test_ceil.py
+++ b/tests/db_functions/math/test_ceil.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class CeilTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_ceil=Ceil('normal')).first()
+ obj = IntegerModel.objects.annotate(null_ceil=Ceil("normal")).first()
self.assertIsNone(obj.null_ceil)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_ceil=Ceil('n1'), n2_ceil=Ceil('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_ceil=Ceil("n1"), n2_ceil=Ceil("n2")
+ ).first()
self.assertIsInstance(obj.n1_ceil, Decimal)
self.assertIsInstance(obj.n2_ceil, Decimal)
self.assertEqual(obj.n1_ceil, Decimal(math.ceil(obj.n1)))
@@ -26,7 +27,9 @@ class CeilTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-12.5, f2=21.33)
- obj = FloatModel.objects.annotate(f1_ceil=Ceil('f1'), f2_ceil=Ceil('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_ceil=Ceil("f1"), f2_ceil=Ceil("f2")
+ ).first()
self.assertIsInstance(obj.f1_ceil, float)
self.assertIsInstance(obj.f2_ceil, float)
self.assertEqual(obj.f1_ceil, math.ceil(obj.f1))
@@ -35,9 +38,9 @@ class CeilTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-11, normal=0, big=-100)
obj = IntegerModel.objects.annotate(
- small_ceil=Ceil('small'),
- normal_ceil=Ceil('normal'),
- big_ceil=Ceil('big'),
+ small_ceil=Ceil("small"),
+ normal_ceil=Ceil("normal"),
+ big_ceil=Ceil("big"),
).first()
self.assertIsInstance(obj.small_ceil, int)
self.assertIsInstance(obj.normal_ceil, int)
@@ -48,7 +51,7 @@ class CeilTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Ceil):
- DecimalModel.objects.create(n1=Decimal('3.12'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('1.25'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("3.12"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("1.25"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__ceil__gt=3).get()
- self.assertEqual(obj.n1, Decimal('3.12'))
+ self.assertEqual(obj.n1, Decimal("3.12"))
diff --git a/tests/db_functions/math/test_cos.py b/tests/db_functions/math/test_cos.py
index 73e59f0463..9e96589bac 100644
--- a/tests/db_functions/math/test_cos.py
+++ b/tests/db_functions/math/test_cos.py
@@ -10,15 +10,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class CosTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_cos=Cos('normal')).first()
+ obj = IntegerModel.objects.annotate(null_cos=Cos("normal")).first()
self.assertIsNone(obj.null_cos)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_cos=Cos('n1'), n2_cos=Cos('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(n1_cos=Cos("n1"), n2_cos=Cos("n2")).first()
self.assertIsInstance(obj.n1_cos, Decimal)
self.assertIsInstance(obj.n2_cos, Decimal)
self.assertAlmostEqual(obj.n1_cos, Decimal(math.cos(obj.n1)))
@@ -26,7 +25,7 @@ class CosTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_cos=Cos('f1'), f2_cos=Cos('f2')).first()
+ obj = FloatModel.objects.annotate(f1_cos=Cos("f1"), f2_cos=Cos("f2")).first()
self.assertIsInstance(obj.f1_cos, float)
self.assertIsInstance(obj.f2_cos, float)
self.assertAlmostEqual(obj.f1_cos, math.cos(obj.f1))
@@ -35,9 +34,9 @@ class CosTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_cos=Cos('small'),
- normal_cos=Cos('normal'),
- big_cos=Cos('big'),
+ small_cos=Cos("small"),
+ normal_cos=Cos("normal"),
+ big_cos=Cos("big"),
).first()
self.assertIsInstance(obj.small_cos, float)
self.assertIsInstance(obj.normal_cos, float)
@@ -48,7 +47,7 @@ class CosTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Cos):
- DecimalModel.objects.create(n1=Decimal('-8.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('3.14'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("-8.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("3.14"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__cos__gt=-0.2).get()
- self.assertEqual(obj.n1, Decimal('-8.0'))
+ self.assertEqual(obj.n1, Decimal("-8.0"))
diff --git a/tests/db_functions/math/test_cot.py b/tests/db_functions/math/test_cot.py
index d876648598..04fdcb475c 100644
--- a/tests/db_functions/math/test_cot.py
+++ b/tests/db_functions/math/test_cot.py
@@ -10,15 +10,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class CotTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_cot=Cot('normal')).first()
+ obj = IntegerModel.objects.annotate(null_cot=Cot("normal")).first()
self.assertIsNone(obj.null_cot)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_cot=Cot('n1'), n2_cot=Cot('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(n1_cot=Cot("n1"), n2_cot=Cot("n2")).first()
self.assertIsInstance(obj.n1_cot, Decimal)
self.assertIsInstance(obj.n2_cot, Decimal)
self.assertAlmostEqual(obj.n1_cot, Decimal(1 / math.tan(obj.n1)))
@@ -26,7 +25,7 @@ class CotTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_cot=Cot('f1'), f2_cot=Cot('f2')).first()
+ obj = FloatModel.objects.annotate(f1_cot=Cot("f1"), f2_cot=Cot("f2")).first()
self.assertIsInstance(obj.f1_cot, float)
self.assertIsInstance(obj.f2_cot, float)
self.assertAlmostEqual(obj.f1_cot, 1 / math.tan(obj.f1))
@@ -35,9 +34,9 @@ class CotTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-5, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_cot=Cot('small'),
- normal_cot=Cot('normal'),
- big_cot=Cot('big'),
+ small_cot=Cot("small"),
+ normal_cot=Cot("normal"),
+ big_cot=Cot("big"),
).first()
self.assertIsInstance(obj.small_cot, float)
self.assertIsInstance(obj.normal_cot, float)
@@ -48,7 +47,7 @@ class CotTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Cot):
- DecimalModel.objects.create(n1=Decimal('12.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("12.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__cot__gt=0).get()
- self.assertEqual(obj.n1, Decimal('1.0'))
+ self.assertEqual(obj.n1, Decimal("1.0"))
diff --git a/tests/db_functions/math/test_degrees.py b/tests/db_functions/math/test_degrees.py
index ab687b8da2..06a5ac7d88 100644
--- a/tests/db_functions/math/test_degrees.py
+++ b/tests/db_functions/math/test_degrees.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class DegreesTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_degrees=Degrees('normal')).first()
+ obj = IntegerModel.objects.annotate(null_degrees=Degrees("normal")).first()
self.assertIsNone(obj.null_degrees)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_degrees=Degrees('n1'), n2_degrees=Degrees('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_degrees=Degrees("n1"), n2_degrees=Degrees("n2")
+ ).first()
self.assertIsInstance(obj.n1_degrees, Decimal)
self.assertIsInstance(obj.n2_degrees, Decimal)
self.assertAlmostEqual(obj.n1_degrees, Decimal(math.degrees(obj.n1)))
@@ -26,7 +27,9 @@ class DegreesTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_degrees=Degrees('f1'), f2_degrees=Degrees('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_degrees=Degrees("f1"), f2_degrees=Degrees("f2")
+ ).first()
self.assertIsInstance(obj.f1_degrees, float)
self.assertIsInstance(obj.f2_degrees, float)
self.assertAlmostEqual(obj.f1_degrees, math.degrees(obj.f1))
@@ -35,9 +38,9 @@ class DegreesTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_degrees=Degrees('small'),
- normal_degrees=Degrees('normal'),
- big_degrees=Degrees('big'),
+ small_degrees=Degrees("small"),
+ normal_degrees=Degrees("normal"),
+ big_degrees=Degrees("big"),
).first()
self.assertIsInstance(obj.small_degrees, float)
self.assertIsInstance(obj.normal_degrees, float)
@@ -48,7 +51,7 @@ class DegreesTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Degrees):
- DecimalModel.objects.create(n1=Decimal('5.4'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-30'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("5.4"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-30"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__degrees__gt=0).get()
- self.assertEqual(obj.n1, Decimal('5.4'))
+ self.assertEqual(obj.n1, Decimal("5.4"))
diff --git a/tests/db_functions/math/test_exp.py b/tests/db_functions/math/test_exp.py
index a1e806ae45..885549b8cd 100644
--- a/tests/db_functions/math/test_exp.py
+++ b/tests/db_functions/math/test_exp.py
@@ -10,15 +10,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class ExpTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_exp=Exp('normal')).first()
+ obj = IntegerModel.objects.annotate(null_exp=Exp("normal")).first()
self.assertIsNone(obj.null_exp)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_exp=Exp('n1'), n2_exp=Exp('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(n1_exp=Exp("n1"), n2_exp=Exp("n2")).first()
self.assertIsInstance(obj.n1_exp, Decimal)
self.assertIsInstance(obj.n2_exp, Decimal)
self.assertAlmostEqual(obj.n1_exp, Decimal(math.exp(obj.n1)))
@@ -26,7 +25,7 @@ class ExpTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_exp=Exp('f1'), f2_exp=Exp('f2')).first()
+ obj = FloatModel.objects.annotate(f1_exp=Exp("f1"), f2_exp=Exp("f2")).first()
self.assertIsInstance(obj.f1_exp, float)
self.assertIsInstance(obj.f2_exp, float)
self.assertAlmostEqual(obj.f1_exp, math.exp(obj.f1))
@@ -35,9 +34,9 @@ class ExpTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_exp=Exp('small'),
- normal_exp=Exp('normal'),
- big_exp=Exp('big'),
+ small_exp=Exp("small"),
+ normal_exp=Exp("normal"),
+ big_exp=Exp("big"),
).first()
self.assertIsInstance(obj.small_exp, float)
self.assertIsInstance(obj.normal_exp, float)
@@ -48,7 +47,7 @@ class ExpTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Exp):
- DecimalModel.objects.create(n1=Decimal('12.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("12.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__exp__gt=10).get()
- self.assertEqual(obj.n1, Decimal('12.0'))
+ self.assertEqual(obj.n1, Decimal("12.0"))
diff --git a/tests/db_functions/math/test_floor.py b/tests/db_functions/math/test_floor.py
index 1068e55476..b660c1c48e 100644
--- a/tests/db_functions/math/test_floor.py
+++ b/tests/db_functions/math/test_floor.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class FloorTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_floor=Floor('normal')).first()
+ obj = IntegerModel.objects.annotate(null_floor=Floor("normal")).first()
self.assertIsNone(obj.null_floor)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_floor=Floor('n1'), n2_floor=Floor('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_floor=Floor("n1"), n2_floor=Floor("n2")
+ ).first()
self.assertIsInstance(obj.n1_floor, Decimal)
self.assertIsInstance(obj.n2_floor, Decimal)
self.assertEqual(obj.n1_floor, Decimal(math.floor(obj.n1)))
@@ -26,7 +27,9 @@ class FloorTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_floor=Floor('f1'), f2_floor=Floor('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_floor=Floor("f1"), f2_floor=Floor("f2")
+ ).first()
self.assertIsInstance(obj.f1_floor, float)
self.assertIsInstance(obj.f2_floor, float)
self.assertEqual(obj.f1_floor, math.floor(obj.f1))
@@ -35,9 +38,9 @@ class FloorTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_floor=Floor('small'),
- normal_floor=Floor('normal'),
- big_floor=Floor('big'),
+ small_floor=Floor("small"),
+ normal_floor=Floor("normal"),
+ big_floor=Floor("big"),
).first()
self.assertIsInstance(obj.small_floor, int)
self.assertIsInstance(obj.normal_floor, int)
@@ -48,7 +51,7 @@ class FloorTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Floor):
- DecimalModel.objects.create(n1=Decimal('5.4'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('3.4'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("5.4"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("3.4"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__floor__gt=4).get()
- self.assertEqual(obj.n1, Decimal('5.4'))
+ self.assertEqual(obj.n1, Decimal("5.4"))
diff --git a/tests/db_functions/math/test_ln.py b/tests/db_functions/math/test_ln.py
index fd2ac87c06..d8a87a348a 100644
--- a/tests/db_functions/math/test_ln.py
+++ b/tests/db_functions/math/test_ln.py
@@ -10,15 +10,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class LnTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_ln=Ln('normal')).first()
+ obj = IntegerModel.objects.annotate(null_ln=Ln("normal")).first()
self.assertIsNone(obj.null_ln)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_ln=Ln('n1'), n2_ln=Ln('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(n1_ln=Ln("n1"), n2_ln=Ln("n2")).first()
self.assertIsInstance(obj.n1_ln, Decimal)
self.assertIsInstance(obj.n2_ln, Decimal)
self.assertAlmostEqual(obj.n1_ln, Decimal(math.log(obj.n1)))
@@ -26,7 +25,7 @@ class LnTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_ln=Ln('f1'), f2_ln=Ln('f2')).first()
+ obj = FloatModel.objects.annotate(f1_ln=Ln("f1"), f2_ln=Ln("f2")).first()
self.assertIsInstance(obj.f1_ln, float)
self.assertIsInstance(obj.f2_ln, float)
self.assertAlmostEqual(obj.f1_ln, math.log(obj.f1))
@@ -35,9 +34,9 @@ class LnTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=20, normal=15, big=1)
obj = IntegerModel.objects.annotate(
- small_ln=Ln('small'),
- normal_ln=Ln('normal'),
- big_ln=Ln('big'),
+ small_ln=Ln("small"),
+ normal_ln=Ln("normal"),
+ big_ln=Ln("big"),
).first()
self.assertIsInstance(obj.small_ln, float)
self.assertIsInstance(obj.normal_ln, float)
@@ -48,7 +47,7 @@ class LnTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Ln):
- DecimalModel.objects.create(n1=Decimal('12.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("12.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__ln__gt=0).get()
- self.assertEqual(obj.n1, Decimal('12.0'))
+ self.assertEqual(obj.n1, Decimal("12.0"))
diff --git a/tests/db_functions/math/test_log.py b/tests/db_functions/math/test_log.py
index 293993800a..655dcbbcfe 100644
--- a/tests/db_functions/math/test_log.py
+++ b/tests/db_functions/math/test_log.py
@@ -8,36 +8,35 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class LogTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create(big=100)
obj = IntegerModel.objects.annotate(
- null_log_small=Log('small', 'normal'),
- null_log_normal=Log('normal', 'big'),
- null_log_big=Log('big', 'normal'),
+ null_log_small=Log("small", "normal"),
+ null_log_normal=Log("normal", "big"),
+ null_log_big=Log("big", "normal"),
).first()
self.assertIsNone(obj.null_log_small)
self.assertIsNone(obj.null_log_normal)
self.assertIsNone(obj.null_log_big)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('12.9'), n2=Decimal('3.6'))
- obj = DecimalModel.objects.annotate(n_log=Log('n1', 'n2')).first()
+ DecimalModel.objects.create(n1=Decimal("12.9"), n2=Decimal("3.6"))
+ obj = DecimalModel.objects.annotate(n_log=Log("n1", "n2")).first()
self.assertIsInstance(obj.n_log, Decimal)
self.assertAlmostEqual(obj.n_log, Decimal(math.log(obj.n2, obj.n1)))
def test_float(self):
FloatModel.objects.create(f1=2.0, f2=4.0)
- obj = FloatModel.objects.annotate(f_log=Log('f1', 'f2')).first()
+ obj = FloatModel.objects.annotate(f_log=Log("f1", "f2")).first()
self.assertIsInstance(obj.f_log, float)
self.assertAlmostEqual(obj.f_log, math.log(obj.f2, obj.f1))
def test_integer(self):
IntegerModel.objects.create(small=4, normal=8, big=2)
obj = IntegerModel.objects.annotate(
- small_log=Log('small', 'big'),
- normal_log=Log('normal', 'big'),
- big_log=Log('big', 'big'),
+ small_log=Log("small", "big"),
+ normal_log=Log("normal", "big"),
+ big_log=Log("big", "big"),
).first()
self.assertIsInstance(obj.small_log, float)
self.assertIsInstance(obj.normal_log, float)
diff --git a/tests/db_functions/math/test_mod.py b/tests/db_functions/math/test_mod.py
index dc363432b7..919b9419d2 100644
--- a/tests/db_functions/math/test_mod.py
+++ b/tests/db_functions/math/test_mod.py
@@ -8,34 +8,33 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class ModTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create(big=100)
obj = IntegerModel.objects.annotate(
- null_mod_small=Mod('small', 'normal'),
- null_mod_normal=Mod('normal', 'big'),
+ null_mod_small=Mod("small", "normal"),
+ null_mod_normal=Mod("normal", "big"),
).first()
self.assertIsNone(obj.null_mod_small)
self.assertIsNone(obj.null_mod_normal)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-9.9'), n2=Decimal('4.6'))
- obj = DecimalModel.objects.annotate(n_mod=Mod('n1', 'n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-9.9"), n2=Decimal("4.6"))
+ obj = DecimalModel.objects.annotate(n_mod=Mod("n1", "n2")).first()
self.assertIsInstance(obj.n_mod, Decimal)
self.assertAlmostEqual(obj.n_mod, Decimal(math.fmod(obj.n1, obj.n2)))
def test_float(self):
FloatModel.objects.create(f1=-25, f2=0.33)
- obj = FloatModel.objects.annotate(f_mod=Mod('f1', 'f2')).first()
+ obj = FloatModel.objects.annotate(f_mod=Mod("f1", "f2")).first()
self.assertIsInstance(obj.f_mod, float)
self.assertAlmostEqual(obj.f_mod, math.fmod(obj.f1, obj.f2))
def test_integer(self):
IntegerModel.objects.create(small=20, normal=15, big=1)
obj = IntegerModel.objects.annotate(
- small_mod=Mod('small', 'normal'),
- normal_mod=Mod('normal', 'big'),
- big_mod=Mod('big', 'small'),
+ small_mod=Mod("small", "normal"),
+ normal_mod=Mod("normal", "big"),
+ big_mod=Mod("big", "small"),
).first()
self.assertIsInstance(obj.small_mod, float)
self.assertIsInstance(obj.normal_mod, float)
diff --git a/tests/db_functions/math/test_pi.py b/tests/db_functions/math/test_pi.py
index 2446420fd3..11e4638168 100644
--- a/tests/db_functions/math/test_pi.py
+++ b/tests/db_functions/math/test_pi.py
@@ -7,7 +7,6 @@ from ..models import FloatModel
class PiTests(TestCase):
-
def test(self):
FloatModel.objects.create(f1=2.5, f2=15.9)
obj = FloatModel.objects.annotate(pi=Pi()).first()
diff --git a/tests/db_functions/math/test_power.py b/tests/db_functions/math/test_power.py
index 94929d38b7..44a90f7571 100644
--- a/tests/db_functions/math/test_power.py
+++ b/tests/db_functions/math/test_power.py
@@ -7,40 +7,39 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class PowerTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create(big=100)
obj = IntegerModel.objects.annotate(
- null_power_small=Power('small', 'normal'),
- null_power_normal=Power('normal', 'big'),
- null_power_big=Power('big', 'normal'),
+ null_power_small=Power("small", "normal"),
+ null_power_normal=Power("normal", "big"),
+ null_power_big=Power("big", "normal"),
).first()
self.assertIsNone(obj.null_power_small)
self.assertIsNone(obj.null_power_normal)
self.assertIsNone(obj.null_power_big)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('1.0'), n2=Decimal('-0.6'))
- obj = DecimalModel.objects.annotate(n_power=Power('n1', 'n2')).first()
+ DecimalModel.objects.create(n1=Decimal("1.0"), n2=Decimal("-0.6"))
+ obj = DecimalModel.objects.annotate(n_power=Power("n1", "n2")).first()
self.assertIsInstance(obj.n_power, Decimal)
- self.assertAlmostEqual(obj.n_power, Decimal(obj.n1 ** obj.n2))
+ self.assertAlmostEqual(obj.n_power, Decimal(obj.n1**obj.n2))
def test_float(self):
FloatModel.objects.create(f1=2.3, f2=1.1)
- obj = FloatModel.objects.annotate(f_power=Power('f1', 'f2')).first()
+ obj = FloatModel.objects.annotate(f_power=Power("f1", "f2")).first()
self.assertIsInstance(obj.f_power, float)
- self.assertAlmostEqual(obj.f_power, obj.f1 ** obj.f2)
+ self.assertAlmostEqual(obj.f_power, obj.f1**obj.f2)
def test_integer(self):
IntegerModel.objects.create(small=-1, normal=20, big=3)
obj = IntegerModel.objects.annotate(
- small_power=Power('small', 'normal'),
- normal_power=Power('normal', 'big'),
- big_power=Power('big', 'small'),
+ small_power=Power("small", "normal"),
+ normal_power=Power("normal", "big"),
+ big_power=Power("big", "small"),
).first()
self.assertIsInstance(obj.small_power, float)
self.assertIsInstance(obj.normal_power, float)
self.assertIsInstance(obj.big_power, float)
- self.assertAlmostEqual(obj.small_power, obj.small ** obj.normal)
- self.assertAlmostEqual(obj.normal_power, obj.normal ** obj.big)
- self.assertAlmostEqual(obj.big_power, obj.big ** obj.small)
+ self.assertAlmostEqual(obj.small_power, obj.small**obj.normal)
+ self.assertAlmostEqual(obj.normal_power, obj.normal**obj.big)
+ self.assertAlmostEqual(obj.big_power, obj.big**obj.small)
diff --git a/tests/db_functions/math/test_radians.py b/tests/db_functions/math/test_radians.py
index ac51155641..cd94a016e4 100644
--- a/tests/db_functions/math/test_radians.py
+++ b/tests/db_functions/math/test_radians.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class RadiansTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_radians=Radians('normal')).first()
+ obj = IntegerModel.objects.annotate(null_radians=Radians("normal")).first()
self.assertIsNone(obj.null_radians)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_radians=Radians('n1'), n2_radians=Radians('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_radians=Radians("n1"), n2_radians=Radians("n2")
+ ).first()
self.assertIsInstance(obj.n1_radians, Decimal)
self.assertIsInstance(obj.n2_radians, Decimal)
self.assertAlmostEqual(obj.n1_radians, Decimal(math.radians(obj.n1)))
@@ -26,7 +27,9 @@ class RadiansTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_radians=Radians('f1'), f2_radians=Radians('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_radians=Radians("f1"), f2_radians=Radians("f2")
+ ).first()
self.assertIsInstance(obj.f1_radians, float)
self.assertIsInstance(obj.f2_radians, float)
self.assertAlmostEqual(obj.f1_radians, math.radians(obj.f1))
@@ -35,9 +38,9 @@ class RadiansTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_radians=Radians('small'),
- normal_radians=Radians('normal'),
- big_radians=Radians('big'),
+ small_radians=Radians("small"),
+ normal_radians=Radians("normal"),
+ big_radians=Radians("big"),
).first()
self.assertIsInstance(obj.small_radians, float)
self.assertIsInstance(obj.normal_radians, float)
@@ -48,7 +51,7 @@ class RadiansTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Radians):
- DecimalModel.objects.create(n1=Decimal('2.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("2.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__radians__gt=0).get()
- self.assertEqual(obj.n1, Decimal('2.0'))
+ self.assertEqual(obj.n1, Decimal("2.0"))
diff --git a/tests/db_functions/math/test_round.py b/tests/db_functions/math/test_round.py
index 320d37fe4e..04ece4246d 100644
--- a/tests/db_functions/math/test_round.py
+++ b/tests/db_functions/math/test_round.py
@@ -11,35 +11,36 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class RoundTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_round=Round('normal')).first()
+ obj = IntegerModel.objects.annotate(null_round=Round("normal")).first()
self.assertIsNone(obj.null_round)
def test_null_with_precision(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_round=Round('normal', 5)).first()
+ obj = IntegerModel.objects.annotate(null_round=Round("normal", 5)).first()
self.assertIsNone(obj.null_round)
def test_null_with_negative_precision(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_round=Round('normal', -1)).first()
+ obj = IntegerModel.objects.annotate(null_round=Round("normal", -1)).first()
self.assertIsNone(obj.null_round)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_round=Round('n1'), n2_round=Round('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_round=Round("n1"), n2_round=Round("n2")
+ ).first()
self.assertIsInstance(obj.n1_round, Decimal)
self.assertIsInstance(obj.n2_round, Decimal)
self.assertAlmostEqual(obj.n1_round, obj.n1, places=0)
self.assertAlmostEqual(obj.n2_round, obj.n2, places=0)
def test_decimal_with_precision(self):
- DecimalModel.objects.create(n1=Decimal('-5.75'), n2=Pi())
+ DecimalModel.objects.create(n1=Decimal("-5.75"), n2=Pi())
obj = DecimalModel.objects.annotate(
- n1_round=Round('n1', 1),
- n2_round=Round('n2', 5),
+ n1_round=Round("n1", 1),
+ n2_round=Round("n2", 5),
).first()
self.assertIsInstance(obj.n1_round, Decimal)
self.assertIsInstance(obj.n2_round, Decimal)
@@ -47,14 +48,16 @@ class RoundTests(TestCase):
self.assertAlmostEqual(obj.n2_round, obj.n2, places=5)
def test_decimal_with_negative_precision(self):
- DecimalModel.objects.create(n1=Decimal('365.25'))
- obj = DecimalModel.objects.annotate(n1_round=Round('n1', -1)).first()
+ DecimalModel.objects.create(n1=Decimal("365.25"))
+ obj = DecimalModel.objects.annotate(n1_round=Round("n1", -1)).first()
self.assertIsInstance(obj.n1_round, Decimal)
self.assertEqual(obj.n1_round, 370)
def test_float(self):
FloatModel.objects.create(f1=-27.55, f2=0.55)
- obj = FloatModel.objects.annotate(f1_round=Round('f1'), f2_round=Round('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_round=Round("f1"), f2_round=Round("f2")
+ ).first()
self.assertIsInstance(obj.f1_round, float)
self.assertIsInstance(obj.f2_round, float)
self.assertAlmostEqual(obj.f1_round, obj.f1, places=0)
@@ -63,8 +66,8 @@ class RoundTests(TestCase):
def test_float_with_precision(self):
FloatModel.objects.create(f1=-5.75, f2=Pi())
obj = FloatModel.objects.annotate(
- f1_round=Round('f1', 1),
- f2_round=Round('f2', 5),
+ f1_round=Round("f1", 1),
+ f2_round=Round("f2", 5),
).first()
self.assertIsInstance(obj.f1_round, float)
self.assertIsInstance(obj.f2_round, float)
@@ -73,16 +76,16 @@ class RoundTests(TestCase):
def test_float_with_negative_precision(self):
FloatModel.objects.create(f1=365.25)
- obj = FloatModel.objects.annotate(f1_round=Round('f1', -1)).first()
+ obj = FloatModel.objects.annotate(f1_round=Round("f1", -1)).first()
self.assertIsInstance(obj.f1_round, float)
self.assertEqual(obj.f1_round, 370)
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_round=Round('small'),
- normal_round=Round('normal'),
- big_round=Round('big'),
+ small_round=Round("small"),
+ normal_round=Round("normal"),
+ big_round=Round("big"),
).first()
self.assertIsInstance(obj.small_round, int)
self.assertIsInstance(obj.normal_round, int)
@@ -94,9 +97,9 @@ class RoundTests(TestCase):
def test_integer_with_precision(self):
IntegerModel.objects.create(small=-5, normal=3, big=-100)
obj = IntegerModel.objects.annotate(
- small_round=Round('small', 1),
- normal_round=Round('normal', 5),
- big_round=Round('big', 2),
+ small_round=Round("small", 1),
+ normal_round=Round("normal", 5),
+ big_round=Round("big", 2),
).first()
self.assertIsInstance(obj.small_round, int)
self.assertIsInstance(obj.normal_round, int)
@@ -107,23 +110,23 @@ class RoundTests(TestCase):
def test_integer_with_negative_precision(self):
IntegerModel.objects.create(normal=365)
- obj = IntegerModel.objects.annotate(normal_round=Round('normal', -1)).first()
+ obj = IntegerModel.objects.annotate(normal_round=Round("normal", -1)).first()
self.assertIsInstance(obj.normal_round, int)
self.assertEqual(obj.normal_round, 370)
def test_transform(self):
with register_lookup(DecimalField, Round):
- DecimalModel.objects.create(n1=Decimal('2.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("2.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__round__gt=0).get()
- self.assertEqual(obj.n1, Decimal('2.0'))
+ self.assertEqual(obj.n1, Decimal("2.0"))
@unittest.skipUnless(
- connection.vendor == 'sqlite',
+ connection.vendor == "sqlite",
"SQLite doesn't support negative precision.",
)
def test_unsupported_negative_precision(self):
FloatModel.objects.create(f1=123.45)
- msg = 'SQLite does not support negative precision.'
+ msg = "SQLite does not support negative precision."
with self.assertRaisesMessage(ValueError, msg):
- FloatModel.objects.annotate(value=Round('f1', -1)).first()
+ FloatModel.objects.annotate(value=Round("f1", -1)).first()
diff --git a/tests/db_functions/math/test_sign.py b/tests/db_functions/math/test_sign.py
index 0458932cee..c099441a19 100644
--- a/tests/db_functions/math/test_sign.py
+++ b/tests/db_functions/math/test_sign.py
@@ -9,23 +9,26 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class SignTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_sign=Sign('normal')).first()
+ obj = IntegerModel.objects.annotate(null_sign=Sign("normal")).first()
self.assertIsNone(obj.null_sign)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_sign=Sign('n1'), n2_sign=Sign('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_sign=Sign("n1"), n2_sign=Sign("n2")
+ ).first()
self.assertIsInstance(obj.n1_sign, Decimal)
self.assertIsInstance(obj.n2_sign, Decimal)
- self.assertEqual(obj.n1_sign, Decimal('-1'))
- self.assertEqual(obj.n2_sign, Decimal('1'))
+ self.assertEqual(obj.n1_sign, Decimal("-1"))
+ self.assertEqual(obj.n2_sign, Decimal("1"))
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_sign=Sign('f1'), f2_sign=Sign('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_sign=Sign("f1"), f2_sign=Sign("f2")
+ ).first()
self.assertIsInstance(obj.f1_sign, float)
self.assertIsInstance(obj.f2_sign, float)
self.assertEqual(obj.f1_sign, -1.0)
@@ -34,9 +37,9 @@ class SignTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=0, big=20)
obj = IntegerModel.objects.annotate(
- small_sign=Sign('small'),
- normal_sign=Sign('normal'),
- big_sign=Sign('big'),
+ small_sign=Sign("small"),
+ normal_sign=Sign("normal"),
+ big_sign=Sign("big"),
).first()
self.assertIsInstance(obj.small_sign, int)
self.assertIsInstance(obj.normal_sign, int)
@@ -47,7 +50,7 @@ class SignTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Sign):
- DecimalModel.objects.create(n1=Decimal('5.4'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('-0.1'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("5.4"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("-0.1"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__sign__lt=0, n2__sign=0).get()
- self.assertEqual(obj.n1, Decimal('-0.1'))
+ self.assertEqual(obj.n1, Decimal("-0.1"))
diff --git a/tests/db_functions/math/test_sin.py b/tests/db_functions/math/test_sin.py
index be7d1515bd..e6c93d75da 100644
--- a/tests/db_functions/math/test_sin.py
+++ b/tests/db_functions/math/test_sin.py
@@ -10,15 +10,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class SinTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_sin=Sin('normal')).first()
+ obj = IntegerModel.objects.annotate(null_sin=Sin("normal")).first()
self.assertIsNone(obj.null_sin)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_sin=Sin('n1'), n2_sin=Sin('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(n1_sin=Sin("n1"), n2_sin=Sin("n2")).first()
self.assertIsInstance(obj.n1_sin, Decimal)
self.assertIsInstance(obj.n2_sin, Decimal)
self.assertAlmostEqual(obj.n1_sin, Decimal(math.sin(obj.n1)))
@@ -26,7 +25,7 @@ class SinTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_sin=Sin('f1'), f2_sin=Sin('f2')).first()
+ obj = FloatModel.objects.annotate(f1_sin=Sin("f1"), f2_sin=Sin("f2")).first()
self.assertIsInstance(obj.f1_sin, float)
self.assertIsInstance(obj.f2_sin, float)
self.assertAlmostEqual(obj.f1_sin, math.sin(obj.f1))
@@ -35,9 +34,9 @@ class SinTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_sin=Sin('small'),
- normal_sin=Sin('normal'),
- big_sin=Sin('big'),
+ small_sin=Sin("small"),
+ normal_sin=Sin("normal"),
+ big_sin=Sin("big"),
).first()
self.assertIsInstance(obj.small_sin, float)
self.assertIsInstance(obj.normal_sin, float)
@@ -48,7 +47,7 @@ class SinTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Sin):
- DecimalModel.objects.create(n1=Decimal('5.4'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('0.1'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("5.4"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("0.1"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__sin__lt=0).get()
- self.assertEqual(obj.n1, Decimal('5.4'))
+ self.assertEqual(obj.n1, Decimal("5.4"))
diff --git a/tests/db_functions/math/test_sqrt.py b/tests/db_functions/math/test_sqrt.py
index baafaea723..b7751d929e 100644
--- a/tests/db_functions/math/test_sqrt.py
+++ b/tests/db_functions/math/test_sqrt.py
@@ -10,15 +10,16 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class SqrtTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_sqrt=Sqrt('normal')).first()
+ obj = IntegerModel.objects.annotate(null_sqrt=Sqrt("normal")).first()
self.assertIsNone(obj.null_sqrt)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_sqrt=Sqrt('n1'), n2_sqrt=Sqrt('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(
+ n1_sqrt=Sqrt("n1"), n2_sqrt=Sqrt("n2")
+ ).first()
self.assertIsInstance(obj.n1_sqrt, Decimal)
self.assertIsInstance(obj.n2_sqrt, Decimal)
self.assertAlmostEqual(obj.n1_sqrt, Decimal(math.sqrt(obj.n1)))
@@ -26,7 +27,9 @@ class SqrtTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_sqrt=Sqrt('f1'), f2_sqrt=Sqrt('f2')).first()
+ obj = FloatModel.objects.annotate(
+ f1_sqrt=Sqrt("f1"), f2_sqrt=Sqrt("f2")
+ ).first()
self.assertIsInstance(obj.f1_sqrt, float)
self.assertIsInstance(obj.f2_sqrt, float)
self.assertAlmostEqual(obj.f1_sqrt, math.sqrt(obj.f1))
@@ -35,9 +38,9 @@ class SqrtTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=20, normal=15, big=1)
obj = IntegerModel.objects.annotate(
- small_sqrt=Sqrt('small'),
- normal_sqrt=Sqrt('normal'),
- big_sqrt=Sqrt('big'),
+ small_sqrt=Sqrt("small"),
+ normal_sqrt=Sqrt("normal"),
+ big_sqrt=Sqrt("big"),
).first()
self.assertIsInstance(obj.small_sqrt, float)
self.assertIsInstance(obj.normal_sqrt, float)
@@ -48,7 +51,7 @@ class SqrtTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Sqrt):
- DecimalModel.objects.create(n1=Decimal('6.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('1.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("6.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("1.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__sqrt__gt=2).get()
- self.assertEqual(obj.n1, Decimal('6.0'))
+ self.assertEqual(obj.n1, Decimal("6.0"))
diff --git a/tests/db_functions/math/test_tan.py b/tests/db_functions/math/test_tan.py
index 51f7ad994c..db9c0ee4b3 100644
--- a/tests/db_functions/math/test_tan.py
+++ b/tests/db_functions/math/test_tan.py
@@ -10,15 +10,14 @@ from ..models import DecimalModel, FloatModel, IntegerModel
class TanTests(TestCase):
-
def test_null(self):
IntegerModel.objects.create()
- obj = IntegerModel.objects.annotate(null_tan=Tan('normal')).first()
+ obj = IntegerModel.objects.annotate(null_tan=Tan("normal")).first()
self.assertIsNone(obj.null_tan)
def test_decimal(self):
- DecimalModel.objects.create(n1=Decimal('-12.9'), n2=Decimal('0.6'))
- obj = DecimalModel.objects.annotate(n1_tan=Tan('n1'), n2_tan=Tan('n2')).first()
+ DecimalModel.objects.create(n1=Decimal("-12.9"), n2=Decimal("0.6"))
+ obj = DecimalModel.objects.annotate(n1_tan=Tan("n1"), n2_tan=Tan("n2")).first()
self.assertIsInstance(obj.n1_tan, Decimal)
self.assertIsInstance(obj.n2_tan, Decimal)
self.assertAlmostEqual(obj.n1_tan, Decimal(math.tan(obj.n1)))
@@ -26,7 +25,7 @@ class TanTests(TestCase):
def test_float(self):
FloatModel.objects.create(f1=-27.5, f2=0.33)
- obj = FloatModel.objects.annotate(f1_tan=Tan('f1'), f2_tan=Tan('f2')).first()
+ obj = FloatModel.objects.annotate(f1_tan=Tan("f1"), f2_tan=Tan("f2")).first()
self.assertIsInstance(obj.f1_tan, float)
self.assertIsInstance(obj.f2_tan, float)
self.assertAlmostEqual(obj.f1_tan, math.tan(obj.f1))
@@ -35,9 +34,9 @@ class TanTests(TestCase):
def test_integer(self):
IntegerModel.objects.create(small=-20, normal=15, big=-1)
obj = IntegerModel.objects.annotate(
- small_tan=Tan('small'),
- normal_tan=Tan('normal'),
- big_tan=Tan('big'),
+ small_tan=Tan("small"),
+ normal_tan=Tan("normal"),
+ big_tan=Tan("big"),
).first()
self.assertIsInstance(obj.small_tan, float)
self.assertIsInstance(obj.normal_tan, float)
@@ -48,7 +47,7 @@ class TanTests(TestCase):
def test_transform(self):
with register_lookup(DecimalField, Tan):
- DecimalModel.objects.create(n1=Decimal('0.0'), n2=Decimal('0'))
- DecimalModel.objects.create(n1=Decimal('12.0'), n2=Decimal('0'))
+ DecimalModel.objects.create(n1=Decimal("0.0"), n2=Decimal("0"))
+ DecimalModel.objects.create(n1=Decimal("12.0"), n2=Decimal("0"))
obj = DecimalModel.objects.filter(n1__tan__lt=0).get()
- self.assertEqual(obj.n1, Decimal('12.0'))
+ self.assertEqual(obj.n1, Decimal("12.0"))