Skip to content

MockPin 'breaks' the Pin interface? #206

@lurch

Description

@lurch

According to the "Abstract Pin" documentation

Warning: Descendents must ensure that pin instances representing the same physical hardware are identical, right down to object identity.

and MockPin is a descendant of Pin. I realise the MockPin doesn't refer to actual hardware, but it might be nice (for the sake of the unit-tests) if

from gpiozero.pins.mock import MockPin
pin1 = MockPin(3)
pin2 = MockPin(3)
print(pin1 == pin2)

printed True, as it does for all the other Pin subclasses (with the current MockPin implementation it prints False).
In turn, this would allow us to have unit-tests for checking that e.g.

from gpiozero.pins.mock import MockPin
from gpiozero import LED
led1 = LED(MockPin(3))
pin2 = LED(MockPin(3))

fails with GPIOPinInUse as all the other Pin subclasses do.

I tried having a go myself at modifying the MockPin class to behave like the other Pin implementations (by changing __init__ to __new__ , adding a _PINS dict, etc.) but that just caused a whole load of problems with MockPWMPin then not working.

Feel free to close this issue, if it's irrelevant and I've misunderstood things!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions