Update battery tests, add case for #66, fix #66

This commit is contained in:
enkore 2014-06-13 23:23:29 +02:00
parent 8f0ac4bdb6
commit 00c230f4f8
4 changed files with 30 additions and 8 deletions

View File

@ -49,16 +49,23 @@ class Battery:
return self._percentage("_DESIGN" if design else "") * 100
def status(self):
if self.consumption():
if self.consumption() > 0.1:
return "Discharging" if self.battery_info["STATUS"] == "Discharging" else "Charging"
else:
return "Full"
def consumption(self, val):
return val if val > 0.1 else 0
class BatteryCharge(Battery):
def __init__(self, bi):
bi["CHARGE_FULL"] = bi["CHARGE_FULL_DESIGN"] if bi["CHARGE_NOW"] > bi["CHARGE_FULL"] else bi["CHARGE_FULL"]
super().__init__(bi)
def consumption(self):
if "VOLTAGE_NOW" in self.battery_info and "CURRENT_NOW" in self.battery_info:
return self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"] # V * A = W
return super().consumption(self.battery_info["VOLTAGE_NOW"] * self.battery_info["CURRENT_NOW"]) # V * A = W
else:
return -1
@ -79,7 +86,7 @@ class BatteryCharge(Battery):
class BatteryEnergy(Battery):
def consumption(self):
return self.battery_info["POWER_NOW"]
return super().consumption(self.battery_info["POWER_NOW"])
def _percentage(self, design):
return self.battery_info["ENERGY_NOW"] / self.battery_info["ENERGY_FULL" + design]

View File

@ -3,7 +3,7 @@
from setuptools import setup
setup(name="i3pystatus",
version="3.29",
version="3.30",
description="Like i3status, this generates status line for i3bar / i3wm",
url="http://github.com/enkore/i3pystatus",
license="MIT",

8
tests/test_battery.py Executable file → Normal file
View File

@ -9,7 +9,6 @@ def factory(path, format, expected):
def test():
bc = battery.BatteryChecker(path=path, format=format)
bc.run()
print(bc.output["full_text"])
assert bc.output["full_text"] == expected
test.description = path + ":" + format
return test
@ -17,15 +16,16 @@ def factory(path, format, expected):
def basic_test_generator():
cases = [
("test_battery_basic1", "FULL", "0.000", ""),
("test_battery_basic2", "FULL", "0.000", ""),
("test_battery_basic1", "FULL", "0.000", "0h:00m"),
("test_battery_basic2", "FULL", "0.000", "0h:00m"),
("test_battery_basic3", "DIS", "15.624", "4h:04m"),
("test_battery_basic4", "DIS", "17.510", "1h:46m"),
("test_battery_basic5", "DIS", "11.453", "4h:52m"),
("test_battery_basic6", "CHR", "30.764", "0h:20m"),
("test_battery_basic7", "DIS", "27.303", "1h:44m"),
("test_battery_broken1", "FULL", "0.000", "0h:00m"),
]
for path, status, consumption, remaining in cases:
yield factory(path, "{status}", status)
yield factory(path, "{consumption:.3f}", consumption)
yield factory(path, "{remaining_hm}", remaining)
yield factory(path, "{remaining:%hh:%Mm}", remaining)

View File

@ -0,0 +1,15 @@
POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_STATUS=Full
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000
POWER_SUPPLY_VOLTAGE_NOW=12532000
POWER_SUPPLY_CURRENT_NOW=1000
POWER_SUPPLY_CHARGE_FULL_DESIGN=5600000
POWER_SUPPLY_CHARGE_FULL=1187000
POWER_SUPPLY_CHARGE_NOW=5600000
POWER_SUPPLY_CAPACITY=471
POWER_SUPPLY_MODEL_NAME=DELL H139107
POWER_SUPPLY_MANUFACTURER=Samsung SDI
POWER_SUPPLY_SERIAL_NUMBER=13685