Skip to content

Commit

Permalink
Merge pull request #115 from BrianPugh/bugfix-setup-arguments
Browse files Browse the repository at this point in the history
Bugfix setup arguments
  • Loading branch information
BrianPugh authored Mar 13, 2023
2 parents f3ead8c + 2f2865b commit 16f6bf2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion belay/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def setup(
""" # noqa: D400
if f is None:
return wraps_partial(Device.setup, autoinit=autoinit, **kwargs) # type: ignore[reportGeneralTypeIssues]
if signature(f).parameters:
if signature(f).parameters and autoinit:
raise ValueError(
f"Method {f} decorated with "
'"@Device.setup(autoinit=True)" '
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ def get_times_bar(val):
assert 84 == device.get_times_bar(2)


def test_classes_setup_arguments(emulate_command):
class MyDevice(Device, skip=True):
@Device.setup
def setup1(baz=1):
foo = 11 # noqa: F841
bar = 41 # noqa: F841

@Device.setup()
def setup2(baz=2):
foo = 12 # noqa: F841
bar = 42 # noqa: F841

with MyDevice(emulate_command) as device:
device.setup1(baz=111)
assert device("foo") == 11
assert device("bar") == 41
assert device("baz") == 111

device.setup2(baz=222)
assert device("foo") == 12
assert device("bar") == 42
assert device("baz") == 222


def test_classes_setup_autoinit(emulate_command):
class MyDevice(Device, skip=True):
@Device.setup(autoinit=True)
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/test_function_decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import belay
from belay import Device


def test_setup_basic(emulated_device):
Expand Down Expand Up @@ -77,3 +78,24 @@ def foo():
emulated_device.close()

mock_teardown.assert_called_once()


def test_classdecorator_setup():
@Device.setup
def foo1():
pass

@Device.setup()
def foo2():
pass

@Device.setup(autoinit=True)
def foo3():
pass

with pytest.raises(ValueError):
# Provided an arg with autoinit=True is not allowed.

@Device.setup(autoinit=True)
def foo(arg1=1):
pass

0 comments on commit 16f6bf2

Please sign in to comment.