1+ import ast
12import inspect
23import re
3- from typing import Generator , Tuple
4+ from typing import Generator
5+ from typing import Tuple
46
57import validators
68
@@ -13,50 +15,35 @@ def docstrings() -> Generator[str, None, None]:
1315 yield from (
1416 inspect .getdoc (getattr (validators , validator )) or ""
1517 for validator in clicktypes .__all__
16- if validator not in ("base58" , "country_code" )
1718 )
1819
1920
2021def testdata (doc : str ) -> Generator [Tuple [str , str , int ], None , None ]:
2122
23+ if "ind_pan" in doc :
24+ pass
25+
26+ def parse_call (s : str ):
27+ tree = ast .parse (s .strip (), mode = "eval" )
28+ if not isinstance (tree .body , ast .Call ):
29+ raise ValueError ("Not a function call" )
30+ func_name = (
31+ ast .unparse (tree .body .func )
32+ if hasattr (ast , "unparse" )
33+ else tree .body .func .id # type: ignore[attr-defined]
34+ )
35+ args = [ast .literal_eval (arg ) for arg in tree .body .args ]
36+ kwargs = {kw .arg : ast .literal_eval (kw .value ) for kw in tree .body .keywords }
37+ return func_name , tuple (args ), kwargs
38+
2239 for match in re .findall (
23- r">>> (\w+)\(\'( .*?)\'\) $\s+# \w+: (.*?)$" ,
40+ r">>>\s* (\w+\( .*?\)) $\s+(.*?)$" ,
2441 doc ,
2542 re .MULTILINE ,
2643 ):
27- yield (match [0 ], match [ 1 ], 0 if match [2 ] == "True" else 2 )
44+ yield (* parse_call ( match [0 ]), 0 if match [1 ] == "True" else 2 )
2845
2946
3047def validator_data ():
3148 for doc in docstrings ():
32- for validator , value , expected in testdata (doc ):
33- yield (validator , value , {}, expected )
34-
35- for data , result in [
36- ("cUSECaVvAiV3srWbFRvVPzm5YzcXJwPSwZfE7veYPHoXmR9h6YMQ" , 0 ),
37- ("18KToMF5ckjXBYt2HAj77qsG3GPeej3PZn" , 0 ),
38- ("n4FFXRNNEW1aA2WPscSuzHTCjzjs4TVE2Z" , 0 ),
39- ("38XzQ9dPGb1uqbZsjPtUajp7omy8aefjqj" , 0 ),
40- ("ThisIsAReallyLongStringThatIsDefinitelyNotBase58Encoded" , 2 ),
41- ("abcABC!@#" , 2 ),
42- ("InvalidBase58!" , 2 ),
43- ]:
44- yield ("base58" , data , {}, result )
45-
46- for data , kwarg , expected in [
47- ("ISR" , "auto" , 0 ),
48- ("US" , "alpha2" , 0 ),
49- ("USA" , "alpha3" , 0 ),
50- ("840" , "numeric" , 0 ),
51- ("" , "auto" , 2 ),
52- ("123456" , "auto" , 2 ),
53- ("XY" , "alpha2" , 2 ),
54- ("PPP" , "alpha3" , 2 ),
55- ("123" , "numeric" , 2 ),
56- ("us" , "auto" , 2 ),
57- ("uSa" , "auto" , 2 ),
58- ("US " , "auto" , 2 ),
59- ("U.S" , "auto" , 2 ),
60- ("1ND" , "unknown" , 2 ),
61- ]:
62- yield ("country_code" , data , {"iso_format" : kwarg }, expected )
49+ yield from testdata (doc )
0 commit comments