コード例 #1
0
ファイル: generator.py プロジェクト: wittejm/recordexpungPDX
def _build_case_strategy(draw: Callable[[SearchStrategy], Any],
                         min_charges_size=0) -> Case:
    case_summary = draw(
        builds(CaseSummary, date=just(DateWithFuture(date=draw(dates())))))
    charge_classes = get_charge_classes()
    charge_strategy_choices = list(
        map(
            lambda charge_class: _build_charge_strategy(
                charge_class(), case_summary), charge_classes))
    charge_strategy = one_of(charge_strategy_choices)
    charges = draw(lists(charge_strategy, min_charges_size))
    return Case(case_summary, charges=tuple(charges))
コード例 #2
0
    for _, module_name, _ in pkgutil.iter_modules(charge_types.__path__):  # type: ignore  # mypy issue #1422
        module = import_module(f"{charge_types.__name__}.{module_name}")
        attrs = list(module.__dict__.values())
        charge_subclass_attrs = list(filter(lambda attr: _is_proper_charge_subclass(attr), attrs))
        charge_classes += charge_subclass_attrs
    return charge_classes


def _build_charge_strategy(charge_class: Type[Charge], case: CaseSummary) -> SearchStrategy[Charge]:
    if charge_class == DismissedCharge:
        disposition_status = one_of(
            just(DispositionStatus.DISMISSED), just(DispositionStatus.NO_COMPLAINT), just(DispositionStatus.DIVERTED)
        )
    else:
        disposition_status = one_of(just(DispositionStatus.CONVICTED), just(DispositionStatus.UNRECOGNIZED))
    disposition = builds(Disposition, status=disposition_status, date=dates(max_value=date(9000, 12, 31)))
    return builds(charge_class, case_number=just(case.case_number), disposition=one_of(none(), disposition))


@composite
def _build_case_strategy(draw: Callable[[SearchStrategy], Any], min_charges_size=0) -> Case:
    case_summary = draw(builds(CaseSummary))
    charge_classes = get_charge_classes()
    charge_strategy_choices = list(
        map(lambda charge_class: _build_charge_strategy(charge_class, case_summary), charge_classes)
    )
    charge_strategy = one_of(charge_strategy_choices)
    charges = draw(lists(charge_strategy, min_charges_size))
    return Case(case_summary, charges=tuple(charges))

コード例 #3
0
from datetime import date

from dateutil.relativedelta import relativedelta
from hypothesis import given
from hypothesis._strategies import dates

from expungeservice.util import DateWithFuture


@given(dates(), dates())
def test_date_with_future_compares_like_date(x: date, y: date):
    x2 = DateWithFuture(x.year, x.month, x.day)
    y2 = DateWithFuture(y.year, y.month, y.day)
    assert (x == y) == (x2 == y2)
    assert (x >= y) == (x2 >= y2)  # type: ignore
    assert (x > y) == (x2 > y2)
    assert (x <= y) == (x2 <= y2)  # type: ignore
    assert (x < y) == (x2 < y2)


@given(dates(), dates(), dates(), dates())
def test_date_with_future_arithmetics_like_date(a: date, b: date, c: date,
                                                d: date):
    try:
        r1 = relativedelta(a, b)
        r2 = relativedelta(b, c)
        r3 = relativedelta(c, d)
        d2 = DateWithFuture(d.year, d.month, d.day)
        result = d + r1 - r2 + r3
        assert result == (d2 + r1 - r2 + r3).date
    except (ValueError, OverflowError) as e:
コード例 #4
0
ファイル: generator.py プロジェクト: wittejm/recordexpungPDX
    return charge_classes


@composite
def _build_charge_strategy(draw: Callable[[SearchStrategy],
                                          Any], charge_type: ChargeType,
                           case: CaseSummary) -> SearchStrategy[Charge]:
    if charge_type == DismissedCharge():
        disposition_status = one_of(just(DispositionStatus.DISMISSED),
                                    just(DispositionStatus.NO_COMPLAINT),
                                    just(DispositionStatus.DIVERTED))
    else:
        disposition_status = one_of(just(DispositionStatus.CONVICTED),
                                    just(DispositionStatus.UNRECOGNIZED))
    disposition_date = just(
        DateWithFuture(date=draw(dates(max_value=date(9000, 12, 31)))))
    disposition = builds(Disposition,
                         status=disposition_status,
                         date=disposition_date)
    arrest_date = just(
        DateWithFuture(date=draw(dates(max_value=date(9000, 12, 31)))))
    probation_revoked_date = one_of(
        none(),
        just(DateWithFuture(date=draw(dates(max_value=date(9000, 12, 31))))))
    return draw(
        builds(
            Charge,
            charge_type=just(charge_type),
            case_number=just(case.case_number),
            disposition=disposition,
            date=arrest_date,