예제 #1
0
def test_pull_request_closed_no(pr_samples):  # noqa: F811
    calc = ClosedCalculator()
    time_from = datetime.now(tz=timezone.utc) - timedelta(days=365 * 3)
    time_to = time_from + timedelta(days=7)
    for pr in pr_samples(100):
        calc(pr, time_from, time_to)
    m = calc.value()
    assert not m.exists
예제 #2
0
def test_pull_request_metrics_timedelta_stability(pr_samples, cls,
                                                  dtypes):  # noqa: F811
    calc = cls()
    time_from = datetime.now(tz=timezone.utc) - timedelta(days=10000)
    time_to = datetime.now(tz=timezone.utc)
    for pr in pr_samples(1000):
        pr = random_dropout(ensure_dtype(pr, dtypes[0]), 0.5)
        r = calc.analyze(pr, time_from, time_to)
        assert (r is None) or ((isinstance(r, dtypes[1]))
                               and r >= dtypes[1](0)), str(pr)
예제 #3
0
def test_pull_request_flow_ratio_no_opened(pr_samples):  # noqa: F811
    calc = FlowRatioCalculator()
    time_to = datetime.now(tz=timezone.utc)
    time_from = time_to - timedelta(days=180)
    for pr in pr_samples(100):
        if pr.closed and pr.closed.best < time_to:
            calc(pr, time_from, time_to)
    m = calc.value()
    assert m.exists
    assert m.value == 0
예제 #4
0
def test_pull_request_metrics_float_binned(pr_samples, cls):  # noqa: F811
    time_from = datetime.now(tz=timezone.utc) - timedelta(days=365)
    time_to = datetime.now(tz=timezone.utc)
    time_intervals = Granularity.split("month", time_from, time_to)
    binned = BinnedPullRequestMetricCalculator([cls()], time_intervals)
    result = binned(pr_samples(1000))
    for m in result:
        assert m[0].exists
        assert m[0].value > 1
        assert m[0].confidence_min is None
        assert m[0].confidence_max is None
예제 #5
0
def test_pull_request_flow_ratio(pr_samples):  # noqa: F811
    calc = FlowRatioCalculator()
    time_from = datetime.now(tz=timezone.utc) - timedelta(days=365)
    time_to = datetime.now(tz=timezone.utc)
    for pr in pr_samples(1000):
        calc(pr, time_from, time_to)
    m = calc.value()
    assert m.exists
    assert 0 < m.value < 1
    assert m.confidence_min is None
    assert m.confidence_max is None
예제 #6
0
def test_pull_request_opened_no(pr_samples):  # noqa: F811
    calc = OpenedCalculator()
    time_to = datetime.now(tz=timezone.utc)
    time_from = time_to - timedelta(days=180)
    n = 0
    for pr in pr_samples(100):
        if pr.closed and pr.closed.best < time_to:
            n += 1
            calc(pr, time_from, time_to)
    assert n > 0
    m = calc.value()
    assert not m.exists
예제 #7
0
def test_pull_request_metrics_out_of_bounds(pr_samples, cls,
                                            peak_attr):  # noqa: F811
    calc = cls()
    for pr in pr_samples(100):
        time_from = datetime.now(tz=timezone.utc) - timedelta(days=10000)
        for attr in peak_attr.split(","):
            time_from = max(getattr(pr, attr).best, time_from)
        time_from += timedelta(days=1)
        time_to = time_from + timedelta(days=7)
        assert calc.analyze(pr, time_from, time_to) is None

        time_from = datetime.now(tz=timezone.utc)
        for attr in peak_attr.split(","):
            time_from = min(getattr(pr, attr).best, time_from)
        time_from -= timedelta(days=7)
        time_to = time_from + timedelta(days=1)
        assert calc.analyze(pr, time_from, time_to) is None
예제 #8
0
def test_pull_request_metrics_counts(pr_samples, cls):  # noqa: F811
    calc = cls()
    nones = nonones = 0
    for pr in pr_samples(1000):
        time_to = datetime.now(tz=timezone.utc)
        time_from = time_to - timedelta(days=10000)
        delta = calc.analyze(pr, time_from, time_to)
        assert isinstance(delta, int)
        if calc.calc.analyze(pr, time_from, time_to) is not None:
            assert delta == 1
            nonones += 1
        else:
            assert delta == 0
            nones += 1
    if cls is not WorkInProgressCounter:
        assert nones > 0
    assert nonones > 0