@@ -437,6 +437,43 @@ def test_dir_include_all_providers_attribute_in_list(self):
437437 attributes = dir (fake )
438438 assert attributes == expected
439439
440+ def test_select_factory_distribution_uses_instance_random (self ):
441+ from faker .utils .distribution import choices_distribution
442+
443+ locale = OrderedDict ([("de_DE" , 3 ), ("en_US" , 2 ), ("ja_JP" , 5 )])
444+ fake = Faker (locale )
445+ fake .seed_instance (12345 )
446+
447+ instance_random = fake ._factories [0 ].random
448+ with patch ("faker.proxy.choices_distribution" , wraps = choices_distribution ) as mock_dist :
449+ fake .name ()
450+ mock_dist .assert_called_once ()
451+ args = mock_dist .call_args [0 ]
452+ assert args [2 ] is instance_random
453+
454+ def test_seed_instance_deterministic_multi_locale_no_weights (self ):
455+ fake = Faker (["en_US" , "ja_JP" , "de_DE" ])
456+ fake .seed_instance (12345 )
457+ first_run = [fake .name () for _ in range (20 )]
458+
459+ fake2 = Faker (["en_US" , "ja_JP" , "de_DE" ])
460+ fake2 .seed_instance (12345 )
461+ second_run = [fake2 .name () for _ in range (20 )]
462+
463+ assert first_run == second_run
464+
465+ def test_seed_instance_deterministic_multi_locale_with_weights (self ):
466+ locale = OrderedDict ([("de_DE" , 3 ), ("en_US" , 2 ), ("ja_JP" , 5 )])
467+ fake = Faker (locale )
468+ fake .seed_instance (12345 )
469+ first_run = [fake .name () for _ in range (20 )]
470+
471+ fake2 = Faker (locale )
472+ fake2 .seed_instance (12345 )
473+ second_run = [fake2 .name () for _ in range (20 )]
474+
475+ assert first_run == second_run
476+
440477 def test_copy (self ):
441478 fake = Faker ("it_IT" )
442479 fake2 = copy .deepcopy (fake )
0 commit comments