diff --git a/badges/test_coverage.svg b/badges/test_coverage.svg index cb3cdc0ec7e70c0e53212e791bb14cfe4c07fe2d..f86374a02f56bab1acc14634e84b66d82d4cf3bf 100644 --- a/badges/test_coverage.svg +++ b/badges/test_coverage.svg @@ -15,7 +15,7 @@ <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> <text x="31.5" y="15" fill="#010101" fill-opacity=".3">coverage</text> <text x="31.5" y="14">coverage</text> - <text x="80" y="15" fill="#010101" fill-opacity=".3">41%</text> - <text x="80" y="14">41%</text> + <text x="80" y="15" fill="#010101" fill-opacity=".3">43%</text> + <text x="80" y="14">43%</text> </g> </svg> diff --git a/binarycpython/utils/dicts.py b/binarycpython/utils/dicts.py index 244d99278f6c93c9d0ddda4ffb228a77c4d029a4..7009d21df4be39e0353f40d67b5a81078e8cef30 100644 --- a/binarycpython/utils/dicts.py +++ b/binarycpython/utils/dicts.py @@ -482,14 +482,9 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict: ): try: new_dict[key] = int(dict_1[key]) + int(dict_2[key]) - except: - print( - "key", - key, - ': Failed to convert string, one of "{}" or "{}" to an int'.format( - dict_1[key], dict_2[key] - ), - ) + except ValueError as e: + msg = "{}: Failed to convert string (either '{}' or '{}') to an int".format(key, dict_1[key], dict_2[key]) + raise ValueError(msg) from e # string-float clash : convert both to floats and save elif ( @@ -500,28 +495,22 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict: ): try: new_dict[key] = float(dict_1[key]) + float(dict_2[key]) - except: - print( - "key", - key, - ': Failed to convert string, one of "{}" or "{}" to a float'.format( - dict_1[key], dict_2[key] - ), - ) + except ValueError as e: + msg = "{}: Failed to convert string (either '{}' or '{}') to an float".format(key, dict_1[key], dict_2[key]) + raise ValueError(msg) from e # If the above cases have not dealt with it, then we should raise an error else: - print( - "merge_dicts error: key: {key} value: {value1} type: {type1} and key: {key} value: {value2} type: {type2} are not of the same type and cannot be merged".format( - key=key, - value1=dict_1[key], - type1=type(dict_1[key]), - value2=dict_2[key], - type2=type(dict_2[key]), - ) + msg = "merge_dicts error: key: {key} value: {value1} type: {type1} and key: {key} value: {value2} type: {type2} are not of the same type and cannot be merged".format( + key=key, + value1=dict_1[key], + type1=type(dict_1[key]), + value2=dict_2[key], + type2=type(dict_2[key]), ) - raise ValueError + raise ValueError(msg) + # Here the keys are the same type # Here we check for the cases that we want to explicitly catch. Ints will be added, # floats will be added, lists will be appended (though that might change) and dicts will be # dealt with by calling this function again. @@ -566,16 +555,14 @@ def merge_dicts(dict_1: dict, dict_2: dict) -> dict: new_dict[key] = None else: - print( - "Object types {}: {} ({}), {} ({}) not supported.".format( - key, - dict_1[key], - type(dict_1[key]), - dict_2[key], - type(dict_2[key]), - ) + msg = "Object types {}: {} ({}), {} ({}) not supported.".format( + key, + dict_1[key], + type(dict_1[key]), + dict_2[key], + type(dict_2[key]), ) - raise ValueError + raise ValueError(msg) # return new_dict diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 3f90ab6e3f370c47100aad5b51775dcc525086c5..4aa28736af8593693cb46a170cecbc7694d7a18e 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -3,6 +3,8 @@ Module containing the Population grid class object. Here all the functionality of a Population object is defined. +TODO: the save_snapshots and save_snapshot, are they actually distinct? + Tasks: - TODO: add functionality to 'on-init' set arguments - TODO: add functionality to return the initial_abundance_hash