Пример #1
0
def test_signal_pwm_special_method_repr():
    """ expect a __repr__ format """
    with mock.patch('mycodo.inputs.signal_pwm.SignalPWMInput.get_measurement'
                    ) as mock_measure:
        mock_measure.side_effect = [(0, 0, 0)]
        signal_pwm = SignalPWMInput(None, None, None, testing=True)
        signal_pwm.read()
        assert "<SignalPWMInput(frequency=0.00)(pulse_width=0.00)(duty_cycle=0.00)>" in repr(
            signal_pwm)
Пример #2
0
def test_signal_pwm_special_method_str():
    """ expect a __str__ format """
    with mock.patch('mycodo.inputs.signal_pwm.SignalPWMInput.get_measurement'
                    ) as mock_measure:
        mock_measure.side_effect = [(0, 0, 0)]
        signal_pwm = SignalPWMInput(None, None, None, testing=True)
        signal_pwm.read()
    assert "Frequency: 0.00" in str(signal_pwm)
    assert "Pulse Width: 0.00" in str(signal_pwm)
    assert "Duty Cycle: 0.00" in str(signal_pwm)
Пример #3
0
def test_signal_pwm_read_updates_temp():
    """  Verify that SignalPWMInput(None, None, None, testing=True).read() gets the average temp """
    with mock.patch('mycodo.inputs.signal_pwm.SignalPWMInput.get_measurement'
                    ) as mock_measure:
        mock_measure.side_effect = [(23, 50, 3000), (25, 55, 3200)]
        signal_pwm = SignalPWMInput(None, None, None, testing=True)
        assert signal_pwm._frequency is None
        assert signal_pwm._pulse_width is None
        assert signal_pwm._duty_cycle is None
        assert not signal_pwm.read()
        assert signal_pwm._frequency == 23.0
        assert signal_pwm._pulse_width == 50.0
        assert signal_pwm._duty_cycle == 3000.0
        assert not signal_pwm.read()
        assert signal_pwm._frequency == 25.0
        assert signal_pwm._pulse_width == 55.0
        assert signal_pwm._duty_cycle == 3200.0
Пример #4
0
def test_signal_pwm_condition_properties():
    """ verify duty_cycle property """
    with mock.patch('mycodo.inputs.signal_pwm.SignalPWMInput.get_measurement'
                    ) as mock_measure:
        mock_measure.side_effect = [(23, 50, 3000), (25, 55, 3200)]
        signal_pwm = SignalPWMInput(None, None, None, testing=True)
        assert signal_pwm._frequency is None
        assert signal_pwm._pulse_width is None
        assert signal_pwm._duty_cycle is None
        assert signal_pwm.frequency == 23.0
        assert signal_pwm.frequency == 23.0
        assert signal_pwm.pulse_width == 50.0
        assert signal_pwm.pulse_width == 50.0
        assert signal_pwm.duty_cycle == 3000.0
        assert signal_pwm.duty_cycle == 3000.0
        assert not signal_pwm.read()
        assert signal_pwm.frequency == 25.0
        assert signal_pwm.pulse_width == 55.0
        assert signal_pwm.duty_cycle == 3200.0