From 89f1fd96e6b7aa0acf6272e4f3469005d4f7c6bf Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 16 Mar 2021 12:12:01 -0700 Subject: [PATCH] add acpi tests --- tests/fixtures/generic/acpi-V.json | 1 + tests/fixtures/generic/acpi-V2.json | 1 + tests/fixtures/generic/acpi-V3.json | 1 + tests/fixtures/generic/acpi-V4.json | 1 + tests/fixtures/ubuntu-18.04/acpi-V.json | 1 + tests/test_acpi.py | 82 +++++++++++++++++++++++++ 6 files changed, 87 insertions(+) create mode 100644 tests/fixtures/generic/acpi-V.json create mode 100644 tests/fixtures/generic/acpi-V2.json create mode 100644 tests/fixtures/generic/acpi-V3.json create mode 100644 tests/fixtures/generic/acpi-V4.json create mode 100644 tests/fixtures/ubuntu-18.04/acpi-V.json create mode 100644 tests/test_acpi.py diff --git a/tests/fixtures/generic/acpi-V.json b/tests/fixtures/generic/acpi-V.json new file mode 100644 index 00000000..e6d17ad7 --- /dev/null +++ b/tests/fixtures/generic/acpi-V.json @@ -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"]}] diff --git a/tests/fixtures/generic/acpi-V2.json b/tests/fixtures/generic/acpi-V2.json new file mode 100644 index 00000000..33b75ae2 --- /dev/null +++ b/tests/fixtures/generic/acpi-V2.json @@ -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"]}] diff --git a/tests/fixtures/generic/acpi-V3.json b/tests/fixtures/generic/acpi-V3.json new file mode 100644 index 00000000..0ada3f76 --- /dev/null +++ b/tests/fixtures/generic/acpi-V3.json @@ -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"]}] diff --git a/tests/fixtures/generic/acpi-V4.json b/tests/fixtures/generic/acpi-V4.json new file mode 100644 index 00000000..c57f0d7a --- /dev/null +++ b/tests/fixtures/generic/acpi-V4.json @@ -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"]}] diff --git a/tests/fixtures/ubuntu-18.04/acpi-V.json b/tests/fixtures/ubuntu-18.04/acpi-V.json new file mode 100644 index 00000000..1c1cdec3 --- /dev/null +++ b/tests/fixtures/ubuntu-18.04/acpi-V.json @@ -0,0 +1 @@ +[{"type": "Adapter", "id": 0, "on-line": true}, {"type": "Cooling", "id": 0, "messages": ["Processor 0 of 7"]}] diff --git a/tests/test_acpi.py b/tests/test_acpi.py new file mode 100644 index 00000000..389027da --- /dev/null +++ b/tests/test_acpi.py @@ -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()