def test_invalid_pulse_length(self):
        reference_pulses_not_enough = TestNecDecoder.reference_pulses[:-1]

        decoder = NecDecoder()
        start = decoder._find_start_index(reference_pulses_not_enough)

        assert not decoder._validate_pulses(reference_pulses_not_enough, start)
    def test_new_message(self):
        decoder = NecDecoder()
        start = decoder._find_start_index(TestNecDecoder.reference_pulses)

        decoder._classify_message(TestNecDecoder.reference_pulses, start)

        assert decoder.current_message_type == NEW_MESSAGE
    def test__find_start_index_no_start(self):
        reference_pulses_no_start = TestNecDecoder.reference_pulses[1:]

        decoder = NecDecoder()
        start = decoder._find_start_index(reference_pulses_no_start)

        assert start == INVALID_FRAME
    def test_no_end_low(self):
        # Set the last pulse to a high time
        reference_pulses = TestNecDecoder.reference_pulses[:]
        reference_pulses[len(reference_pulses) - 1] = 1687.5
        reference_pulses_no_end_low = reference_pulses

        decoder = NecDecoder()
        start = decoder._find_start_index(reference_pulses_no_end_low)

        assert not decoder._validate_pulses(reference_pulses_no_end_low, start)
    def test_no_pause(self):
        # Set the pause to a low time
        reference_pulses = TestNecDecoder.reference_pulses[:]
        reference_pulses[1] = 562.5
        reference_pulses_no_pause = reference_pulses

        decoder = NecDecoder()
        start = decoder._find_start_index(reference_pulses_no_pause)

        assert not decoder._validate_pulses(reference_pulses_no_pause, start)
    def test_convert_pulses_fast(self):
        pulses_fast = [
            pulse - pulse * TestNecDecoder.time_tolerance
            for pulse in TestNecDecoder.reference_pulses
        ]

        decoder = NecDecoder()
        start = decoder._find_start_index(TestNecDecoder.reference_pulses)

        assert TestNecDecoder.reference_bits == decoder._convert_pulses(
            pulses_fast, start)
    def test__find_start_index_fast(self):
        pulses_fast = [
            pulse - pulse * TestNecDecoder.time_tolerance
            for pulse in TestNecDecoder.reference_pulses
        ]

        decoder = NecDecoder()
        first_element_index = 0
        start = decoder._find_start_index(pulses_fast)

        assert start == first_element_index
    def test_convert_pulses_valid(self):
        decoder = NecDecoder()
        start = decoder._find_start_index(TestNecDecoder.reference_pulses)

        assert TestNecDecoder.reference_bits == decoder._convert_pulses(
            TestNecDecoder.reference_pulses, start)
    def test_valid_pulses(self):
        decoder = NecDecoder()
        start = decoder._find_start_index(TestNecDecoder.reference_pulses)
        decoder._classify_message(TestNecDecoder.reference_pulses, start)

        assert decoder._validate_pulses(TestNecDecoder.reference_pulses, start)
    def test__find_start_index_spec(self):
        decoder = NecDecoder()
        first_element_index = 0
        start = decoder._find_start_index(TestNecDecoder.reference_pulses)

        assert start == first_element_index