Skip to content

Commit

Permalink
Strip brackets and extra spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Feb 13, 2023
1 parent d83c312 commit 2c3fb22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def validate_bls_withdrawal_credentials(bls_withdrawal_credentials: str) -> byte


def normalize_input_list(input: str) -> Sequence[str]:
input = input.strip('[({})]')
input = re.sub(' +', ' ', input)
return re.split(r'; |, | |,|;', input)


Expand Down
17 changes: 17 additions & 0 deletions tests/test_utils/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from staking_deposit.exceptions import ValidationError
from staking_deposit.utils.validation import (
normalize_input_list,
validate_int_range,
validate_password_strength,
)
Expand Down Expand Up @@ -43,3 +44,19 @@ def test_validate_int_range(num: Any, low: int, high: int, valid: bool) -> None:
else:
with pytest.raises(ValidationError):
validate_int_range(num, low, high)


@pytest.mark.parametrize(
'input, result',
[
('1', ['1']),
('1,2,3', ['1', '2', '3']),
('[1,2,3]', ['1', '2', '3']),
('(1,2,3)', ['1', '2', '3']),
('{1,2,3}', ['1', '2', '3']),
('1 2 3', ['1', '2', '3']),
('1 2 3', ['1', '2', '3']),
]
)
def test_normalize_input_list(input, result):
assert normalize_input_list(input) == result

0 comments on commit 2c3fb22

Please sign in to comment.