Example #1
0
def fixture_useful_screens(monkeypatch, mocker):
    def mock_get_randr_screens(*args, **kwargs):
        return {"DVI-I-0": (1920, 1080, 50, 60)}

    monkeypatch.setattr(barython.panel, "get_randr_screens",
                        mock_get_randr_screens)
    monkeypatch.setattr(barython.screen, "get_randr_screens",
                        mock_get_randr_screens)

    disable_spawn_bar(Panel)
    p = Panel(keep_unplugged_screens=False)
    disable_spawn_bar(Screen)
    s0, s1 = Screen("DVI-I-0"), Screen("DVI-I-1")

    for i in (p, s0, s1):
        mocker.spy(i, "start")
        mocker.spy(i, "init_bar")
        mocker.spy(i, "_write_in_bar")

    w = TextWidget(text="test")
    s0.add_widget("l", w)
    s1.add_widget("l", w)

    p.add_screen(s0, s1)
    return p, s0, s1
Example #2
0
def test_screen_gather():
    p = Panel(keep_unplugged_screens=True)
    s = Screen()
    p.add_screen(s)
    w = TextWidget(text="test")
    s.add_widget("l", w)
    w.update()

    content = s.gather()
    assert content == "%{l}test"
Example #3
0
def test_pannel_global_instance_add_screen():
    """
    Test to add a screen to a panel
    """
    p = Panel(instance_per_screen=False, keep_unplugged_screens=True)
    assert len(p.screens) == 0

    s = Screen()
    p.add_screen(s)
    assert p.screens[0] == s
Example #4
0
def test_pannel_add_screen():
    """
    Test to add a screen to a panel
    """
    p = Panel(keep_unplugged_screens=True)
    assert len(p._screens) == 0

    s = Screen()
    p.add_screen(s)
    assert p._screens[0] == s
Example #5
0
def test_panel_gather_one_screen():
    p = Panel(instance_per_screen=False, keep_unplugged_screens=True)
    w = TextWidget(text="test")

    s = Screen()
    p.add_screen(s)
    s.add_widget("l", w)
    w.update()

    assert p.gather() == "%{l}test"
Example #6
0
def test_base_hooks_with_panel(mocker):
    callback0, callback1 = mocker.stub(), mocker.stub()
    p = Panel(keep_unplugged_screens=True)
    s = Screen()
    w0, w1 = Widget(), Widget()
    w0.hooks.subscribe(callback0, _Hook)
    w1.hooks.subscribe(callback1, _Hook)

    s.add_widget("l", w0, w1)
    p.add_screen(s)

    assert p.hooks.hooks[_Hook][0].callbacks == {callback0, callback1}
Example #7
0
def test_battery_widget_update(one_battery_dir):
    BAT_NAME = "BAT0"
    bw = BatteryWidget()
    infos = bw.read_battery_infos(BAT_NAME)
    organized_result = bw.organize_result(**{BAT_NAME: infos})

    p = Panel(instance_per_screen=False, keep_unplugged_screens=True)
    s = Screen("HDMI-0")
    s.add_widget("l", bw)
    p.add_screen(s)
    bw.update()

    assert bw._content == organized_result
Example #8
0
def test_pannel_add_screen_insert():
    """
    Test the screen insertion in a panel, with multiple screens at a time
    """
    p = Panel(keep_unplugged_screens=True)
    s = Screen()
    s1 = Screen()
    s2 = Screen()

    p.add_screen(s, s2)
    p.add_screen(s1, index=1)

    assert len(p.screens) == 3
    for screen, pscreen in zip((s, s1, s2), p._screens):
        assert screen == pscreen
Example #9
0
def test_panel_clean_screens_instance_per_screen(monkeypatch):
    def mock_get_randr_screens(*args, **kwargs):
        return {"DVI-I-0": (1920, 1080, 50, 60)}

    monkeypatch.setattr(barython.panel, "get_randr_screens",
                        mock_get_randr_screens)
    monkeypatch.setattr(barython.screen, "get_randr_screens",
                        mock_get_randr_screens)

    p = Panel(instance_per_screen=True, keep_unplugged_screens=False)
    s0, s1 = Screen("DVI-I-0"), Screen("DVI-I-1")
    w = TextWidget(text="test")
    s0.add_widget("l", w)
    s1.add_widget("l", w)
    p.add_screen(s0, s1)

    assert tuple(p.clean_screens()) == (s0, )
Example #10
0
def test_screen_gather_multiple_widgets():
    """
    Test the gather function with more than one widget
    """
    p = Panel(keep_unplugged_screens=True)
    s = Screen()
    p.add_screen(s)
    w = TextWidget(text="test")
    w1 = TextWidget(text="test1")
    s.add_widget("l", w, w1)
    w.update()
    w1.update()

    s.add_widget("r", w, w1)
    s.add_widget("c", w, w1)

    content = s.gather()
    assert content == "%{l}testtest1%{c}testtest1%{r}testtest1"
Example #11
0
def test_base_lock_update(mocker):
    """
    Test that only one update is running at a time by widget
    """
    disable_spawn_bar(Panel)
    p = Panel(instance_per_screen=False, keep_unplugged_screens=True)
    w = SubprocessWidget(cmd="echo Test", refresh=0.2)
    for i in range(0, 4):
        s = Screen()
        s.add_widget("l", w)
        p.add_screen(s)
    mocker.spy(w, "continuous_update")

    try:
        threading.Thread(target=p.start).start()
        time.sleep(0.3)
        assert w.continuous_update.call_count == 1
    finally:
        p.stop()
Example #12
0
def test_panel_gather_no_screen(fixture_useful_screens):
    p = Panel(instance_per_screen=False, keep_unplugged_screens=True)
    disable_spawn_bar(p)
    p.gather()
    try:
        threading.Thread(target=p.start).start()
        time.sleep(0.1)
        assert p.gather() == ""
    finally:
        p.stop()