Skip to content

Commit 3b48045

Browse files
Merge pull request #52 from Blockchain-Technology-Lab/small_fix
Fix issue #48
2 parents 528f16c + 8ae0b69 commit 3b48045

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tests/test_helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ def test_get_granularity(mocker):
170170
granularity = hlp.get_granularity()
171171
assert isinstance(granularity, str)
172172

173+
get_config_mock.return_value = {'granularity': ''}
174+
granularity = hlp.get_granularity()
175+
assert granularity is None
176+
173177
get_config_mock.return_value = {'granularity': 'blah'}
174178
with pytest.raises(ValueError):
175179
hlp.get_granularity()

tokenomics_decentralization/helper.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,20 @@ def get_metrics():
225225
def get_granularity():
226226
"""
227227
Retrieves the granularity to be used in the analysis
228-
:returns: string in ['day', 'week', 'month', 'year']
229-
:raises ValueError: if the granularity is not set in the config file or if it is not one of the allowed values
228+
:returns: string in ['day', 'week', 'month', 'year'] that represents the chosen granularity
229+
or None if the relevant field is empty in the config file
230+
:raises ValueError: if the granularity field is missing from the config file or if
231+
the chosen value is not one of the allowed ones
230232
"""
231233
try:
232234
granularity = get_config_data()['granularity']
233-
if granularity in ['day', 'week', 'month', 'year']:
234-
return granularity
235+
if granularity:
236+
if granularity in ['day', 'week', 'month', 'year']:
237+
return granularity
238+
else:
239+
raise ValueError('Malformed "granularity" in config; should be one of: "day", "week", "month", "year", or empty')
235240
else:
236-
raise ValueError('Malformed "granularity" in config; should be one of: "day", "week", "month", "year", or empty')
241+
return None
237242
except KeyError:
238243
raise ValueError('"granularity" not in config file')
239244

0 commit comments

Comments
 (0)