Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
1c95737e
Kaydet (Commit)
1c95737e
authored
Ock 10, 2018
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reduced redundancy in DecimalField tests with subTest().
üst
db9cd1b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
test_decimalfield.py
tests/forms_tests/field_tests/test_decimalfield.py
+12
-14
No files found.
tests/forms_tests/field_tests/test_decimalfield.py
Dosyayı görüntüle @
1c95737e
...
...
@@ -22,21 +22,9 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
self
.
assertEqual
(
f
.
clean
(
'3.14'
),
decimal
.
Decimal
(
"3.14"
))
self
.
assertEqual
(
f
.
clean
(
3.14
),
decimal
.
Decimal
(
"3.14"
))
self
.
assertEqual
(
f
.
clean
(
decimal
.
Decimal
(
'3.14'
)),
decimal
.
Decimal
(
"3.14"
))
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'NaN'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'Inf'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'-Inf'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'a'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'łąść'
)
self
.
assertEqual
(
f
.
clean
(
'1.0 '
),
decimal
.
Decimal
(
"1.0"
))
self
.
assertEqual
(
f
.
clean
(
' 1.0'
),
decimal
.
Decimal
(
"1.0"
))
self
.
assertEqual
(
f
.
clean
(
' 1.0 '
),
decimal
.
Decimal
(
"1.0"
))
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'1.0a'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Ensure that there are no more than 4 digits in total.'"
):
f
.
clean
(
'123.45'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Ensure that there are no more than 2 decimal places.'"
):
...
...
@@ -54,13 +42,23 @@ class DecimalFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
f
.
clean
(
'-000.123'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Ensure that there are no more than 4 digits in total.'"
):
f
.
clean
(
'-000.12345'
)
with
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
'--0.12'
)
self
.
assertEqual
(
f
.
max_digits
,
4
)
self
.
assertEqual
(
f
.
decimal_places
,
2
)
self
.
assertIsNone
(
f
.
max_value
)
self
.
assertIsNone
(
f
.
min_value
)
def
test_enter_a_number_error
(
self
):
f
=
DecimalField
(
max_digits
=
4
,
decimal_places
=
2
)
values
=
(
'-NaN'
,
'NaN'
,
'+NaN'
,
'-Inf'
,
'Inf'
,
'+Inf'
,
'-Infinity'
,
'Infinity'
,
'+Infinity'
,
'a'
,
'łąść'
,
'1.0a'
,
'--0.12'
,
)
for
value
in
values
:
with
self
.
subTest
(
value
=
value
),
self
.
assertRaisesMessage
(
ValidationError
,
"'Enter a number.'"
):
f
.
clean
(
value
)
def
test_decimalfield_2
(
self
):
f
=
DecimalField
(
max_digits
=
4
,
decimal_places
=
2
,
required
=
False
)
self
.
assertIsNone
(
f
.
clean
(
''
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment