def test_pcf8591_loopback_switching_channels(): adc = PCF8591(i2c, FOUR_SINGLE_ENDED) p1 = adc.single_ended_input(1) p2 = adc.single_ended_input(2) for i in xrange(8): assert p1.value == 0.0 assert p2.value == 1.0
def test_pcf8591_loopback_differential_gnd_to_ain3(): adc = PCF8591(i2c, THREE_DIFFERENTIAL) cmp_gnd = adc.differential_input(1) with adc.output as output: for v in (i / 255.0 for i in xrange(256)): output.value = v assert_is_approx(max(-0.5, -v), cmp_gnd.value)
def test_pcf8591_loopback_differential_vref_to_ain3(): adc = PCF8591(i2c, THREE_DIFFERENTIAL) cmp_vref = adc.differential_input(2) with adc.output as output: for v in (i / 255.0 for i in range(256)): output.value = v assert_is_approx(min(0.5, 1 - v), cmp_vref.value)
def test_pcf8591_loopback_single_ended(): adc = PCF8591(i2c, FOUR_SINGLE_ENDED) input = adc.single_ended_input(3) with adc.output as output: for v in (i / 255.0 for i in xrange(256)): output.value = v assert_is_approx(v, input.value)
def test_can_be_created_with_one_differential_and_two_single_ended_inputs(): adc = PCF8591(i2c, SINGLE_ENDED_AND_DIFFERENTIAL) assert adc.single_ended_input_count == 2 assert adc.differential_input_count == 1 assert_all_input_pins_report_direction(adc)
def test_can_be_created_with_three_differential_inputs(): adc = PCF8591(i2c, THREE_DIFFERENTIAL) assert adc.single_ended_input_count == 0 assert adc.differential_input_count == 3 assert_all_input_pins_report_direction(adc)
def test_can_be_created_with_four_single_ended_inputs(): adc = PCF8591(i2c, FOUR_SINGLE_ENDED) assert adc.single_ended_input_count == 4 assert adc.differential_input_count == 0 assert_all_input_pins_report_direction(adc)
def create_pcf8591(*args, **kwargs): adc = PCF8591(*args, **kwargs) i2c.message_precondition = correct_message_for(adc) return adc
def test_cannot_be_created_with_an_invalid_mode(): with pytest.raises(ValueError): PCF8591(i2c, 999)