Skip to content

Commit d87f8b6

Browse files
committed
Raise ValueError instead of argparse error if invalid date format
1 parent 0a4821d commit d87f8b6

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

tests/test_helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import tokenomics_decentralization.helper as hlp
22
import pathlib
33
import os
4-
import argparse
54
import datetime
65
import pytest
76

@@ -12,9 +11,9 @@ def test_valid_date():
1211

1312
for d in ['2022/1/01', '2022/01/1', '2022/1', '2022/01', '2022.1.01', '2022.01.1', '2022.1', '2022.01', 'blah',
1413
'2022-', '2022-1-1', '2022-1-01', '2022-1', '2022-01-1', '2022-02-29']:
15-
with pytest.raises(argparse.ArgumentTypeError) as e_info:
14+
with pytest.raises(ValueError) as e_info:
1615
hlp.valid_date(d)
17-
assert e_info.type == argparse.ArgumentTypeError
16+
assert e_info.type == ValueError
1817

1918

2019
def test_get_date_beginning():

tokenomics_decentralization/helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import datetime
88
import calendar
9-
import argparse
109
import json
1110
from collections import defaultdict
1211
import logging
@@ -33,8 +32,8 @@ def valid_date(date_string):
3332
try:
3433
get_date_beginning(date_string)
3534
except ValueError:
36-
raise argparse.ArgumentTypeError("Please use the format YYYY-MM-DD for the timeframe argument "
37-
"(day and month can be omitted).")
35+
raise ValueError("Please use the format YYYY-MM-DD for the timeframe argument "
36+
"(day and month can be omitted).")
3837
return date_string
3938

4039

0 commit comments

Comments
 (0)