66
77from mindee import InferenceResponse
88from mindee .parsing .v2 import InferenceActiveOptions
9- from mindee .parsing .v2 .field import FieldConfidence , ListField , ObjectField , SimpleField
9+ from mindee .parsing .v2 .field .field_confidence import FieldConfidence
10+ from mindee .parsing .v2 .field .list_field import ListField
11+ from mindee .parsing .v2 .field .object_field import ObjectField
12+ from mindee .parsing .v2 .field .simple_field import SimpleField
1013from mindee .parsing .v2 .field .inference_fields import InferenceFields
1114from mindee .parsing .v2 .inference import Inference
1215from mindee .parsing .v2 .inference_file import InferenceFile
@@ -27,14 +30,14 @@ def _get_samples(json_path: Path, rst_path: Path) -> Tuple[dict, str]:
2730
2831
2932def _get_inference_samples (name : str ) -> Tuple [dict , str ]:
30- json_path = V2_DATA_DIR / "inference " / f"{ name } .json"
31- rst_path = V2_DATA_DIR / "inference " / f"{ name } .rst"
33+ json_path = V2_DATA_DIR / "products" / "extraction " / f"{ name } .json"
34+ rst_path = V2_DATA_DIR / "products" / "extraction " / f"{ name } .rst"
3235 return _get_samples (json_path , rst_path )
3336
3437
3538def _get_product_samples (product , name : str ) -> Tuple [dict , str ]:
36- json_path = V2_DATA_DIR / "products" / product / f"{ name } .json"
37- rst_path = V2_DATA_DIR / "products" / product / f"{ name } .rst"
39+ json_path = V2_DATA_DIR / "products" / "extraction" / product / f"{ name } .json"
40+ rst_path = V2_DATA_DIR / "products" / "extraction" / product / f"{ name } .rst"
3841 return _get_samples (json_path , rst_path )
3942
4043
@@ -53,42 +56,54 @@ def test_deep_nested_fields():
5356 response .inference .result .fields ["field_object" ].fields ["sub_object_object" ],
5457 ObjectField ,
5558 )
59+ fields = response .inference .result .fields
60+ assert isinstance (fields .get ("field_object" ), ObjectField )
5661 assert isinstance (
57- response .inference .result .fields ["field_object" ]
58- .fields ["sub_object_object" ]
59- .fields ,
62+ fields .get ("field_object" ).get_simple_field ("sub_object_simple" ), SimpleField
63+ )
64+ assert isinstance (
65+ fields .get ("field_object" ).get_list_field ("sub_object_list" ), ListField
66+ )
67+ assert isinstance (
68+ fields .get ("field_object" ).get_object_field ("sub_object_object" ), ObjectField
69+ )
70+ assert len (fields .get ("field_object" ).simple_fields ) == 1
71+ assert len (fields .get ("field_object" ).list_fields ) == 1
72+ assert len (fields .get ("field_object" ).object_fields ) == 1
73+ assert isinstance (
74+ fields ["field_object" ].fields ["sub_object_object" ].fields ,
6075 dict ,
6176 )
6277 assert isinstance (
63- response . inference . result . fields ["field_object" ]
78+ fields ["field_object" ]
6479 .fields ["sub_object_object" ]
6580 .fields ["sub_object_object_sub_object_list" ],
6681 ListField ,
6782 )
6883 assert isinstance (
69- response . inference . result . fields ["field_object" ]
84+ fields ["field_object" ]
7085 .fields ["sub_object_object" ]
7186 .fields ["sub_object_object_sub_object_list" ]
7287 .items ,
7388 list ,
7489 )
7590 assert isinstance (
76- response . inference . result . fields ["field_object" ]
91+ fields ["field_object" ]
7792 .fields ["sub_object_object" ]
7893 .fields ["sub_object_object_sub_object_list" ]
7994 .items [0 ],
8095 ObjectField ,
8196 )
8297 assert isinstance (
83- response . inference . result . fields ["field_object" ]
98+ fields ["field_object" ]
8499 .fields ["sub_object_object" ]
85100 .fields ["sub_object_object_sub_object_list" ]
86101 .items [0 ]
87102 .fields ["sub_object_object_sub_object_list_simple" ],
88103 SimpleField ,
89104 )
90105 assert (
91- response . inference . result . fields ["field_object" ]
106+ fields ["field_object" ]
92107 .fields ["sub_object_object" ]
93108 .fields ["sub_object_object_sub_object_list" ]
94109 .items [0 ]
@@ -299,7 +314,9 @@ def test_text_context_field_is_false() -> None:
299314
300315@pytest .mark .v2
301316def test_text_context_field_is_true () -> None :
302- with open (V2_DATA_DIR / "inference" / "text_context_enabled.json" , "r" ) as file :
317+ with open (
318+ V2_DATA_DIR / "products" / "extraction" / "text_context_enabled.json" , "r"
319+ ) as file :
303320 json_sample = json .load (file )
304321 response = InferenceResponse (json_sample )
305322 assert isinstance (response .inference .active_options , InferenceActiveOptions )
0 commit comments