Ticket #7920: decimal2.diff
File decimal2.diff, 3.5 KB (added by , 16 years ago) |
---|
-
tests/regressiontests/model_fields/tests.py
1 1 """ 2 2 >>> from django.db.models.fields import * 3 >>> try: 4 ... from decimal import Decimal 5 ... except ImportError: 6 ... from django.utils._decimal import Decimal 3 7 4 8 # DecimalField 5 9 6 10 >>> f = DecimalField(max_digits=4, decimal_places=2) 7 11 8 >>> f.to_python(3) 9 Decimal("3") 12 >>> f.to_python(3) == Decimal("3") 13 True 10 14 11 >>> f.to_python("3.14") 12 Decimal("3.14") 15 >>> f.to_python("3.14") == Decimal("3.14") 16 True 13 17 14 18 >>> f.to_python("abc") 15 19 Traceback (most recent call last): -
tests/regressiontests/forms/fields.py
308 308 Traceback (most recent call last): 309 309 ... 310 310 ValidationError: [u'This field is required.'] 311 >>> f.clean('1') 312 Decimal("1") 311 >>> f.clean('1') == Decimal("1") 312 True 313 313 >>> isinstance(f.clean('1'), Decimal) 314 314 True 315 >>> f.clean('23') 316 Decimal("23") 317 >>> f.clean('3.14') 318 Decimal("3.14") 319 >>> f.clean(3.14) 320 Decimal("3.14") 321 >>> f.clean(Decimal('3.14')) 322 Decimal("3.14") 315 >>> f.clean('23') == Decimal("23") 316 True 317 >>> f.clean('3.14') == Decimal("3.14") 318 True 319 >>> f.clean(3.14) == Decimal("3.14") 320 True 321 >>> f.clean(Decimal('3.14')) == Decimal("3.14") 322 True 323 323 >>> f.clean('a') 324 324 Traceback (most recent call last): 325 325 ... … … 328 328 Traceback (most recent call last): 329 329 ... 330 330 ValidationError: [u'Enter a number.'] 331 >>> f.clean('1.0 ') 332 Decimal("1.0") 333 >>> f.clean(' 1.0') 334 Decimal("1.0") 335 >>> f.clean(' 1.0 ') 336 Decimal("1.0") 331 >>> f.clean('1.0 ') == Decimal("1.0") 332 True 333 >>> f.clean(' 1.0') == Decimal("1.0") 334 True 335 >>> f.clean(' 1.0 ') == Decimal("1.0") 336 True 337 337 >>> f.clean('1.0a') 338 338 Traceback (most recent call last): 339 339 ... … … 350 350 Traceback (most recent call last): 351 351 ... 352 352 ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.'] 353 >>> f.clean('-12.34') 354 Decimal("-12.34") 353 >>> f.clean('-12.34') == Decimal("-12.34") 354 True 355 355 >>> f.clean('-123.45') 356 356 Traceback (most recent call last): 357 357 ... 358 358 ValidationError: [u'Ensure that there are no more than 4 digits in total.'] 359 >>> f.clean('-.12') 360 Decimal("-0.12") 361 >>> f.clean('-00.12') 362 Decimal("-0.12") 363 >>> f.clean('-000.12') 364 Decimal("-0.12") 359 >>> f.clean('-.12') == Decimal("-0.12") 360 True 361 >>> f.clean('-00.12') == Decimal("-0.12") 362 True 363 >>> f.clean('-000.12') == Decimal("-0.12") 364 True 365 365 >>> f.clean('-000.123') 366 366 Traceback (most recent call last): 367 367 ... … … 380 380 381 381 >>> f.clean(None) 382 382 383 >>> f.clean('1') 384 Decimal("1") 383 >>> f.clean('1') == Decimal("1") 384 True 385 385 386 386 DecimalField accepts min_value and max_value just like IntegerField: 387 387 >>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) … … 394 394 Traceback (most recent call last): 395 395 ... 396 396 ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] 397 >>> f.clean('1.5') 398 Decimal("1.5") 399 >>> f.clean('0.5') 400 Decimal("0.5") 401 >>> f.clean('.5') 402 Decimal("0.5") 403 >>> f.clean('00.50') 404 Decimal("0.50") 397 >>> f.clean('1.5') == Decimal("1.5") 398 True 399 >>> f.clean('0.5') == Decimal("0.5") 400 True 401 >>> f.clean('.5') == Decimal("0.5") 402 True 403 >>> f.clean('00.50') == Decimal("0.50") 404 True 405 405 406 406 # DateField ################################################################### 407 407