@@ -170,36 +170,95 @@ def test_create_brand_taxonomy_mapping(self):
170170
171171
172172class TestTaxonomy :
173+ @pytest .mark .parametrize (
174+ "taxonomy,item,candidates,output" ,
175+ [
176+ (label_taxonomy , "en:fr-bio-01" , {"en:organic" }, True ),
177+ (label_taxonomy , "en:organic" , {"en:fr-bio-01" }, False ),
178+ (label_taxonomy , "en:fr-bio-01" , [], False ),
179+ (label_taxonomy , "en:no-gluten" , {"en:organic" }, False ),
180+ (
181+ label_taxonomy ,
182+ "en:no-gluten" ,
183+ {"en:organic" , "en:no-additives" , "en:vegan" },
184+ False ,
185+ ),
186+ (
187+ label_taxonomy ,
188+ "en:fr-bio-16" ,
189+ {"en:organic" , "en:no-gluten" , "en:no-additives" , "en:vegan" },
190+ True ,
191+ ),
192+ ],
193+ )
194+ def test_is_child_of_any (
195+ self , taxonomy : Taxonomy , item : str , candidates : list [str ], output : bool
196+ ):
197+ assert taxonomy .is_child_of_any (item , candidates ) is output
198+
199+ def test_is_child_of_any_unknown_item (self ):
200+ with pytest .raises (ValueError ):
201+ label_taxonomy .is_child_of_any ("unknown-id" , set ())
202+
173203 @pytest .mark .parametrize (
174204 "taxonomy,item,candidates,output" ,
175205 [
176206 (label_taxonomy , "en:organic" , {"en:fr-bio-01" }, True ),
177207 (label_taxonomy , "en:fr-bio-01" , {"en:organic" }, False ),
178208 (label_taxonomy , "en:fr-bio-01" , [], False ),
179- (label_taxonomy , "en:organic" , {"en:gluten-free " }, False ),
209+ (label_taxonomy , "en:organic" , {"en:no-gluten " }, False ),
180210 (
181211 label_taxonomy ,
182212 "en:organic" ,
183- {"en:gluten-free " , "en:no-additives" , "en:vegan" },
213+ {"en:no-gluten " , "en:no-additives" , "en:vegan" },
184214 False ,
185215 ),
186216 (
187217 label_taxonomy ,
188218 "en:organic" ,
189- {"en:gluten-free " , "en:no-additives" , "en:fr-bio-16" },
219+ {"en:no-gluten " , "en:no-additives" , "en:fr-bio-16" },
190220 True ,
191221 ),
192222 ],
193223 )
194- def test_is_child_of_any (
195- self , taxonomy : Taxonomy , item : str , candidates : list , output : bool
224+ def test_is_parent_of_any (
225+ self , taxonomy : Taxonomy , item : str , candidates : list [ str ] , output : bool
196226 ):
197227 assert taxonomy .is_parent_of_any (item , candidates ) is output
198228
199- def test_is_child_of_any_unknwon_item (self ):
229+ def test_is_parent_of_any_unknown_item (self ):
200230 with pytest .raises (ValueError ):
201231 label_taxonomy .is_parent_of_any ("unknown-id" , set ())
202232
233+ @pytest .mark .parametrize (
234+ "taxonomy,item,output" ,
235+ [
236+ (category_taxonomy , "en:brown-camargue-rices" , set ()),
237+ (
238+ category_taxonomy ,
239+ "en:cooked-brown-rices" ,
240+ {"en:unsalted-cooked-brown-rices" },
241+ ),
242+ (
243+ category_taxonomy ,
244+ "en:brown-rices" ,
245+ {
246+ "en:brown-jasmine-rices" ,
247+ "en:brown-basmati-rices" ,
248+ "en:brown-camargue-rices" ,
249+ "en:cooked-brown-rices" ,
250+ "en:unsalted-cooked-brown-rices" ,
251+ },
252+ ),
253+ ],
254+ )
255+ def test_get_children_hierarchy (
256+ self , taxonomy : Taxonomy , item : str , output : set [str ]
257+ ):
258+ node = taxonomy [item ]
259+ children_list = node .get_children_hierarchy ()
260+ assert set ((x .id for x in children_list )) == output
261+
203262 @pytest .mark .parametrize (
204263 "taxonomy,item,output" ,
205264 [
@@ -228,8 +287,8 @@ def test_get_parents_hierarchy(
228287 self , taxonomy : Taxonomy , item : str , output : set [str ]
229288 ):
230289 node = taxonomy [item ]
231- parents = node .get_parents_hierarchy ()
232- assert set ((x .id for x in parents )) == output
290+ parents_list = node .get_parents_hierarchy ()
291+ assert set ((x .id for x in parents_list )) == output
233292
234293 @pytest .mark .parametrize (
235294 "taxonomy,items,output" ,
0 commit comments