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_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 #4
0
def test_screen_add_widget_bad_alignment():
    """
    Test to add a widget in different alignments
    """
    s = Screen()
    w = Widget()

    with pytest.raises(ValueError):
        s.add_widget(w)

    with pytest.raises(ValueError):
        s.add_widget("v", w)
Example #5
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 #6
0
def test_bspwm_desktop_pool_widget_actions_desktop_different_screen(
        basic_bspwm_desktop_pool_widget):
    """
    Test action for a focused desktop on different screen
    """
    bspwm = basic_bspwm_desktop_pool_widget
    # simulate the focus on the desktop d of monitor HDMI-0
    bspwm._focused["HDMI-0"] = "d"

    s = Screen("HDMI-0")
    s.add_widget("l", bspwm)
    expected = {1: "bspc desktop \"q\" -s \"d\""}
    assert expected == bspwm._actions_desktop("q", "HDMI-1")
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_screen_add_widget_insert():
    """
    Test to add widget before specified index
    """
    s = Screen()
    w = Widget()
    s.add_widget("l", w)

    w1 = Widget()
    w2 = Widget()
    s.add_widget("l", w1, w2, index=0)

    assert s._widgets["l"][0] == w1
    assert s._widgets["l"][1] == w2
Example #9
0
def test_screen_refresh():
    """
    Test if a Screen object get the refresh of its panel if not set
    """
    s = Screen(refresh=-1)
    assert s.refresh == -1

    s.refresh = 1
    assert s.refresh == 1

    p = Panel(refresh=2, keep_unplugged_screens=True)
    s.refresh = -1
    s.panel = p
    assert s.refresh == p.refresh
    assert s.refresh == 2
Example #10
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 #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_screen_add_widget():
    """
    Test to add a widget in different alignments
    """
    s = Screen()

    w = Widget()
    s.add_widget("l", w)
    assert s._widgets["l"][0] == w

    w = Widget()
    s.add_widget("c", w)
    assert s._widgets["c"][0] == w

    w = Widget()
    s.add_widget("r", w)
    assert s._widgets["r"][0] == w

    assert len(w.screens) == 1
    assert next(iter(w.screens)) == s
Example #13
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"