1- import random
21import re
32
43import pandas as pd
@@ -202,9 +201,8 @@ def test_religion_based_transformation():
202201 )
203202 from giskard .scanner .robustness .text_transformations import TextReligionTransformation
204203
205- t = TextReligionTransformation (column = "text" )
204+ t = TextReligionTransformation (column = "text" , rng_seed = 10 )
206205
207- random .seed (0 )
208206 transformed = dataset .transform (t )
209207 transformed_text = transformed .df .text .values
210208
@@ -213,12 +211,12 @@ def test_religion_based_transformation():
213211 "mois de ramadan."
214212 )
215213 assert (
216- transformed_text [1 ] == "Une partie des chrétiens commémorent ce vendredi 5 mai la naissance, l’éveil et la "
217- "mort de muhammad , dit « le Bouddha »"
214+ transformed_text [1 ] == "Une partie des hindous commémorent ce vendredi 5 mai la naissance, l’éveil et la "
215+ "mort de abraham , dit « le Bouddha »"
218216 )
219217 assert (
220218 transformed_text [2 ] == "Signs have also been placed in the direction of kumbh mela along one of the Peak "
221- "District’s most popular hiking routes, Cave Dale, to help christians combine prayer "
219+ "District’s most popular hiking routes, Cave Dale, to help jews combine prayer "
222220 "with enjoying the outdoors."
223221 )
224222 assert (
@@ -228,9 +226,6 @@ def test_religion_based_transformation():
228226
229227
230228def test_country_based_transformation ():
231- import random
232-
233- random .seed (10 )
234229 dataset = _dataset_from_dict (
235230 {
236231 "text" : [
@@ -244,31 +239,30 @@ def test_country_based_transformation():
244239 )
245240 from giskard .scanner .robustness .text_transformations import TextNationalityTransformation
246241
247- t = TextNationalityTransformation (column = "text" )
242+ t = TextNationalityTransformation (column = "text" , rng_seed = 0 )
248243
249244 transformed = dataset .transform (t )
250245 transformed_text = transformed .df .text .values
251246
252247 assert (
253- transformed_text [0 ] == "Les musulmans de Eswatini fêtent vendredi 21 avril la fin du "
248+ transformed_text [0 ] == "Les musulmans de Saint Thomas et Prince fêtent vendredi 21 avril la fin du "
254249 "jeûne pratiqué durant le mois de ramadan."
255250 )
256- assert transformed_text [1 ] == "Des incendies ravagent l'Congo depuis la fin août 2019."
251+ assert transformed_text [1 ] == "Des incendies ravagent l'Liban depuis la fin août 2019."
257252 assert (
258- transformed_text [2 ] == "Bali is an Libyan island known for its forested volcanic mountains, iconic"
253+ transformed_text [2 ] == "Bali is an Singaporean island known for its forested volcanic mountains, iconic"
259254 " rice paddies, beaches and coral reefs. The island is home to religious sites "
260255 "such as cliffside Uluwatu Temple"
261256 )
262257 assert (
263258 transformed_text [3 ]
264- == "President Joe Biden visited U.S. 's capital for the first time since Nigeria invaded the country"
259+ == "President Joe Biden visited UAE 's capital for the first time since Syria invaded the country"
265260 )
266261
267262
268263def test_country_based_transformation_edge_cases ():
269264 from giskard .scanner .robustness .text_transformations import TextNationalityTransformation
270265
271- random .seed (0 )
272266 df = pd .DataFrame (
273267 {
274268 "text" : [
@@ -281,7 +275,7 @@ def test_country_based_transformation_edge_cases():
281275 }
282276 )
283277
284- t = TextNationalityTransformation (column = "text" )
278+ t = TextNationalityTransformation (column = "text" , rng_seed = 0 )
285279
286280 t1 = t .make_perturbation (df .iloc [0 ])
287281 t2 = t .make_perturbation (df .iloc [1 ])
0 commit comments