def __init__(self, root_output_path): self.root_output_path = root_output_path self.random = random self.fake = Faker() self.random_mimesis = Random() self.random.seed(0) self.random_mimesis.seed(0) self._ = Field('en', seed=0) Faker.seed(0)
def __init__(self, *, seed: Seed = None, **kwargs: t.Any) -> None: """Initialize attributes. Keep in mind, that locale-independent data providers will work only with keyword-only arguments since version 5.0.0. :param seed: Seed for random. When set to `None` the current system time is used. """ self.seed = seed self.random = Random() self.reseed(seed)
def flights(): return [ models.Flight.objects.create( name=f"Flight_{i}", number=Random().custom_code(mask="@@ ####"), departure=Address().city(), destination=Address().city(), scheduled_at=Datetime().datetime(), expected_at=Datetime().datetime(), duration=Numbers().integer_number(start=1, end=100), fare=Numbers().float_number(start=1, end=10000, precision=2), ) for i in range(10) ]
def generate_groups() -> list: groups_objects = [] for _ in range(5): group_num = Random().custom_code("@@@-###") specialty = " ".join(Text("ru").words(quantity=2)) alma_mater = orm.select(am for am in models.AlmaMater).random(1)[0] groups_objects.append( models.Group( group_num=group_num, specialty=specialty, alma_mater=alma_mater, private=True, ), ) return groups_objects
def reseed(self, seed: Seed = None) -> None: """Reseed the internal random generator. In case we use the default seed, we need to create a per instance random generator, in this case two providers with the same seed will always return the same values. :param seed: Seed for random. When set to `None` the current system time is used. """ if self.random is random: self.random = Random() self.seed = seed self.random.seed(self.seed)
new_some_view = defaultdict(list) for some in SOMETHING: new_some_view[some['key']].append(some['id']) with soft_assertions(): for key in new_some_view: assert_that(len(new_some_view[key])).described_as( f'key "{key}"" has duplicates "{new_some_view[key]}"' ).is_less_than_or_equal_to(1) @mark.parametrize('some_list', [ [20, 30, 20, 30, 40, 50, 15, 11, 20, 40, 50, 15, 6, 7], [9, 5, 4], Random().randints(20, 0, 10), ]) def test_list_doesnt_have_duplicates(some_list): """Parametrized test asserts there is no duplicate ints in list. Using next features: 1. Random() function; 2. Sorting set; 3. Sorting list; 4. List comprehension; """ some_list.sort() logging.info(some_list)
groups = orm.select(gr for gr in models.Group)[:] if orm.select(acs for acs in models.AcademicStatus)[:]: print("Селектинг форм обучения") ac_statuses = orm.select(acs for acs in models.AcademicStatus)[:] else: print("Генерация форм обучения") ac_statuses = generate_ac_statuses() if orm.select(st for st in models.State)[:]: print("Селектинг статусов") bot_statuses = orm.select(st for st in models.State)[:] else: print("Генерация статусов") bot_statuses = generate_bot_statuses() for i in range(20): vk_id = Random().custom_code(mask="#########") name, surname = person.full_name().split() email = person.email() phone = person.telephone(mask="89########") with orm.db_session: ac_status = orm.select(ac for ac in models.AcademicStatus).random(1)[0] group = orm.select(gr for gr in models.Group).random(1)[0] st = models.Student( vk_id=vk_id, first_name=name, last_name=surname, email=email, phone_number=phone, group=group, academic_status=ac_status, )