示例#1
0
def test_convergence_to_zero_does_not_raise():
    analyser = Analyser()
    analyser.check_temperature_convergence(fermenter="f1",
                                           temperatures=[20, 19.5, 18, 17, 17],
                                           is_cooling=True,
                                           setpoint=0,
                                           acceptable_delta=0.5)
示例#2
0
def test_convergence_does_not_raise_on_contained_variations():
    analyser = Analyser()

    # Should not raise. What matters in the end is the delta between first and last values.
    analyser.check_temperature_convergence(
        fermenter="f1", temperatures=[20, 21, 18, 17, 17], is_cooling=True, setpoint=0,
    )
示例#3
0
def test_state_is_reset_to_ok_after_succesful_run():
    analyser = Analyser(db='testdb.json', reset_db=True)
    analyser.analyse = mock.MagicMock()

    analyser.run(("f1", ), date="now()", group_time="30m")

    assert analyser.db.get(Query().id == "f1")['state'] == STATE.OK
示例#4
0
def test_check_temperature_raises():
    analyser = Analyser()

    with raises(Anomaly) as excinfo:
        analyser.check_temperature_max(
            fermenter="f1", temperatures=[21, 22, 23, 24, 25.1], max_temp=25
        )
    assert excinfo.value.message == "temperature-exceeds-max"
示例#5
0
def test_steady_temperature_should_not_raise():
    analyser = Analyser()

    # Should not raise.
    analyser.check_temperature_convergence(fermenter="f1",
                                           temperatures=[19, 19, 19, 19, 19],
                                           is_cooling=False,
                                           setpoint=20,
                                           acceptable_delta=0.5)
示例#6
0
def test_cold_unit_breaks_during_cc():
    analyser = Analyser()

    # Should raise.
    with raises(Anomaly) as excinfo:
        analyser.check_temperature_convergence(fermenter="f1",
                                               temperatures=[4, 4, 4, 4, 6],
                                               is_cooling=True,
                                               setpoint=0,
                                               acceptable_delta=0.5)
    assert excinfo.value.message == STATE.TEMP_RISING
示例#7
0
def test_temperature_decreases_but_should_be_increasing():
    analyser = Analyser()

    # Should raise.
    with raises(Anomaly) as excinfo:
        analyser.check_temperature_convergence(
            fermenter="f1",
            temperatures=[20, 19.5, 19, 19, 19],
            is_cooling=False,
            setpoint=20,
        )
    assert excinfo.value.message == "temperature-falling"
示例#8
0
def test_oscillation_around_20():
    analyser = Analyser()

    # Should raise.
    with raises(Anomaly) as excinfo:
        analyser.check_temperature_convergence(
            fermenter="f1",
            temperatures=[19.5, 20, 20.5, 20, 20.5],
            is_cooling=True,
            setpoint=20,
        )
    assert excinfo.value.message == "temperature-rising"
示例#9
0
def test_convergence_to_zero_raises():
    analyser = Analyser()

    # Should raise.
    with raises(Anomaly) as excinfo:
        analyser.check_temperature_convergence(
            fermenter="f1",
            temperatures=[20, 20, 20.5, 20.6, 20.7],
            is_cooling=True,
            setpoint=0,
        )
    assert excinfo.value.message == "temperature-rising"
示例#10
0
def test_temperature_decreases_but_should_be_increasing():
    analyser = Analyser()

    # Should raise.
    with raises(Anomaly) as excinfo:
        analyser.check_temperature_convergence(
            fermenter="f1",
            temperatures=[20, 19.5, 19, 19, 19],
            is_cooling=False,
            setpoint=20,
            acceptable_delta=0.5)
    assert excinfo.value.message == STATE.TEMP_FALLING
示例#11
0
def test_oscillation_around_20():
    analyser = Analyser()

    # Should raise.
    with raises(Anomaly) as excinfo:
        analyser.check_temperature_convergence(
            fermenter="f1",
            temperatures=[19.5, 20, 20.5, 20, 21],
            is_cooling=True,
            setpoint=20,
            acceptable_delta=0.5)
    assert excinfo.value.message == STATE.TEMP_RISING
示例#12
0
def test_same_message_is_not_sent_twice():
    analyser = Analyser(db='testdb.json', reset_db=True)
    analyser.send_signal_message = mock.MagicMock()

    analyser.send_alert(Anomaly(STATE.NO_DATA, {'fermenter': 'f1'}))
    assert analyser.send_signal_message.call_count == 1

    analyser.send_alert(Anomaly(STATE.NO_DATA, {'fermenter': 'f1'}))
    assert analyser.send_signal_message.call_count == 1
示例#13
0
def test_check_temperature_convergence():
    analyser = Analyser()

    # Should not raise
    analyser.check_temperature_max(
        fermenter="f1", temperatures=[20, 21, 22, 23], max_temp=25
    )

    analyser.check_temperature_max(
        fermenter="f1", temperatures=[20, 21, 22, 23, 24, 25], max_temp=25
    )