File: test_acpi.py

package info (click to toggle)
jc 1.25.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,104 kB
  • sloc: python: 70,400; sh: 724; xml: 278; makefile: 5
file content (105 lines) | stat: -rw-r--r-- 4,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import os
import unittest
import json
import jc.parsers.acpi

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


class MyTests(unittest.TestCase):

    # input
    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V.out'), 'r', encoding='utf-8') as f:
        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:
        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:
        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:
        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:
        ubuntu_18_04_acpi_V = f.read()

    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V-never-fully-discharge.out'), 'r', encoding='utf-8') as f:
        acpi_V_never_fully_discharge = f.read()

    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-not-charging.out'), 'r', encoding='utf-8') as f:
        acpi_not_charging = f.read()

    # output
    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V.json'), 'r', encoding='utf-8') as f:
        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:
        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:
        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:
        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:
        ubuntu_18_04_acpi_V_json = json.loads(f.read())

    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-V-never-fully-discharge.json'), 'r', encoding='utf-8') as f:
        acpi_V_never_fully_discharge_json = json.loads(f.read())

    with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/acpi-not-charging.json'), 'r', encoding='utf-8') as f:
        acpi_not_charging_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)

    def test_acpi_V_never_fully_discharge(self):
        """
        Test 'acpi -V' with "never fully discharge" message
        """
        self.assertEqual(jc.parsers.acpi.parse(self.acpi_V_never_fully_discharge, quiet=True), self.acpi_V_never_fully_discharge_json)

    def test_acpi_not_charging(self):
        """
        Test 'acpi' with "Not charging" message
        """
        self.assertEqual(jc.parsers.acpi.parse(self.acpi_not_charging, quiet=True), self.acpi_not_charging_json)


if __name__ == '__main__':
    unittest.main()