1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-06 22:32:54 +02:00

add upower tests

This commit is contained in:
Kelly Brazil
2021-03-24 21:24:25 -07:00
parent 04745a36b8
commit e4ca0de92a
8 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1 @@
[{"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0", "vendor": "NOTEBOOK", "model": "BAT", "serial": "0001", "power_supply": true, "updated": "Thu Feb 9 18:42:15 2012", "has_history": true, "has_statistics": true, "detail": {"type": "battery", "present": true, "rechargeable": true, "state": "charging", "energy": 22.3998, "energy_empty": 0.0, "energy_full": 52.6473, "energy_full_design": 62.16, "energy_rate": 31.6905, "voltage": 12.191, "time_to_full": 57.3, "percentage": 42.5469, "capacity": 84.6964, "technology": "lithium-ion", "energy_unit": "Wh", "energy_empty_unit": "Wh", "energy_full_unit": "Wh", "energy_full_design_unit": "Wh", "energy_rate_unit": "W", "voltage_unit": "V", "time_to_full_unit": "minutes"}, "history_charge": [{"time": 1328809335, "percent_charged": 42.547, "status": "charging"}, {"time": 1328809305, "percent_charged": 42.02, "status": "charging"}, {"time": 1328809275, "percent_charged": 41.472, "status": "charging"}, {"time": 1328809245, "percent_charged": 41.008, "status": "charging"}], "history_rate": [{"time": 1328809335, "percent_charged": 31.691, "status": "charging"}, {"time": 1328809305, "percent_charged": 32.323, "status": "charging"}, {"time": 1328809275, "percent_charged": 33.133, "status": "charging"}], "updated_seconds_ago": 1, "updated_epoch": 1328841735, "updated_epoch_utc": null}]

View File

@ -0,0 +1 @@
[{"native_path": "BAT0", "vendor": "Samsung SDI", "model": "DELL 7XFJJA2", "serial": "4448", "power_supply": true, "updated": "Tuesday 01 October 2019 12:50:41 PM IST", "has_history": true, "has_statistics": true, "detail": {"type": "battery", "present": true, "rechargeable": true, "state": "fully-charged", "warning_level": null, "energy": 33.4443, "energy_empty": 0.0, "energy_full": 33.4443, "energy_full_design": 48.84, "energy_rate": 0.0111, "voltage": 12.446, "percentage": 100.0, "capacity": 68.4773, "technology": "lithium-ion", "icon_name": "battery-full-charged-symbolic", "energy_unit": "Wh", "energy_empty_unit": "Wh", "energy_full_unit": "Wh", "energy_full_design_unit": "Wh", "energy_rate_unit": "W", "voltage_unit": "V"}, "updated_seconds_ago": 101, "updated_epoch": 1569959441, "updated_epoch_utc": null}]

View File

@ -0,0 +1 @@
[{"native_path": "BAT0", "vendor": "Samsung SDI", "model": "DELL 7XFJJA2", "serial": "4448", "power_supply": true, "updated": "Tuesday 01 October 2019 12:50:41 PM UTC", "has_history": true, "has_statistics": true, "detail": {"type": "battery", "present": true, "rechargeable": true, "state": "fully-charged", "warning_level": null, "energy": 33.4443, "energy_empty": 0.0, "energy_full": 33.4443, "energy_full_design": 48.84, "energy_rate": 0.0111, "voltage": 12.446, "percentage": 100.0, "capacity": 68.4773, "technology": "lithium-ion", "icon_name": "battery-full-charged-symbolic", "energy_unit": "Wh", "energy_empty_unit": "Wh", "energy_full_unit": "Wh", "energy_full_design_unit": "Wh", "energy_rate_unit": "W", "voltage_unit": "V"}, "updated_seconds_ago": 101, "updated_epoch": 1569959441, "updated_epoch_utc": 1569934241}]

View File

@ -0,0 +1 @@
[{"type": "Device", "device_name": "/org/freedesktop/UPower/devices/line_power_ACAD", "native_path": "ACAD", "power_supply": true, "updated": "Thu Mar 11 18:28:08 2021", "has_history": false, "has_statistics": false, "detail": {"type": "line-power", "warning_level": null, "online": true, "icon_name": "ac-adapter-symbolic"}, "updated_seconds_ago": 538247, "updated_epoch": 1615516088, "updated_epoch_utc": null}, {"type": "Device", "device_name": "/org/freedesktop/UPower/devices/DisplayDevice", "power_supply": false, "updated": "Thu Mar 11 18:28:08 2021", "has_history": false, "has_statistics": false, "detail": {"type": "unknown", "warning_level": null, "icon_name": "battery-missing-symbolic"}, "updated_seconds_ago": 538247, "updated_epoch": 1615516088, "updated_epoch_utc": null}, {"type": "Daemon", "daemon_version": "0.99.7", "on_battery": false, "lid_is_closed": false, "lid_is_present": false, "critical_action": "HybridSleep"}]

View File

@ -0,0 +1 @@
[{"type": "Device", "device_name": "/org/freedesktop/UPower/devices/line_power_ACAD", "native_path": "ACAD", "power_supply": true, "updated": "Thu 11 Mar 2021 06:28:08 PM UTC", "has_history": false, "has_statistics": false, "detail": {"type": "line-power", "warning_level": null, "online": true, "icon_name": "ac-adapter-symbolic"}, "updated_seconds_ago": 441975, "updated_epoch": 1615516088, "updated_epoch_utc": 1615487288}, {"type": "Device", "device_name": "/org/freedesktop/UPower/devices/DisplayDevice", "power_supply": false, "updated": "Thu 11 Mar 2021 06:28:08 PM UTC", "has_history": false, "has_statistics": false, "detail": {"type": "unknown", "warning_level": null, "icon_name": "battery-missing-symbolic"}, "updated_seconds_ago": 441975, "updated_epoch": 1615516088, "updated_epoch_utc": 1615487288}, {"type": "Daemon", "daemon_version": "0.99.7", "on_battery": false, "lid_is_closed": false, "lid_is_present": false, "critical_action": "HybridSleep"}]

View File

@ -0,0 +1 @@
[{"native_path": "ACAD", "power_supply": true, "updated": "Thu 11 Mar 2021 06:28:08 PM UTC", "has_history": false, "has_statistics": false, "detail": {"type": "line-power", "warning_level": null, "online": true, "icon_name": "ac-adapter-symbolic"}, "updated_seconds_ago": 442049, "updated_epoch": 1615516088, "updated_epoch_utc": 1615487288}]

94
tests/test_upower.py Normal file
View File

@ -0,0 +1,94 @@
import os
import json
import unittest
import jc.parsers.upower
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
def setUp(self):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-i.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_upower_i = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_upower_d = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d-clocale.out'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_upower_d_clocale = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-utc.out'), 'r', encoding='utf-8') as f:
self.generic_upower_i_utc = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-non-utc.out'), 'r', encoding='utf-8') as f:
self.generic_upower_i_non_utc = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-c-locale.out'), 'r', encoding='utf-8') as f:
self.generic_upower_i_c_locale = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-i.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_upower_i_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_upower_d_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/upower-d-clocale.json'), 'r', encoding='utf-8') as f:
self.ubuntu_18_4_upower_d_clocale_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-utc.json'), 'r', encoding='utf-8') as f:
self.generic_upower_i_utc_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-non-utc.json'), 'r', encoding='utf-8') as f:
self.generic_upower_i_non_utc_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/upower-i-c-locale.json'), 'r', encoding='utf-8') as f:
self.generic_upower_i_c_locale_json = json.loads(f.read())
def test_upower_nodata(self):
"""
Test 'upower' with no data
"""
self.assertEqual(jc.parsers.upower.parse('', quiet=True), [])
def test_upower_i_ubuntu_18_4(self):
"""
Test 'upower -i' on Ubuntu 18.4
"""
self.assertEqual(jc.parsers.upower.parse(self.ubuntu_18_4_upower_i, quiet=True), self.ubuntu_18_4_upower_i_json)
def test_upower_d_ubuntu_18_4(self):
"""
Test 'upower -d' on Ubuntu 18.4 using LANG=en_US.UTF-8
"""
self.assertEqual(jc.parsers.upower.parse(self.ubuntu_18_4_upower_d, quiet=True), self.ubuntu_18_4_upower_d_json)
def test_upower_d_clocale_ubuntu_18_4(self):
"""
Test 'upower -d' on Ubuntu 18.4 using LANG=C
"""
self.assertEqual(jc.parsers.upower.parse(self.ubuntu_18_4_upower_d, quiet=True), self.ubuntu_18_4_upower_d_json)
def test_upower_i_utc_generic(self):
"""
Test 'upower -i' with utc time output
"""
self.assertEqual(jc.parsers.upower.parse(self.generic_upower_i_utc, quiet=True), self.generic_upower_i_utc_json)
def test_upower_i_non_utc_generic(self):
"""
Test 'upower -i' with non-utc time output
"""
self.assertEqual(jc.parsers.upower.parse(self.generic_upower_i_non_utc, quiet=True), self.generic_upower_i_non_utc_json)
def test_upower_i_c_locale(self):
"""
Test 'upower -i' with LANG=C time output
"""
self.assertEqual(jc.parsers.upower.parse(self.generic_upower_i_c_locale, quiet=True), self.generic_upower_i_c_locale_json)
if __name__ == '__main__':
unittest.main()