Example #1
0
async def test_control_event(faker):
    loop = asyncio.get_event_loop()
    listener = Listener()

    disp = Display(index=0)
    tally = Tally.from_display(disp)

    tally.bind_async(loop, on_control=listener.callback)

    for _ in range(100):
        data_len = faker.pyint(min_value=1, max_value=1024)
        control_data = faker.binary(length=data_len)

        disp = Display(index=0, control=control_data)
        tally.update_from_display(disp)

        _, rx_data = await listener.get()
        assert rx_data == tally.control == disp.control == control_data
        assert disp == tally == Tally.from_display(disp)
Example #2
0
def test_tally_display_conversion(faker):
    # i = 0
    # if True:
    for _ in range(100):
        i = faker.pyint(max_value=0xfffe)
        disp = Display(index=i)
        tally = Tally(i)
        for tally_type, color in iter_tally_types_and_colors():
            brightness = faker.pyint(max_value=3)
            # print(f'{i=}, {tally_type=}, {color=}')
            disp.brightness = brightness
            tally.brightness = brightness
            assert 0 <= tally.normalized_brightness <= 1
            assert tally.normalized_brightness == brightness / 3
            setattr(tally, tally_type.name, color)
            setattr(disp, tally_type.name, color)
            for word in faker.words(3):
                # print(f'{word=}')
                tally.text = word
                disp.text = word

                assert disp == Tally.from_display(disp) == tally
                assert disp == Display.from_tally(tally) == tally
                assert Tally.from_display(disp).normalized_brightness == tally.normalized_brightness
Example #3
0
async def test_control_event_with_text(faker):
    loop = asyncio.get_event_loop()

    text_listener = Listener()
    ctrl_listener = Listener()

    tally_text = 'foo'

    disp = Display(index=0, text=tally_text)
    tally = Tally.from_display(disp)

    assert disp == tally

    tally.bind_async(loop,
        on_update=text_listener.callback,
        on_control=ctrl_listener.callback,
    )

    for _ in range(100):
        for word in faker.words(3):
            data_len = faker.pyint(min_value=1, max_value=1024)
            control_data = faker.binary(length=data_len)

            disp = Display(index=0, control=control_data)
            tally.update_from_display(disp)

            _, rx_data = await ctrl_listener.get()
            assert rx_data == tally.control == disp.control == control_data
            assert tally.text == tally_text

            _, props_changed = await text_listener.get()
            assert set(props_changed) == set(['control'])

            tally_text=word
            disp = Display(index=0, text=tally_text)
            tally.update_from_display(disp)

            _, props_changed = await text_listener.get()
            assert set(props_changed) == set(['text'])

            assert tally.text == tally_text
            assert tally.control == control_data