Ejemplo n.º 1
0
def test_clock_datetime_timezone(fake_qtile, monkeypatch):
    """ test clock with datetime timezone """
    class FakeDateutilTZ:
        class TZ:
            @classmethod
            def gettz(cls, val):
                None

        tz = TZ

    # Set up references to pytz and dateutil so we know these aren't being used
    # If they're called, the widget would try to run None(self.timezone) which
    # would raise an exception
    clock.pytz = None
    clock.dateutil = FakeDateutilTZ

    # Fake datetime module just adds the timezone value to the time
    clk3 = clock.Clock(timezone=1)

    fakebar = Bar([clk3], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    clk3._configure(fake_qtile, fakebar)
    text = clk3.poll()

    # Default time is 10:20 and we add 1 hour for the timezone
    assert text == "11:20"
Ejemplo n.º 2
0
def test_clock_invalid_timezone(fake_qtile, monkeypatch):
    """ test clock widget with invalid timezone (and no pytz or dateutil modules) """
    class FakeDateutilTZ:
        @classmethod
        def tz(cls):
            return cls

        @classmethod
        def gettz(cls, val):
            return None

    # pytz and dateutil must not be in the sys.modules dict...
    monkeypatch.delitem(sys.modules, "pytz")
    monkeypatch.delitem(sys.modules, "dateutil")

    # Set up references to pytz and dateutil so we know these aren't being used
    # If they're called, the widget would try to run None(self.timezone) which
    # would raise an exception
    clock.pytz = None
    clock.dateutil = FakeDateutilTZ

    # Fake datetime module just adds the timezone value to the time
    clk2 = clock.Clock(timezone="1")

    fakebar = Bar([clk2], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    clk2._configure(fake_qtile, fakebar)

    # An invalid timezone current causes a TypeError
    with pytest.raises(TypeError):
        clk2.poll()
Ejemplo n.º 3
0
def test_keyboard_kbdd_colours(fake_qtile, patched_widget, fake_window):
    MockSpawn.call_count = 1
    kbd = patched_widget.KeyboardKbdd(configured_keyboards=["gb", "us"],
                                      colours=["#ff0000", "#00ff00"])
    fakebar = Bar([kbd], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    kbd._configure(fake_qtile, fakebar)

    # Create a message with the index of the active keyboard
    message = MockMessage(body=0)
    kbd._signal_received(message)
    assert kbd.layout.colour == "#ff0000"

    # Create a message with the index of the active keyboard
    message = MockMessage(body=1)
    kbd._signal_received(message)
    assert kbd.layout.colour == "#00ff00"

    # No change where self.colours is a string
    kbd.colours = "#ffff00"
    kbd._set_colour(1)
    assert kbd.layout.colour == "#00ff00"

    # Colours list is shorter than length of layouts
    kbd.colours = ["#ff00ff"]

    # Should pick second item in colours list but it doesn't exit
    # so widget looks for previous item
    kbd._set_colour(1)
    assert kbd.layout.colour == "#ff00ff"
Ejemplo n.º 4
0
def test_widgetbox_widget(manager):
    manager.conn = xcbq.Connection(manager.display)

    # We need to trick the widgets into thinking this is libqtile.qtile so
    # we add some methods that are called when the widgets are configured
    manager.call_soon = no_op
    manager.register_widget = no_op

    tb_one = TextBox(name="tb_one", text="TB ONE")
    tb_two = TextBox(name="tb_two", text="TB TWO")

    # Give widgetbox invalid value for button location
    widget_box = WidgetBox([tb_one, tb_two],
                           close_button_location="middle",
                           fontsize=10)

    # Create a bar and set attributes needed to run widget
    fakebar = Bar([widget_box], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op

    # Configure the widget box
    widget_box._configure(manager, fakebar)

    # Invalid value should be corrected to default
    assert widget_box.close_button_location == "left"

    # Check only widget in bar is widgetbox
    assert fakebar.widgets == [widget_box]

    # Open box
    widget_box.cmd_toggle()

    # Check it's open
    assert widget_box.box_is_open

    # Default text position is left
    assert fakebar.widgets == [widget_box, tb_one, tb_two]

    # Close box
    widget_box.cmd_toggle()

    # Check it's closed
    assert not widget_box.box_is_open

    # Check widgets have been removed
    assert fakebar.widgets == [widget_box]

    # Move button to right-hand side
    widget_box.close_button_location = "right"

    # Re-open box with new layout
    widget_box.cmd_toggle()

    # Now widgetbox is on the right
    assert fakebar.widgets == [tb_one, tb_two, widget_box]
Ejemplo n.º 5
0
def test_imapwidget(fake_qtile, monkeypatch, fake_window, patched_imap):
    imap = patched_imap.ImapWidget(user="******")
    fakebar = Bar([imap], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    imap._configure(fake_qtile, fakebar)
    text = imap.poll()
    assert text == "INBOX: 2"
Ejemplo n.º 6
0
def test_no_update_available_without_no_update_string(fake_qtile):
    """ test output with no update (without dedicated string nor color) """
    cu3 = CheckUpdates(distro=good_distro, custom_command=cmd_0_line)
    fakebar = Bar([cu3], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    cu3._configure(fake_qtile, fakebar)
    text = cu3.poll()
    assert text == ""
Ejemplo n.º 7
0
def test_clock(fake_qtile, monkeypatch):
    """ test clock output with default settings """
    monkeypatch.setattr("libqtile.widget.clock.datetime", MockDatetime)
    clk1 = clock.Clock()
    fakebar = Bar([clk1], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    clk1._configure(fake_qtile, fakebar)
    text = clk1.poll()
    assert text == "10:20"
Ejemplo n.º 8
0
def test_imapwidget_keyring_error(fake_qtile, monkeypatch, fake_window,
                                  patched_imap):
    patched_imap.keyring.valid = False
    imap = patched_imap.ImapWidget(user="******")
    fakebar = Bar([imap], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    imap._configure(fake_qtile, fakebar)
    text = imap.poll()
    assert text == "Gnome Keyring Error"
Ejemplo n.º 9
0
def test_widgetbox_widget(fake_qtile, fake_window):

    tb_one = TextBox(name="tb_one", text="TB ONE")
    tb_two = TextBox(name="tb_two", text="TB TWO")

    # Give widgetbox invalid value for button location
    widget_box = WidgetBox([tb_one, tb_two],
                           close_button_location="middle",
                           fontsize=10)

    # Create a bar and set attributes needed to run widget
    fakebar = Bar([widget_box], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op

    # Configure the widget box
    widget_box._configure(fake_qtile, fakebar)

    # Invalid value should be corrected to default
    assert widget_box.close_button_location == "left"

    # Check only widget in bar is widgetbox
    assert fakebar.widgets == [widget_box]

    # Open box
    widget_box.cmd_toggle()

    # Check it's open
    assert widget_box.box_is_open

    # Default text position is left
    assert fakebar.widgets == [widget_box, tb_one, tb_two]

    # Close box
    widget_box.cmd_toggle()

    # Check it's closed
    assert not widget_box.box_is_open

    # Check widgets have been removed
    assert fakebar.widgets == [widget_box]

    # Move button to right-hand side
    widget_box.close_button_location = "right"

    # Re-open box with new layout
    widget_box.cmd_toggle()

    # Now widgetbox is on the right
    assert fakebar.widgets == [tb_one, tb_two, widget_box]
Ejemplo n.º 10
0
def test_gmail_checker_invalid_response(fake_qtile, monkeypatch, fake_window):
    monkeypatch.setitem(sys.modules, "imaplib", FakeIMAP("imaplib"))
    reload(gmail_checker)

    gmc = gmail_checker.GmailChecker()
    fakebar = Bar([gmc], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    gmc._configure(fake_qtile, fakebar)
    text = gmc.poll()
    assert text == "UNKNOWN ERROR"
Ejemplo n.º 11
0
def test_gmail_checker_valid_response(fake_qtile, monkeypatch, fake_window):
    monkeypatch.setitem(sys.modules, "imaplib", FakeIMAP("imaplib"))
    reload(gmail_checker)

    gmc = gmail_checker.GmailChecker(username="******", password="******")
    fakebar = Bar([gmc], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    gmc._configure(fake_qtile, fakebar)
    text = gmc.poll()
    assert text == "inbox[10],unseen[2]"
Ejemplo n.º 12
0
def test_mpris2_no_metadata(fake_qtile, patched_module, fake_window):
    mp = patched_module.Mpris2(stop_pause_text="Test Paused")
    fakebar = Bar([mp], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    fake_qtile.call_later = no_op
    mp._configure(fake_qtile, fakebar)
    mp.configured = True

    mp.message(STATUS_PLAYING)
    assert mp.displaytext == "No metadata for current track"
Ejemplo n.º 13
0
def patched_moc(fake_qtile, monkeypatch, fake_window):
    widget = moc.Moc()
    MockMocpProcess.reset()
    monkeypatch.setattr(widget, "call_process", MockMocpProcess.run)
    monkeypatch.setattr("libqtile.widget.moc.subprocess.Popen",
                        MockMocpProcess.run)
    fakebar = Bar([widget], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    widget._configure(fake_qtile, fakebar)
    return widget
Ejemplo n.º 14
0
def test_cmus_error_handling(fake_qtile, patched_cmus):
    widget = patched_cmus.Cmus()
    MockCmusRemoteProcess.is_error = True
    fakebar = Bar([widget], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    widget._configure(fake_qtile, fakebar)
    text = widget.poll()

    # Widget does nothing with error message so text is blank
    # TODO: update widget to show error?
    assert text == ""
Ejemplo n.º 15
0
def test_imapwidget(fake_qtile, monkeypatch):
    monkeypatch.setitem(sys.modules, "imaplib", FakeIMAP("imaplib"))
    monkeypatch.setitem(sys.modules, "keyring", FakeKeyring("keyring"))
    from libqtile.widget import imapwidget

    imap = imapwidget.ImapWidget(user="******")
    fakebar = Bar([imap], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    imap._configure(fake_qtile, fakebar)
    text = imap.poll()
    assert text == "INBOX: 2"
Ejemplo n.º 16
0
def test_df_no_warning(fake_qtile):
    ''' Test no text when free space over threshold '''
    df1 = df.DF()
    fakebar = Bar([df1], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    df1._configure(fake_qtile, fakebar)
    text = df1.poll()
    assert text == ""

    df1.draw()
    assert df1.layout.colour == df1.foreground
Ejemplo n.º 17
0
def test_update_process_error(fake_qtile):
    """ test output where update check gives error"""
    cu7 = CheckUpdates(distro=good_distro,
                       custom_command=cmd_error,
                       no_update_string="ERROR",
                       )
    fakebar = Bar([cu7], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    cu7._configure(fake_qtile, fakebar)
    text = cu7.poll()
    assert text == "ERROR"
Ejemplo n.º 18
0
def test_update_available(fake_qtile, fake_window):
    """ test output with update (check number of updates and color) """
    cu2 = CheckUpdates(distro=good_distro,
                       custom_command=cmd_1_line,
                       colour_have_updates="#123456")
    fakebar = Bar([cu2], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    cu2._configure(fake_qtile, fakebar)
    text = cu2.poll()
    assert text == "Updates: 1"
    assert cu2.layout.colour == cu2.colour_have_updates
Ejemplo n.º 19
0
def test_imapwidget_keyring_error(fake_qtile, monkeypatch, fake_window):
    monkeypatch.setitem(sys.modules, "imaplib", FakeIMAP("imaplib"))
    monkeypatch.setitem(sys.modules, "keyring", FakeKeyring("keyring"))
    from libqtile.widget import imapwidget
    imapwidget.keyring.valid = False

    imap = imapwidget.ImapWidget(user="******")
    fakebar = Bar([imap], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    imap._configure(fake_qtile, fakebar)
    text = imap.poll()
    assert text == "Gnome Keyring Error"
Ejemplo n.º 20
0
def test_update_available_with_restart_indicator(monkeypatch, fake_qtile):
    """ test output with no indicator where restart needed """
    cu5 = CheckUpdates(distro=good_distro,
                       custom_command=cmd_1_line,
                       restart_indicator="*",
                       )
    monkeypatch.setattr("os.path.exists", lambda x: True)
    fakebar = Bar([cu5], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    cu5._configure(fake_qtile, fakebar)
    text = cu5.poll()
    assert text == "Updates: 1*"
Ejemplo n.º 21
0
def test_escape_text(fake_qtile, patched_cmus, fake_window):
    widget = patched_cmus.Cmus()

    # Set track to a stopped item
    MockCmusRemoteProcess.index = 3
    fakebar = Bar([widget], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    widget._configure(fake_qtile, fakebar)
    text = widget.poll()

    # It's stopped so colour should reflect this
    assert text == "♫ Above & Beyond - Always - Tinlicker Extended Mix"
Ejemplo n.º 22
0
def test_imapwidget_password_none(fake_qtile, monkeypatch, fake_window,
                                  patched_imap):
    patched_imap.keyring.valid = False
    patched_imap.keyring.error = False

    imap = patched_imap.ImapWidget(user="******")
    fakebar = Bar([imap], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    imap._configure(fake_qtile, fakebar)
    with pytest.raises(AttributeError):
        with pytest.raises(UnboundLocalError):
            imap.poll()
Ejemplo n.º 23
0
    def build_widget(**kwargs):
        monkeypatch.setitem(sys.modules, "psutil", MockPsutil("psutil"))
        from libqtile.widget import net

        # Reload fixes cases where psutil may have been imported previously
        reload(net)
        widget = net.Net(**kwargs)
        fakebar = Bar([widget], 24)
        fakebar.window = fake_window
        fakebar.width = 10
        fakebar.height = 10
        fakebar.draw = no_op
        widget._configure(fake_qtile, fakebar)

        return widget
Ejemplo n.º 24
0
def test_df_always_visible(fake_qtile):
    ''' Test text is always displayed '''
    df2 = df.DF(visible_on_warn=False)
    fakebar = Bar([df2], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    df2._configure(fake_qtile, fakebar)
    text = df2.poll()

    # See values above
    assert text == "/ (38G|83%)"

    df2.draw()
    assert df2.layout.colour == df2.foreground
Ejemplo n.º 25
0
def test_no_update_available_with_no_update_string_and_color_no_updates(fake_qtile):
    """ test output with no update (with dedicated string and color) """
    cu4 = CheckUpdates(distro=good_distro,
                       custom_command=cmd_0_line,
                       no_update_string=nus,
                       colour_no_updates="#654321"
                       )
    fakebar = Bar([cu4], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    cu4._configure(fake_qtile, fakebar)
    text = cu4.poll()
    assert text == nus
    assert cu4.layout.colour == cu4.colour_no_updates
Ejemplo n.º 26
0
def test_gmail_checker_only_unseen(fake_qtile, monkeypatch, fake_window):
    monkeypatch.setitem(sys.modules, "imaplib", FakeIMAP("imaplib"))
    reload(gmail_checker)

    gmc = gmail_checker.GmailChecker(display_fmt="unseen[{0}]",
                                     status_only_unseen=True,
                                     username="******",
                                     password="******")
    fakebar = Bar([gmc], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    gmc._configure(fake_qtile, fakebar)
    text = gmc.poll()
    assert text == "unseen[2]"
Ejemplo n.º 27
0
def test_cmus(fake_qtile, patched_cmus):
    widget = patched_cmus.Cmus()
    fakebar = Bar([widget], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    widget._configure(fake_qtile, fakebar)
    text = widget.poll()
    assert text == "♫ Rick Astley - Never Gonna Give You Up"
    assert widget.layout.colour == widget.play_color

    widget.play()
    text = widget.poll()
    assert text == "♫ Rick Astley - Never Gonna Give You Up"
    assert widget.layout.colour == widget.noplay_color
Ejemplo n.º 28
0
def test_keyboardkbdd_process_not_running(fake_qtile, patched_widget):
    MockSpawn.call_count = 0
    kbd = patched_widget.KeyboardKbdd(configured_keyboards=["gb", "us"])
    fakebar = Bar([kbd], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    kbd._configure(fake_qtile, fakebar)
    assert not kbd.is_kbdd_running
    assert kbd.keyboard == "N/A"

    # Second call of _check_kbdd will confirm process running
    # so widget should now show layout
    kbd.poll()
    assert kbd.keyboard == "gb"
Ejemplo n.º 29
0
def test_imapwidget_password_none(fake_qtile, monkeypatch):
    monkeypatch.setitem(sys.modules, "imaplib", FakeIMAP("imaplib"))
    monkeypatch.setitem(sys.modules, "keyring", FakeKeyring("keyring"))
    from libqtile.widget import imapwidget
    imapwidget.keyring.valid = False
    imapwidget.keyring.error = False

    imap = imapwidget.ImapWidget(user="******")
    fakebar = Bar([imap], 24)
    fakebar.window = FakeWindow()
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    imap._configure(fake_qtile, fakebar)
    with pytest.raises(AttributeError):
        with pytest.raises(UnboundLocalError):
            imap.poll()
Ejemplo n.º 30
0
def test_mpris2_no_scroll(fake_qtile, patched_module, fake_window):
    # If no scrolling, then the update function creates the text to display
    # and draws the bar.
    mp = patched_module.Mpris2(scroll_chars=None)
    fakebar = Bar([mp], 24)
    fakebar.window = fake_window
    fakebar.width = 10
    fakebar.height = 10
    fakebar.draw = no_op
    fake_qtile.call_later = no_op
    mp._configure(fake_qtile, fakebar)
    mp.configured = True

    mp.message(METADATA_PLAYING)
    assert mp.text == "Never Gonna Give You Up - Whenever You Need Somebody - Rick Astley"

    mp.message(METADATA_PAUSED)
    assert mp.text == "Paused: Never Gonna Give You Up - Whenever You Need Somebody - Rick Astley"