str support + tests

This commit is contained in:
Jesse Bannon 2023-11-05 08:00:21 -08:00
parent a874a6134e
commit e5c0cd0bf1
2 changed files with 31 additions and 9 deletions

View file

@ -1,6 +1,7 @@
import hashlib
import re
import shlex
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
@ -116,7 +117,7 @@ class DownloadArgsParser:
return largest_consecutive + 1
@classmethod
def _argument_name_and_value_to_dict(cls, arg_name: str, arg_value: str) -> Dict:
def _argument_name_and_value_to_dict(cls, arg_name: str, arg_value: Any) -> Dict:
"""
:param arg_name: Argument name in the form of 'key1.key2.key3'
:param arg_value: Argument value
@ -134,14 +135,15 @@ class DownloadArgsParser:
next_dict[arg_name_split[-1]] = arg_value
if arg_value == "True":
next_dict[arg_name_split[-1]] = True
elif arg_value == "False":
next_dict[arg_name_split[-1]] = False
elif arg_value.isdigit():
next_dict[arg_name_split[-1]] = int(arg_value)
elif arg_value.replace(".", "", 1).isdigit():
next_dict[arg_name_split[-1]] = float(arg_value)
if isinstance(arg_value, str):
if arg_value == "True":
next_dict[arg_name_split[-1]] = True
elif arg_value == "False":
next_dict[arg_name_split[-1]] = False
elif arg_value.isdigit():
next_dict[arg_name_split[-1]] = int(arg_value)
elif arg_value.replace(".", "", 1).isdigit():
next_dict[arg_name_split[-1]] = float(arg_value)
return argument_dict

View file

@ -97,6 +97,26 @@ class TestDownloadArgsParser:
"dl --parameter.not.using.list[0] 'v0'",
{"parameter": {"not": {"using": {"list[0]": "v0"}}}},
),
(
None,
"dl --a.float.parameter 1.3",
{"a": {"float": {"parameter": 1.3}}},
),
(
None,
"dl --a.int.parameter 6",
{"a": {"int": {"parameter": 6}}},
),
(
None,
"dl --a.true.parameter True",
{"a": {"true": {"parameter": True}}},
),
(
None,
"dl --a.false.parameter False",
{"a": {"false": {"parameter": False}}},
),
],
)
def test_successful_args(self, config_options_generator, aliases, cmd, expected_sub_dict):