Esempio n. 1
0
def test_GenderField_returns_female_value_if_random_no_is_gt_or_eq_male_probability(
        monkeypatch):
    monkeypatch.setattr("random.random", lambda: 0.5)
    gender = field.GenderField(male_value=MALE_VALUE,
                               female_value=FEMALE_VALUE)
    obs = gender.next_value(row)
    assert obs == FEMALE_VALUE
Esempio n. 2
0
def test_RepeatField_generates_list_of_values():
    random.seed(124)
    gender_field = field.RepeatField(field=field.GenderField(
        male_value="M", female_value="F", male_probability=0.6),
                                     min_repeats=3,
                                     max_repeats=7)

    assert gender_field.next_value({}) == ['M', 'M', 'F', 'M', 'F']
    assert gender_field.next_value({}) == ['M', 'M', 'M']
Esempio n. 3
0
def test_RepeatField_generates_joined_list_of_values():
    random.seed(124)
    gender_field = field.RepeatField(field=field.GenderField(
        male_value="M", female_value="F", male_probability=0.6),
                                     min_repeats=3,
                                     max_repeats=7,
                                     glue=",")

    assert gender_field.next_value({}) == "M,M,F,M,F"
    assert gender_field.next_value({}) == "M,M,M"
Esempio n. 4
0
def test_LastNameField_returns_male_last_name_if_gender_is_male(monkeypatch):
    f = mock.Mock()
    f.return_value.last_name_male.return_value = MALE_SURNAME

    monkeypatch.setattr("faker.Faker", f)

    ln_field = field.LastNameField(gender_field="gender")

    gender = field.GenderField(male_value=MALE_VALUE,
                               female_value=FEMALE_VALUE)

    fset = Fieldset(fields={"gender": gender})

    ln_field.init_from_fieldset(fset)

    obs = ln_field.next_value({"gender": MALE_VALUE})
    assert obs == MALE_SURNAME
Esempio n. 5
0
def test_FirstNameField_returns_female_name_if_gender_field_is_female(
        monkeypatch):
    f = mock.Mock()
    f.return_value.first_name_female.return_value = FEMALE_NAME

    monkeypatch.setattr("faker.Faker", f)

    fn_field = field.FirstNameField(gender_field="gender")

    gender = field.GenderField(male_value=MALE_VALUE,
                               female_value=FEMALE_VALUE)

    fset = Fieldset(fields={"gender": gender})

    fn_field.init_from_fieldset(fset)

    obs = fn_field.next_value({"gender": FEMALE_VALUE})
    assert obs == FEMALE_NAME
Esempio n. 6
0
def test_MiddleNameField_returns_different_name_if_same_as_first_name(
        monkeypatch):
    f = mock.Mock()
    f.return_value.first_name_female.side_effect = [FEMALE_NAME, FEMALE_NAME2]

    monkeypatch.setattr("faker.Faker", f)
    fn_field = field.FirstNameField(gender_field="gender")

    mn_field = field.MiddleNameField(gender_field="gender",
                                     first_name_field="first_name")

    gender = field.GenderField(male_value=MALE_VALUE,
                               female_value=FEMALE_VALUE)

    fset = Fieldset(fields={"first_name": fn_field, "gender": gender})

    mn_field.init_from_fieldset(fset)

    obs = mn_field.next_value({
        "gender": FEMALE_VALUE,
        "first_name": FEMALE_NAME
    })
    assert obs == FEMALE_NAME2