3535
3636
3737def int_or_zero (number_str : str ) -> int :
38+ """
39+ >>> int_or_zero("1")
40+ 1
41+ >>> int_or_zero("One")
42+ 0
43+
44+ This is not a general-purpose function:
45+ If use changes, handle more cases.
46+
47+ >>> int_or_zero("1.0")
48+ 0
49+ """
3850 try :
3951 number = int (number_str )
4052 except (TypeError , ValueError , OverflowError ):
@@ -49,6 +61,16 @@ def get_str_int_error(
4961 min_message : str ,
5062 max_message : str ,
5163) -> str | None :
64+ """
65+ >>> get_str_int_error("", 1, 10, "low", "high")
66+ 'is required'
67+ >>> get_str_int_error("ABC", 1, 10, "low", "high")
68+ 'should be an integer'
69+ >>> get_str_int_error("0", 1, 10, "low", "high")
70+ 'should not be less than 1: low'
71+ >>> get_str_int_error("11", 1, 10, "low", "high")
72+ 'should not be greater than 10: high'
73+ """
5274 if number_str == "" :
5375 return "is required"
5476 try :
@@ -63,6 +85,11 @@ def get_str_int_error(
6385
6486
6587def get_max_rows_error (number_str ) -> str | None :
88+ """
89+ >>> get_max_rows_error(100)
90+ >>> get_max_rows_error(99)
91+ 'Maximum row count should not be less than 100: For very small data sets, ...'
92+ """
6693 message = get_str_int_error (
6794 number_str = number_str ,
6895 minimum = MIN_ROW_COUNT ,
0 commit comments