1
1
# =============================================================================
2
2
# Minet Scrape Unit Tests
3
3
# =============================================================================
4
+ from typing import Optional
5
+
4
6
import pytest
5
7
from bs4 import BeautifulSoup , Tag , SoupStrainer
6
8
from textwrap import dedent
31
33
ScraperValidationMixedConcernError ,
32
34
ScraperValidationUnknownKeyError ,
33
35
)
36
+ from minet .scrape .classes .function import infer_fieldnames_from_function_return_type
34
37
35
38
BASIC_HTML = """
36
39
<ul>
160
163
"""
161
164
162
165
163
- class TestDefinitionScraper ( object ) :
166
+ class TestDefinitionScraper :
164
167
def test_basics (self ):
165
168
result = scrape ({"iterator" : "li" }, BASIC_HTML )
166
169
@@ -1055,3 +1058,31 @@ def clean(t):
1055
1058
text = get_display_text (elements )
1056
1059
1057
1060
assert text == "L'internationale."
1061
+
1062
+
1063
+ class TestFunctionScraper :
1064
+ def test_infer_fieldnames_from_function_return_type (self ):
1065
+ def basic_string () -> str :
1066
+ return "ok"
1067
+
1068
+ def basic_int () -> int :
1069
+ return 4
1070
+
1071
+ def basic_float () -> float :
1072
+ return 4.0
1073
+
1074
+ def basic_bool () -> bool :
1075
+ return True
1076
+
1077
+ def basic_void () -> None :
1078
+ return
1079
+
1080
+ def basic_optional_scalar () -> Optional [str ]:
1081
+ return
1082
+
1083
+ assert infer_fieldnames_from_function_return_type (basic_string ) == ["value" ]
1084
+ assert infer_fieldnames_from_function_return_type (basic_int ) == ["value" ]
1085
+ assert infer_fieldnames_from_function_return_type (basic_float ) == ["value" ]
1086
+ assert infer_fieldnames_from_function_return_type (basic_bool ) == ["value" ]
1087
+ assert infer_fieldnames_from_function_return_type (basic_void ) == ["value" ]
1088
+ assert infer_fieldnames_from_function_return_type (basic_optional_scalar ) == ["value" ]
0 commit comments