def test_SimpleProbability_p_always_returns_same_level_p():
    prob = modify.SimpleProbability(0.45)
    assert prob.p('alfjhlfhlwkhf') == 0.45
    assert prob.p(None) == 0.45
    assert prob.p(modify.Household(1)) == 0.45
    assert prob.p(modify.Person(1)) == 0.45
    assert prob.p(modify.Activity(1)) == 0.45
def test_PersonPolicy_apply_to_delegates_to_modifier_policy_apply_to_for_list_of_probabilities(mocker, SmithHousehold):
    mocker.patch.object(modify.RemoveActivity, 'apply_to')
    mocker.patch.object(modify.SimpleProbability, 'p', return_value=1)

    policy = modify.PersonPolicy(modify.RemoveActivity(['']), [1., modify.SimpleProbability(1.)])
    household = SmithHousehold

    policy.apply_to(household)

    assert modify.RemoveActivity.apply_to.call_count == 4
def test_HouseholdPolicy_apply_to_delegates_to_modifier_policy_apply_to_for_single_probability(mocker, SmithHousehold):
    mocker.patch.object(modify.RemoveActivity, 'apply_to')
    mocker.patch.object(modify.SimpleProbability, 'sample', return_value=True)

    policy = modify.HouseholdPolicy(modify.RemoveActivity(['']), modify.SimpleProbability(1.))
    household = SmithHousehold

    policy.apply_to(household)

    modify.RemoveActivity.apply_to.assert_called_once_with(household)
def test_verify_probability_check_list_of_probabilities():
    p_list = [
        modify.HouseholdProbability(0.5),
        modify.ActivityProbability([''], 0.5),
        modify.SimpleProbability(0.5), 0.2
    ]
    verified_p_list = modify.verify_probability(
        p_list, (float, list, modify.HouseholdProbability,
                 modify.ActivityProbability, modify.SimpleProbability))

    assert p_list[:-1] == verified_p_list[:-1]
    assert isinstance(verified_p_list[-1], modify.SimpleProbability)
    assert verified_p_list[-1].p(None) == 0.2