11import os
22import shutil
3+ from typing import List
34
45import pytest
56import six
67from voluptuous import Any , Schema
78
89from numdoclint import cli , jupyter_notebook , py_module
910
10- TMP_TEST_MODULE_DIR = 'tests/tmp_test/'
11- TMP_TEST_MODULE_PATH_1 = os .path .join (
11+ TMP_TEST_MODULE_DIR : str = 'tests/tmp_test/'
12+ TMP_TEST_MODULE_PATH_1 : str = os .path .join (
1213 TMP_TEST_MODULE_DIR ,
1314 'tmp_test_1.py' )
14- TMP_TEST_MODULE_PATH_2 = os .path .join (
15+ TMP_TEST_MODULE_PATH_2 : str = os .path .join (
1516 TMP_TEST_MODULE_DIR ,
1617 'tmp_test_2.py' )
1718
1819
19- def setup ():
20+ def setup () -> None :
2021 """Function to be executed at the start of the test.
2122 """
2223 shutil .rmtree (TMP_TEST_MODULE_DIR , ignore_errors = True )
2324 os .makedirs (TMP_TEST_MODULE_DIR )
24- init_file_path = os .path .join (TMP_TEST_MODULE_DIR , '__init__.py' )
25+ init_file_path : str = os .path .join (TMP_TEST_MODULE_DIR , '__init__.py' )
2526 with open (init_file_path , 'w' ) as f :
2627 f .write ('\n ' )
2728
2829
29- def teardown ():
30+ def teardown () -> None :
3031 """Function to be executed at the end of the test.
3132 """
3233 shutil .rmtree (TMP_TEST_MODULE_DIR , ignore_errors = True )
3334
3435
35- def test__get_list_of_str_from_csv ():
36- result_list = cli ._get_list_of_str_from_csv (csv = '' )
36+ def test__get_list_of_str_from_csv () -> None :
37+ result_list : List [ str ] = cli ._get_list_of_str_from_csv (csv = '' )
3738 assert result_list == []
3839 result_list = cli ._get_list_of_str_from_csv (csv = 'apple,orange' )
3940 assert result_list == ['apple' , 'orange' ]
4041
4142
42- def test__get_list_of_int_from_csv ():
43- result_list = cli ._get_list_of_int_from_csv (csv = '' )
43+ def test__get_list_of_int_from_csv () -> None :
44+ result_list : List [ int ] = cli ._get_list_of_int_from_csv (csv = '' )
4445 assert result_list == []
4546 result_list = cli ._get_list_of_int_from_csv (csv = '1,2,3' )
4647 assert result_list == [1 , 2 , 3 ]
4748
4849
49- def _assert_default_value_check_info_id_is_in (info_list ) :
50+ def _assert_default_value_check_info_id_is_in (info_list : List [ dict ]) -> None :
5051 """
5152 Check that the check result of the default value
5253 is included in the list.
@@ -61,7 +62,7 @@ def _assert_default_value_check_info_id_is_in(info_list):
6162 AssertionError
6263 If not included in the list.
6364 """
64- default_val_info_exists = False
65+ default_val_info_exists : bool = False
6566 for info_dict in info_list :
6667 if (info_dict [py_module .INFO_KEY_INFO_ID ]
6768 == py_module .INFO_ID_LACKED_DOC_DEFAULT_VALUE ):
@@ -70,7 +71,8 @@ def _assert_default_value_check_info_id_is_in(info_list):
7071 assert default_val_info_exists
7172
7273
73- def _assert_default_value_check_info_id_is_not_in (info_list ):
74+ def _assert_default_value_check_info_id_is_not_in (
75+ info_list : List [dict ]) -> None :
7476 """
7577 Check that the check result of the default value is not
7678 included in the list.
@@ -85,24 +87,24 @@ def _assert_default_value_check_info_id_is_not_in(info_list):
8587 AssertionError
8688 If included in the list.
8789 """
88- info_id_list = [
90+ info_id_list : List [ int ] = [
8991 info_dict [py_module .INFO_KEY_INFO_ID ] for info_dict in info_list ]
9092 for info_id in info_id_list :
9193 assert info_id != py_module .INFO_ID_LACKED_DOC_DEFAULT_VALUE
9294
9395
94- def test__validate_args ():
95- with pytest .raises (Exception ):
96+ def test__validate_args () -> None :
97+ with pytest .raises (Exception ): # type: ignore
9698 cli ._validate_args (
97- path = None ,
99+ path = None , # type: ignore
98100 ignore_info_id_list = [],
99101 check_recursively = False )
100- with pytest .raises (Exception ):
102+ with pytest .raises (Exception ): # type: ignore
101103 cli ._validate_args (
102104 path = 'sample/path.py' ,
103105 ignore_info_id_list = [- 1 ],
104106 check_recursively = False )
105- with pytest .raises (Exception ):
107+ with pytest .raises (Exception ): # type: ignore
106108 cli ._validate_args (
107109 path = 'sample/path.py' ,
108110 ignore_info_id_list = [],
@@ -113,14 +115,14 @@ def test__validate_args():
113115 check_recursively = False )
114116
115117
116- def test__exec_numdoclint ():
117- module_str_1 = """
118+ def test__exec_numdoclint () -> None :
119+ module_str_1 : str = """
118120def sample_func_1(price):
119121 pass
120122 """
121123 with open (TMP_TEST_MODULE_PATH_1 , 'w' ) as f :
122124 f .write (module_str_1 )
123- module_str_2 = '''
125+ module_str_2 : str = '''
124126@Appender
125127def sample_func_2(price=100):
126128 """
@@ -136,15 +138,15 @@ def sample_func_2(price=100):
136138 with open (TMP_TEST_MODULE_PATH_2 , 'w' ) as f :
137139 f .write (module_str_2 )
138140
139- info_list = cli ._exec_numdoclint (
141+ info_list : List [ dict ] = cli ._exec_numdoclint (
140142 path = TMP_TEST_MODULE_PATH_1 ,
141143 check_recursively = False ,
142144 is_jupyter = False ,
143145 ignore_func_name_prefix_list = [],
144146 ignore_info_id_list = [],
145147 enable_default_or_optional_doc_check = True ,
146148 skip_decorator_name_list = [])
147- schema = Schema (
149+ schema : Schema = Schema (
148150 schema = {
149151 py_module .INFO_KEY_MODULE_PATH : TMP_TEST_MODULE_PATH_1 ,
150152 py_module .INFO_KEY_FUNC_NAME : 'sample_func_1' ,
@@ -154,7 +156,7 @@ def sample_func_2(price=100):
154156 required = True )
155157 for info_dict in info_list :
156158 schema (info_dict )
157- info_id_list = [
159+ info_id_list : List [ int ] = [
158160 info_dict [py_module .INFO_KEY_INFO_ID ] for info_dict in info_list ]
159161 info_list = cli ._exec_numdoclint (
160162 path = TMP_TEST_MODULE_PATH_1 ,
@@ -221,10 +223,10 @@ def sample_func_2(price=100):
221223 assert info_list
222224 for info_dict in info_list :
223225 schema (info_dict )
224- module_path_list = [
226+ module_path_list : List [ str ] = [
225227 info_dict [py_module .INFO_KEY_MODULE_PATH ] for info_dict in info_list ]
226- module_path_1_exists = False
227- module_path_2_exists = False
228+ module_path_1_exists : bool = False
229+ module_path_2_exists : bool = False
228230 for module_path in module_path_list :
229231 if TMP_TEST_MODULE_PATH_1 in module_path :
230232 module_path_1_exists = True
@@ -388,8 +390,8 @@ def sample_func_2(price=100):
388390 _assert_default_value_check_info_id_is_not_in (info_list = info_list )
389391
390392
391- def test_main ():
392- module_str_1 = """
393+ def test_main () -> None :
394+ module_str_1 : str = """
393395def sample_func_1(price):
394396 pass
395397 """
@@ -398,18 +400,20 @@ def sample_func_1(price):
398400
399401 class Args :
400402
401- path = TMP_TEST_MODULE_PATH_1
402- check_recursively = False
403- is_jupyter = False
404- ignore_func_name_prefix_list = []
405- ignore_info_id_list = []
406- enable_default_or_optional_doc_check = True
407- skip_decorator_name_list = []
408-
409- args = Args ()
410- info_list = cli .main (args = args , return_list = True )
403+ path : str = TMP_TEST_MODULE_PATH_1
404+ check_recursively : bool = False
405+ is_jupyter : bool = False
406+ ignore_func_name_prefix_list : List [str ] = []
407+ ignore_info_id_list : List [int ] = []
408+ enable_default_or_optional_doc_check : bool = True
409+ skip_decorator_name_list : List [str ] = []
410+
411+ args : Args = Args ()
412+ info_list : List [dict ]= cli .main (
413+ args = args , # type: ignore
414+ return_list = True )
411415 assert info_list
412- schema = Schema (
416+ schema : Schema = Schema (
413417 schema = {
414418 py_module .INFO_KEY_MODULE_PATH : TMP_TEST_MODULE_PATH_1 ,
415419 py_module .INFO_KEY_FUNC_NAME : 'sample_func_1' ,
0 commit comments