-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f55fb45
commit d2d6301
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from quam.core.macro.method_macro import MethodMacro | ||
|
||
|
||
class TestClass: | ||
def __init__(self, value: int): | ||
self.value = value | ||
|
||
@MethodMacro | ||
def add(self, x: int) -> int: | ||
return self.value + x | ||
|
||
|
||
def test_method_macro_binding(): | ||
"""Test that MethodMacro correctly binds to instance methods""" | ||
obj = TestClass(5) | ||
assert isinstance(obj.add, MethodMacro) | ||
assert MethodMacro.is_macro_method(obj.add) | ||
assert obj.add.instance == obj | ||
|
||
|
||
def test_method_macro_apply(): | ||
"""Test that MethodMacro.apply works with instance methods""" | ||
obj = TestClass(5) | ||
assert obj.add.apply(3) == 8 # 5 + 3 | ||
assert obj.add(3) == 8 # Should work the same way | ||
|
||
|
||
def test_is_macro_method(): | ||
"""Test the is_macro_method static method""" | ||
obj = TestClass(5) | ||
|
||
assert MethodMacro.is_macro_method(obj.add) | ||
assert not MethodMacro.is_macro_method(lambda x: x) | ||
assert not MethodMacro.is_macro_method(42) | ||
|
||
|
||
def test_method_macro_preserves_metadata(): | ||
"""Test that MethodMacro preserves the original function's metadata""" | ||
|
||
def original(x: int) -> int: | ||
"""Test docstring""" | ||
return x | ||
|
||
decorated = MethodMacro(original) | ||
assert decorated.__doc__ == original.__doc__ | ||
assert decorated.__name__ == original.__name__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters