mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-21 00:19:42 +02:00
add acpi tests
This commit is contained in:
1
tests/fixtures/generic/acpi-V.json
vendored
Normal file
1
tests/fixtures/generic/acpi-V.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"type": "Battery", "id": 0, "state": "Charging", "charge_percent": 71, "until_charged": "00:29:20", "design_capacity_mah": 2110, "last_full_capacity": 2271, "last_full_capacity_percent": 100}, {"type": "Battery", "id": 1, "state": "Discharging", "charge_percent": 98, "charge_remaining": "01:43:14", "design_capacity_mah": 4400, "last_full_capacity": 3013, "last_full_capacity_percent": 68}, {"type": "Battery", "id": 2, "state": "Discharging", "charge_percent": 0}, {"type": "Battery", "id": 3, "state": "Full", "charge_percent": 100}, {"type": "Adapter", "id": 0, "on-line": true}, {"type": "Adapter", "id": 1, "on-line": false}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 46.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 127.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 127.0, "temperature_unit": "C"}]}, {"type": "Thermal", "id": 1, "mode": "ok", "temperature": 55.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 130.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 100.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 1, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 2, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 3, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 4, "messages": ["intel_powerclamp no state information available", "another message"]}, {"type": "Cooling", "id": 5, "messages": ["Processor 0 of 10"]}]
|
1
tests/fixtures/generic/acpi-V2.json
vendored
Normal file
1
tests/fixtures/generic/acpi-V2.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"type": "Battery", "id": 0, "state": "Charging", "charge_percent": 71, "until_charged": "00:29:20", "design_capacity_mah": 2110, "last_full_capacity": 2271, "last_full_capacity_percent": 100}, {"type": "Adapter", "id": 0, "on-line": true}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 46.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 127.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 127.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 1, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 2, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 3, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 4, "messages": ["intel_powerclamp no state information available"]}, {"type": "Cooling", "id": 5, "messages": ["Processor 0 of 10"]}]
|
1
tests/fixtures/generic/acpi-V3.json
vendored
Normal file
1
tests/fixtures/generic/acpi-V3.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"type": "Battery", "id": 0, "state": "Discharging", "charge_percent": 98, "charge_remaining": "01:43:14", "design_capacity_mah": 4400, "last_full_capacity": 3013, "last_full_capacity_percent": 68}, {"type": "Battery", "id": 1, "state": "Discharging", "charge_percent": 0}, {"type": "Adapter", "id": 0, "on-line": false}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 60.5, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 84.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 3"]}, {"type": "Cooling", "id": 1, "messages": ["intel_powerclamp no state information available"]}, {"type": "Cooling", "id": 2, "messages": ["Processor 0 of 3"]}, {"type": "Cooling", "id": 3, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 4, "messages": ["Processor 0 of 3"]}, {"type": "Cooling", "id": 5, "messages": ["LCD 0 of 15"]}, {"type": "Cooling", "id": 6, "messages": ["Processor 0 of 3"]}]
|
1
tests/fixtures/generic/acpi-V4.json
vendored
Normal file
1
tests/fixtures/generic/acpi-V4.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"type": "Battery", "id": 0, "state": "Full", "charge_percent": 100, "design_capacity_mah": 1969, "last_full_capacity": 2118, "last_full_capacity_percent": 100}, {"type": "Adapter", "id": 0, "on-line": true}, {"type": "Thermal", "id": 0, "mode": "ok", "temperature": 45.0, "temperature_unit": "C", "trip_points": [{"id": 0, "switches_to_mode": "critical", "temperature": 127.0, "temperature_unit": "C"}, {"id": 1, "switches_to_mode": "hot", "temperature": 127.0, "temperature_unit": "C"}]}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 1, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 2, "messages": ["x86_pkg_temp no state information available"]}, {"type": "Cooling", "id": 3, "messages": ["Processor 0 of 10"]}, {"type": "Cooling", "id": 4, "messages": ["intel_powerclamp no state information available"]}, {"type": "Cooling", "id": 5, "messages": ["Processor 0 of 10"]}]
|
1
tests/fixtures/ubuntu-18.04/acpi-V.json
vendored
Normal file
1
tests/fixtures/ubuntu-18.04/acpi-V.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"type": "Adapter", "id": 0, "on-line": true}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 7"]}]
|
82
tests/test_acpi.py
Normal file
82
tests/test_acpi.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import json
|
||||||
|
import jc.parsers.acpi
|
||||||
|
|
||||||
|
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/generic/acpi-V.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V2.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V2 = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V3.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V3 = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V4.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V4 = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/acpi-V.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.ubuntu_18_04_acpi_V = f.read()
|
||||||
|
|
||||||
|
# output
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V2.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V2_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V3.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V3_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V4.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_acpi_V4_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-18.04/acpi-V.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.ubuntu_18_04_acpi_V_json = json.loads(f.read())
|
||||||
|
|
||||||
|
def test_acpi_nodata(self):
|
||||||
|
"""
|
||||||
|
Test 'acpi' with no data
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.acpi.parse('', quiet=True), [])
|
||||||
|
|
||||||
|
def test_acpi_V_all(self):
|
||||||
|
"""
|
||||||
|
Test 'acpi -V' with all known options
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.acpi.parse(self.generic_acpi_V, quiet=True), self.generic_acpi_V_json)
|
||||||
|
|
||||||
|
def test_acpi_V2(self):
|
||||||
|
"""
|
||||||
|
Test 'acpi -V' from internet sample
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.acpi.parse(self.generic_acpi_V2, quiet=True), self.generic_acpi_V2_json)
|
||||||
|
|
||||||
|
def test_acpi_V3(self):
|
||||||
|
"""
|
||||||
|
Test 'acpi -V' from internet sample
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.acpi.parse(self.generic_acpi_V3, quiet=True), self.generic_acpi_V3_json)
|
||||||
|
|
||||||
|
def test_acpi_V4(self):
|
||||||
|
"""
|
||||||
|
Test 'acpi -V' from internet sample
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.acpi.parse(self.generic_acpi_V4, quiet=True), self.generic_acpi_V4_json)
|
||||||
|
|
||||||
|
def test_acpi_V_ubuntu(self):
|
||||||
|
"""
|
||||||
|
Test 'acpi -V' on Ubuntu 18.04
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.acpi.parse(self.ubuntu_18_04_acpi_V, quiet=True), self.ubuntu_18_04_acpi_V_json)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user