示例#1
0
def test_duration_filter() -> None:
    log = create_task4_log()
    customers = create_customers(log)
    process_event_history(log, customers)

    all_calls = []
    for c in customers:
        hist = c.get_history()
        all_calls.extend(hist[0])

    fil = DurationFilter()
    invalid_inputs = ['', 'LG40', 'l50', 'g65', '50', 'sdklfjeind', ' ']
    for input in invalid_inputs:
        filtered = fil.apply(customers, all_calls, input)
        assert filtered == all_calls

    filtered = fil.apply(customers, all_calls, 'L60')
    for call in filtered:
        assert call.duration < 60

    filtered = fil.apply(customers, filtered, 'G60')
    assert filtered == []

    filtered = fil.apply(customers, all_calls, 'G5400')
    for call in filtered:
        assert call.duration > 5400
示例#2
0
def test_absolute_garbage(s: str) -> None:
    """ Test that none of the filters raise errors when absolute garbage input
    strings are passed in.
    """
    print(s)
    cf = CustomerFilter()
    df = DurationFilter()
    lf = LocationFilter()
    # test that nothing crashes
    cf.apply(CUSTOMERS, CALL_LIST, s)
    df.apply(CUSTOMERS, CALL_LIST, s)
    lf.apply(CUSTOMERS, CALL_LIST, s)
示例#3
0
def test_duration_filter(s: str, t: int):
    """ Test that DurationFilter works in the general case - with valid inputs,
    aka either 'L' or 'G' followed by the limit time (in seconds).
    """
    filt = DurationFilter()
    results = filt.apply(CUSTOMERS, CALL_LIST, s + str(t))
    for call in results:
        if s == 'L':
            assert call.duration < t
        else:
            assert call.duration > t