Esempio n. 1
0
def test_report_init():
    a = Report(1, 3, name="a")
    assert a.t0 == 1
    assert a.te == 3
    assert a.name == "a"
    start = pytz.utc.localize(dt.datetime(2000, 1, 1))
    end = start + dt.timedelta(seconds=60)
    b = Report(start, end, name="b")
    assert b.t0 == 946684800.0
    assert b.te == 946684860.0
    start = dt.datetime(2000, 1, 1)
    end = start + dt.timedelta(seconds=60)
    c = Report(start, end, name="c")
    assert c.t0 == 946684800.0
    assert c.te == 946684860.0
    with pytest.raises(ValueError):
        d = Report(t0=5, te=1, name="d")
    return True
Esempio n. 2
0
def test_timeserie_toreports():
    a = TimeSerie(10 * np.sin(np.linspace(0, 2 * np.pi, 100)),
                  t0=1,
                  fs=10,
                  name="a")
    b = a > 4
    b.name = "a > 4"
    reports = b.to_reports()
    assert len(reports) == 1
    assert compare_reports(reports[0], Report(1.7, 5.4, name="a > 4"))
    return True
Esempio n. 3
0
def test_report_totimeserie():
    a = Report(2, 4, name="a")
    ts_a = a.to_timeserie()
    assert compare_timeseries(
        ts_a, TimeSerie([0.0, 1.0, 1.0, 0.0], t0=1.0, fs=1, name="a"))
    b = Report(3, 8, name="b")
    ts_b = b.to_timeserie(fs=4, window=2)
    cmp_b = TimeSerie([0.0, 0.0] + (20 * [1.0]) + [0.0, 0.0],
                      t0=2.5,
                      fs=4,
                      name="b")
    ts_b._reprconfig["threshold"] = 100
    cmp_b._reprconfig["threshold"] = 100
    assert compare_timeseries(ts_b, cmp_b)
    return True
Esempio n. 4
0
def test_statechangearray_toreports():
    a = StateChangeArray([True, False, True, False], t=[2, 4, 6, 8], name="a")
    r1, r2 = a.to_reports()
    assert compare_reports(r1, Report(2, 4, name="a"))
    assert compare_reports(r2, Report(6, 8, name="a"))
    b = StateChangeArray([False, True, False, True, False],
                         t=[1, 2, 4, 6, 8],
                         name="b")
    r3, r4 = b.to_reports()
    assert compare_reports(r3, Report(2, 4, name="b"))
    assert compare_reports(r4, Report(6, 8, name="b"))
    c = StateChangeArray([False, True, False, True, False],
                         t=[1, 2, 4, 6, 8],
                         name="c")
    r5, r6 = c.to_reports()
    assert compare_reports(r5, Report(2, 4, name="c"))
    assert compare_reports(r6, Report(6, 8, name="c"))
    d = StateChangeArray([1, 2, 4, 7], t=[2, 4, 6, 8], name="d")
    with pytest.raises(ValueError):
        d.to_reports()
    return True
Esempio n. 5
0
def test_statechangearray_fromreports():
    a1 = Report(t0=2, te=4, name="a")
    a2 = Report(t0=6, te=8, name="a")
    a = StateChangeArray.from_reports([a1, a2])
    assert compare_statechangearrays(
        a,
        StateChangeArray([True, False, True, False], t=[2, 4, 6, 8], name="a"))
    a3 = Report(t0=12, te=13, name="a")
    a3.te = 10  # this is a hacky way to test errors in the from_reports() method
    with pytest.raises(ValueError):
        b = StateChangeArray.from_reports([a1, a2, a3])
    a4 = Report(t0=7, te=10, name="a")
    with pytest.raises(ValueError):
        c = StateChangeArray.from_reports([a1, a2, a4])
    d = StateChangeArray.from_reports([a1, a2, a4], on_error="ignore")
    assert compare_statechangearrays(
        d,
        StateChangeArray([True, False, True, False], t=[2, 4, 6, 8], name="a"))
    e = StateChangeArray.from_reports([a1, a2, a4], on_error="extend")
    assert compare_statechangearrays(
        e,
        StateChangeArray([True, False, True, False], t=[2, 4, 6, 10],
                         name="a"))
    return True
Esempio n. 6
0
def test_report_tostatechangearray():
    a = Report(1, 4, name="a")
    array = a.to_statechangearray()
    assert compare_statechangearrays(
        array, StateChangeArray([True, False], t=[1, 4], name="a"))
    return True
Esempio n. 7
0
def test_report_toevent():
    a = Report(1, 3, name="a")
    a_start, a_end = a.to_events()
    assert compare_events(a_start, Event(1, t=1, name="a"))
    assert compare_events(a_end, Event(0, t=3, name="a"))
    return True
Esempio n. 8
0
def test_report_repr():
    a = Report(0, 8, name="a")
    assert repr(a) == "Report(t0=0, te=8, name='a')"
    return True
Esempio n. 9
0
def test_report_duration():
    start = dt.datetime(2000, 1, 1)
    end = start + dt.timedelta(seconds=60)
    a = Report(start, end, name="a")
    assert a.duration == 60
    return True