Skip to content

Commit f85b8f2

Browse files
committed
#16 Add default value conditions and test patterns
1 parent add62ff commit f85b8f2

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

numdoclint/helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ def get_arg_default_val_info_dict(py_module_str, func_name):
814814
default_val_info_dict = {}
815815
for arg_str in splitted_arg_list:
816816
arg_str = arg_str.replace(' ', '')
817+
arg_str = arg_str.replace("'", '')
818+
arg_str = arg_str.replace('"', '')
817819
arg_str = _remove_type_str_from_arg_str(arg_str=arg_str)
818820
default_val_exists = '=' in arg_str
819821
if not default_val_exists:
@@ -840,6 +842,7 @@ def _remove_type_str_from_arg_str(arg_str):
840842
after_arg_str : str
841843
String after type information has been removed.
842844
"""
845+
arg_str = arg_str.replace(' = ', '=')
843846
is_in = ':' in arg_str
844847
if not is_in:
845848
return arg_str

tests/test_helper.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class SampleClass:
8282
8383
def sample_func_6(self, cls, price, name, *args, **kwargs):
8484
pass
85+
86+
def sample_func_7(price: int = 100, name: str = 'apple'):
87+
pass
8588
"""
8689

8790
arg_name_list = helper.get_arg_name_list(
@@ -114,6 +117,10 @@ def sample_func_6(self, cls, price, name, *args, **kwargs):
114117
assert arg_name_list == [
115118
'self', 'cls', 'price', 'name', '*args', '**kwargs']
116119

120+
arg_name_list = helper.get_arg_name_list(
121+
py_module_str=py_module_str, func_name='sample_func_7')
122+
assert arg_name_list == ['price', 'name']
123+
117124

118125
def test_get_func_indent_num():
119126
py_module_str = """
@@ -726,12 +733,16 @@ def sample_func_6( prince = 100, location_id = 200 ):
726733
print(600)
727734
728735
729-
def sample_func
736+
def sample_func_7
730737
(
731738
price,
732739
name
733740
):
734741
pass
742+
743+
744+
def sample_func_8(dict_val: Optional[Dict[str, int]] = None):
745+
pass
735746
"""
736747
args_str = helper._get_args_str(
737748
code_str=code_str, func_name='sample_func_1')
@@ -758,7 +769,7 @@ def sample_func
758769
assert args_str == 'prince = 100, location_id = 200'
759770

760771
args_str = helper._get_args_str(
761-
code_str=code_str, func_name='sample_func')
772+
code_str=code_str, func_name='sample_func_7')
762773
assert args_str == 'price, name'
763774

764775

@@ -775,6 +786,15 @@ def sample_func_2(price, location_id=100, season=3):
775786
def sample_func_3(
776787
price: int, location_id: int=100) -> str:
777788
print(300)
789+
790+
791+
def sample_func_4(
792+
price: int = 100, name: str = 'apple') -> str:
793+
print(300)
794+
795+
796+
def sample_func_5(name: str = "apple") -> str:
797+
print(300)
778798
"""
779799
default_val_info_dict = helper.get_arg_default_val_info_dict(
780800
py_module_str=py_module_str, func_name='sample_func_1')
@@ -797,6 +817,21 @@ def sample_func_3(
797817
}
798818
assert default_val_info_dict == expected_dict
799819

820+
default_val_info_dict = helper.get_arg_default_val_info_dict(
821+
py_module_str=py_module_str, func_name='sample_func_4')
822+
expected_dict = {
823+
'price': '100',
824+
'name': 'apple',
825+
}
826+
assert default_val_info_dict == expected_dict
827+
828+
default_val_info_dict = helper.get_arg_default_val_info_dict(
829+
py_module_str=py_module_str, func_name='sample_func_5')
830+
expected_dict = {
831+
'name': 'apple',
832+
}
833+
assert default_val_info_dict == expected_dict
834+
800835

801836
def test__get_return_value_docstring():
802837
docstring = """
@@ -1684,6 +1719,10 @@ def test__remove_type_str_from_arg_str():
16841719
arg_str=' price: int=100 ')
16851720
assert after_arg_str == 'price=100'
16861721

1722+
after_arg_str = helper._remove_type_str_from_arg_str(
1723+
arg_str=' price: int = 100 ')
1724+
assert after_arg_str == 'price=100'
1725+
16871726

16881727
def test__remove_nested_func_str():
16891728
func_str = """

0 commit comments

Comments
 (0)