canonical / checkbox

Checkbox
https://checkbox.readthedocs.io
GNU General Public License v3.0
30 stars 47 forks source link

Replaced open(Path, ...) with Path.open(...) (BugFix) #1297

Closed p-gentili closed 3 months ago

p-gentili commented 3 months ago

Description

Built-in open() function does not support a pathlib.Path as input prior to Python 3.6. This PR fixes the problem using the Path.open() method instead.

When running with Python 3.5, the bluetooth/detect job fails with:

Traceback (most recent call last):
  File "/tmp/nest-xo3ruwnc.42f5de41bd7d4de9df695dad3244630364071fec43fbc8d7d2655bc1c56849b5/bt_list_adapters.py", line 91, in <module>
    sys.exit(main())
  File "/tmp/nest-xo3ruwnc.42f5de41bd7d4de9df695dad3244630364071fec43fbc8d7d2655bc1c56849b5/bt_list_adapters.py", line 82, in main
    rf_devices = get_bluetooth_devices(rf_devices_paths)
  File "/tmp/nest-xo3ruwnc.42f5de41bd7d4de9df695dad3244630364071fec43fbc8d7d2655bc1c56849b5/bt_list_adapters.py", line 70, in get_bluetooth_devices
    if is_bluetooth_adapter(rfdev):
  File "/tmp/nest-xo3ruwnc.42f5de41bd7d4de9df695dad3244630364071fec43fbc8d7d2655bc1c56849b5/bt_list_adapters.py", line 52, in is_bluetooth_adapter
    type = get_node_content(path / "type")
  File "/tmp/nest-xo3ruwnc.42f5de41bd7d4de9df695dad3244630364071fec43fbc8d7d2655bc1c56849b5/bt_list_adapters.py", line 39, in get_node_content
    with open(path, "r") as f:
TypeError: invalid file: PosixPath('/sys/class/rfkill/rfkill0/type')

Resolved issues

N/A

Documentation

N/A

Tests

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 44.16%. Comparing base (6f16853) to head (2314d94). Report is 115 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1297 +/- ## ======================================= Coverage 44.16% 44.16% ======================================= Files 359 359 Lines 38812 38812 Branches 6581 6581 ======================================= Hits 17141 17141 Misses 21007 21007 Partials 664 664 ``` | [Flag](https://app.codecov.io/gh/canonical/checkbox/pull/1297/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=canonical) | Coverage Δ | | |---|---|---| | [provider-base](https://app.codecov.io/gh/canonical/checkbox/pull/1297/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=canonical) | `18.56% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=canonical#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.