timofurrer / w1thermsensor

A Python package and CLI tool to work with w1 temperature sensors like DS1822, DS18S20 & DS18B20 on the Raspberry Pi, Beagle Bone and other devices.
MIT License
493 stars 113 forks source link

[Bug]: Doesn't run or test on Python 3.11 #116

Closed quentinmit closed 1 year ago

quentinmit commented 1 year ago

Erroneous Behavior

First problem:

$ python3.11 setup.py build
error in w1thermsensor setup command: 'python_requires' must be a string containing valid version specifiers; Invalid specifier: '>=3.5.*'

After resolving that by changing python_requires in setup.py to >=3.5, then one of the tests fails:

$ PYTHONPATH=build/lib/:$PYTHONPATH python3.11 -m pytest
_________________________ test_repr_protocol[sensors0] _________________________
sensors = [{'id': '1', 'temperature': 20, 'type': <Sensor.DS18B20: 40>}]
    @pytest.mark.parametrize(
        "sensors",
        [
            # just a sensor
            ({"type": Sensor.DS18B20, "id": "1"},)
        ],
        indirect=["sensors"],
    )
    def test_repr_protocol(sensors):
        """Test the __repr__ protocol of a sensor instance"""
        # given
        sensor = W1ThermSensor()
        # when
>       sensor_copy = eval(repr(sensor))
tests/test_core.py:517:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
<string>:1: in <module>
    ???
/nix/store/c0k0vlyqfhjddkrcapphgvhjhy5v7gf6-python3.11-w1thermsensor-2.0.0/lib/python3.11/site-packages/w1thermsensor/core.py:150: in __init__
    self.BASE_DIRECTORY / (self.slave_prefix + self.id) / self.SLAVE_FILE
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = W1ThermSensor(sensor_type=40, sensor_id='1')
    @property
    def slave_prefix(self) -> str:
        """Returns the slave prefix for this temperature sensor"""
>       return "%s-" % hex(self.type.value)[2:]
E       AttributeError: 'int' object has no attribute 'value'
/nix/store/c0k0vlyqfhjddkrcapphgvhjhy5v7gf6-python3.11-w1thermsensor-2.0.0/lib/python3.11/site-packages/w1thermsensor/core.py:222: AttributeError
=========================== short test summary info ============================
FAILED tests/test_core.py::test_repr_protocol[sensors0] - AttributeError: 'int' object has no attribute 'value'
======================== 1 failed, 144 passed in 1.90s =========================

Expected Behavior

Tests all pass

Steps to reproduce

sed -i 's/3\.5\.\*/3.5/' setup.py
python3.11 setup.py build
PYTHONPATH=build/lib/:$PYTHONPATH python3.11 -m pytest

Version

2.0.0

Python Version

3.11

Operating System

NixOS 22.11

Guidelines

timofurrer commented 1 year ago

@quentinmit thanks for the report 💙

I've updated the setup and supported Python versions.

There was actually a breaking change regarding the Enum __str__ and __repr__ interface in Python 3.11 which caused that issue -.^