Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RPi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ def setmode(mode):
BOARD - Use Raspberry Pi board numbers
BCM - Use Broadcom GPIO 00..nn numbers
"""
if _State.mode != UNKNOWN:
if _State.mode != UNKNOWN and _State.mode != mode:
raise ValueError("A different mode has already been set!")

if mode != BCM and mode != BOARD:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def test_is_iterable():
assert GPIO_DEVEL.is_iterable(i) is True


@pytest.mark.parametrize('GPIO_MODE', [GPIO.BCM, GPIO.BOARD])
def test_setmode_remain_silent_in_same_mode(GPIO_MODE):
GPIO_DEVEL.Reset()
GPIO.setmode(GPIO_MODE) # Set a mode first
try:
GPIO.setmode(GPIO_MODE) # Expect there is not exception being raised
except ValueError:
pytest.fail('Failed to due double setup')


def test_setmode_raise_double_setup_exception():
GPIO_DEVEL.Reset()
with pytest.raises(Exception):
Expand Down