Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: acpi parser: adhere code to the happy path to avoid nested branches #488

Merged
merged 3 commits into from
Nov 24, 2023
Merged

Conversation

lavafroth
Copy link
Contributor

Changes

  • Use python's any operator to check if a line contains 'Charging', 'Discharging', 'Full'
  • Ignore a line with 'rate information unavailable' the same way as a line with 'will never fully discharge'
  • Set the on-line property to the result of the boolean condition itself

@kellyjonbrazil
Copy link
Owner

Hi there - thanks for the contribution! It looks like the logic is not exactly the same for the 'rate information unavailable' branching as tests are failing:

======================================================================
ERROR: test_acpi_V3 (test_acpi.MyTests)
Test 'acpi -V' from internet sample
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/jc/jc/tests/test_acpi.py", line 77, in test_acpi_V3
    self.assertEqual(jc.parsers.acpi.parse(self.generic_acpi_V3, quiet=True), self.generic_acpi_V3_json)
  File "/home/runner/work/jc/jc/jc/parsers/acpi.py", line 391, in parse
    return _process(raw_output)
  File "/home/runner/work/jc/jc/jc/parsers/acpi.py", line 282, in _process
    entry['charge_remaining_hours'] = int(entry['charge_remaining'].split(':')[0])
ValueError: invalid literal for int() with base 10: 'rate'

======================================================================
ERROR: test_acpi_V_all (test_acpi.MyTests)
Test 'acpi -V' with all known options
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/jc/jc/tests/test_acpi.py", line 65, in test_acpi_V_all
    self.assertEqual(jc.parsers.acpi.parse(self.generic_acpi_V, quiet=True), self.generic_acpi_V_json)
  File "/home/runner/work/jc/jc/jc/parsers/acpi.py", line 391, in parse
    return _process(raw_output)
  File "/home/runner/work/jc/jc/jc/parsers/acpi.py", line 282, in _process
    entry['charge_remaining_hours'] = int(entry['charge_remaining'].split(':')[0])
ValueError: invalid literal for int() with base 10: 'rate'

======================================================================
ERROR: test_acpi_V_never_fully_discharge (test_acpi.MyTests)
Test 'acpi -V' with "never fully discharge" message
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/jc/jc/tests/test_acpi.py", line 95, in test_acpi_V_never_fully_discharge
    self.assertEqual(jc.parsers.acpi.parse(self.acpi_V_never_fully_discharge, quiet=True), self.acpi_V_never_fully_discharge_json)
  File "/home/runner/work/jc/jc/jc/parsers/acpi.py", line 391, in parse
    return _process(raw_output)
  File "/home/runner/work/jc/jc/jc/parsers/acpi.py", line 282, in _process
    entry['charge_remaining_hours'] = int(entry['charge_remaining'].split(':')[0])
ValueError: invalid literal for int() with base 10: 'discharging'

----------------------------------------------------------------------
Ran 1[35](https://github.com/kellyjonbrazil/jc/actions/runs/6964880989/job/18976769329?pr=488#step:6:36)6 tests in 7.8[57](https://github.com/kellyjonbrazil/jc/actions/runs/6964880989/job/18976769329?pr=488#step:6:58)s

FAILED (errors=3)
Error: Process completed with exit code 1.

You should be able to run tests locally with the ./runtests.sh script.

@lavafroth
Copy link
Contributor Author

lavafroth commented Nov 24, 2023 via email

@kellyjonbrazil kellyjonbrazil changed the base branch from master to dev November 24, 2023 17:30
@kellyjonbrazil
Copy link
Owner

Looks good - I'll merge into dev. Thanks!

@kellyjonbrazil kellyjonbrazil merged commit 71db67e into kellyjonbrazil:dev Nov 24, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants