def test_text_battery_error(monkeypatch): with monkeypatch.context() as m: m.setattr(battery, "load_battery", DummyErrorBattery) batt = Battery() text = batt.poll() assert text == "Error: err"
def test_text_battery_empty(monkeypatch): loaded_bat = BatteryStatus( state=BatteryState.EMPTY, percent=0.5, power=15., time=1729, ) with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery() text = batt.poll() assert text == "Empty" with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery(show_short_text=False) text = batt.poll() assert text == "x 50% 0:28 15.00 W" loaded_bat = BatteryStatus( state=BatteryState.UNKNOWN, percent=0., power=15., time=1729, ) with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery() text = batt.poll() assert text == "Empty"
def test_text_battery_discharging(monkeypatch): loaded_bat = BatteryStatus( state=BatteryState.DISCHARGING, percent=0.5, power=15., time=1729, ) with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery() text = batt.poll() assert text == "V 50% 0:28 15.00 W"
def test_text_battery_unknown(monkeypatch): loaded_bat = BatteryStatus( state=BatteryState.UNKNOWN, percent=0.5, power=15., time=1729, ) with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery() text = batt.poll() assert text == "? 50% 0:28 15.00 W"
def test_battery_background(fake_qtile, fake_window, monkeypatch): ok = BatteryStatus( state=BatteryState.DISCHARGING, percent=0.5, power=15.0, time=1729, ) low = BatteryStatus( state=BatteryState.DISCHARGING, percent=0.1, power=15.0, time=1729, ) low_background = "ff0000" background = "000000" with monkeypatch.context() as manager: manager.setattr(battery, "load_battery", dummy_load_battery(ok)) batt = Battery(low_percentage=0.2, low_background=low_background, background=background) fakebar = FakeBar([batt], window=fake_window) batt._configure(fake_qtile, fakebar) assert batt.background == background batt._battery._status = low batt.poll() assert batt.background == low_background batt._battery._status = ok batt.poll() assert batt.background == background
def widget_battery(self) -> list[_Widget]: """Widget for displaying battery usage. Returns ------- list[libqtile.widget.base._Widget] The list of widgets to add to the bar. """ # Widget for icon battery config = dict( **self.fonts["Icons2"], # Formatting options format="{char}", show_short_text=False, padding=4, # Icons for each state charge_char="", full_char="", empty_char="", discharge_char="", unknown_char="", # Other options update_interval=1, low_percentage=0.15, low_foreground=self.colors["orange"], foreground=self.colors["orange"], background=self.colors["background"], ) w_battery_icon = Battery(**config) # Widget for the percentage of the battery w_battery_text = Battery( **self.fonts["Normal"], # Formatting options format="{percent:2.0%} ", show_short_text=False, padding=0, # Other options update_interval=config["update_interval"], low_percentage=config["low_percentage"], low_foreground=config["foreground"], foreground=config["foreground"], background=config["background"], ) widgets: list[_Widget] = [w_battery_icon, w_battery_text] return widgets
def test_text_battery_full(monkeypatch): loaded_bat = BatteryStatus( state=BatteryState.FULL, percent=0.5, power=15., time=1729, ) with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery() text = batt.poll() assert text == "Full" with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery(show_short_text=False) text = batt.poll() assert text == "= 50% 0:28 15.00 W"
def test_text_battery_hidden(monkeypatch): loaded_bat = BatteryStatus( state=BatteryState.DISCHARGING, percent=0.5, power=15., time=1729, ) with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery(hide_threshold=0.6) text = batt.poll() assert text != "" with monkeypatch.context() as m: m.setattr(battery, "load_battery", dummy_load_battery(loaded_bat)) batt = Battery(hide_threshold=0.4) text = batt.poll() assert text == ""