|
@@ 473-496 (lines=24) @@
|
| 470 |
|
if value.is_integer(): |
| 471 |
|
# the typecast to int may return int or long, depending on the size of value |
| 472 |
|
value = int(value) |
| 473 |
|
if self._is_type_int_long(value): |
| 474 |
|
if 'minimum' in config_header['type']: |
| 475 |
|
if value < config_header['type']['minimum']: |
| 476 |
|
msg = u'The value {0} in cell {1} is smaller than the given minimum ' \ |
| 477 |
|
u'of {2}'.format(value, cell_index_str, config_header['type']['minimum']) |
| 478 |
|
if config_header['fail_on_type_error']: |
| 479 |
|
msg_queue['fail_on_type_error']['exceptions'].append(msg) |
| 480 |
|
else: |
| 481 |
|
msg_queue['fail_on_type_error']['logs'].append(msg) |
| 482 |
|
if 'maximum' in config_header['type']: |
| 483 |
|
if value > config_header['type']['maximum']: |
| 484 |
|
msg = u'The value {0} in cell {1} is greater than the given maximum ' \ |
| 485 |
|
u'of {2}'.format(value, cell_index_str, config_header['type']['maximum']) |
| 486 |
|
if config_header['fail_on_type_error']: |
| 487 |
|
msg_queue['fail_on_type_error']['exceptions'].append(msg) |
| 488 |
|
else: |
| 489 |
|
msg_queue['fail_on_type_error']['logs'].append(msg) |
| 490 |
|
else: |
| 491 |
|
msg = u'The value {0} in cell {1} is of type {2}; required by ' \ |
| 492 |
|
u'specification is int'.format(value, cell_index_str, type(value)) |
| 493 |
|
if config_header['fail_on_type_error']: |
| 494 |
|
msg_queue['fail_on_type_error']['exceptions'].append(msg) |
| 495 |
|
else: |
| 496 |
|
msg_queue['fail_on_type_error']['logs'].append(msg) |
| 497 |
|
|
| 498 |
|
elif config_header['type']['base'] == 'string': |
| 499 |
|
if self._is_type_numeric(value): |
|
@@ 442-465 (lines=24) @@
|
| 439 |
|
|
| 440 |
|
elif config_header['type']['base'] == 'float': |
| 441 |
|
# TODO Allow int, too |
| 442 |
|
if not isinstance(value, float): |
| 443 |
|
msg = u'The value {0} in cell {1} is of type {2}; required by ' \ |
| 444 |
|
u'specification is float'.format(value, cell_index_str, type(value)) |
| 445 |
|
if config_header['fail_on_type_error']: |
| 446 |
|
msg_queue['fail_on_type_error']['exceptions'].append(msg) |
| 447 |
|
else: |
| 448 |
|
msg_queue['fail_on_type_error']['logs'].append(msg) |
| 449 |
|
else: |
| 450 |
|
if 'minimum' in config_header['type']: |
| 451 |
|
if value < config_header['type']['minimum']: |
| 452 |
|
msg = u'The value {0} in cell {1} is smaller than the given minimum ' \ |
| 453 |
|
u'of {2}'.format(value, cell_index_str, config_header['type']['minimum']) |
| 454 |
|
if config_header['fail_on_type_error']: |
| 455 |
|
msg_queue['fail_on_type_error']['exceptions'].append(msg) |
| 456 |
|
else: |
| 457 |
|
msg_queue['fail_on_type_error']['logs'].append(msg) |
| 458 |
|
if 'maximum' in config_header['type']: |
| 459 |
|
if value > config_header['type']['maximum']: |
| 460 |
|
msg = u'The value {0} in cell {1} is greater than the given maximum ' \ |
| 461 |
|
u'of {2}'.format(value, cell_index_str, config_header['type']['maximum']) |
| 462 |
|
if config_header['fail_on_type_error']: |
| 463 |
|
msg_queue['fail_on_type_error']['exceptions'].append(msg) |
| 464 |
|
else: |
| 465 |
|
msg_queue['fail_on_type_error']['logs'].append(msg) |
| 466 |
|
elif config_header['type']['base'] == 'integer': |
| 467 |
|
# Integer values stored by Excel are returned as float (e.g. 3465.0) |
| 468 |
|
# So we have to check if the float can be converted to int without precision loss |