-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Any class function decorated with @Property, or any class attribute with a property as a value, will now be instrumented.
- Loading branch information
Showing
6 changed files
with
211 additions
and
16 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
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
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
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
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,105 @@ | ||
"""Tests for methods decorated with @property""" | ||
|
||
# pyright: reportMissingImports=false | ||
# pylint: disable=import-error,import-outside-toplevel | ||
import pytest | ||
from _appmap.test.helpers import DictIncluding | ||
|
||
pytestmark = [ | ||
pytest.mark.appmap_enabled, | ||
] | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup(with_data_dir): # pylint: disable=unused-argument | ||
# with_data_dir sets up sys.path so example_class can be imported | ||
pass | ||
|
||
|
||
def test_getter_instrumented(events): | ||
from example_class import ExampleClass | ||
|
||
ec = ExampleClass() | ||
|
||
actual = ExampleClass.read_only.__doc__ | ||
assert actual == "Read-only" | ||
|
||
assert ec.read_only == "read only" | ||
|
||
with pytest.raises(AttributeError, match=r".*(has no setter|can't set attribute).*"): | ||
# E AttributeError: can't set attribute | ||
|
||
ec.read_only = "not allowed" | ||
|
||
with pytest.raises(AttributeError, match=r".*(has no deleter|can't delete attribute).*"): | ||
del ec.read_only | ||
|
||
assert len(events) == 2 | ||
assert events[0].to_dict() == DictIncluding( | ||
{ | ||
"event": "call", | ||
"defined_class": "example_class.ExampleClass", | ||
"method_id": "read_only (get)", | ||
} | ||
) | ||
|
||
|
||
def test_accessible_instrumented(events): | ||
from example_class import ExampleClass | ||
|
||
ec = ExampleClass() | ||
assert ExampleClass.fully_accessible.__doc__ == "Fully-accessible" | ||
|
||
assert ec.fully_accessible == "fully accessible" | ||
|
||
ec.fully_accessible = "updated" | ||
# Check the value of the attribute directly, to avoid extra events | ||
assert ec._fully_accessible == "updated" # pylint: disable=protected-access | ||
|
||
del ec.fully_accessible | ||
|
||
# assert len(events) == 6 | ||
assert events[0].to_dict() == DictIncluding( | ||
{ | ||
"event": "call", | ||
"defined_class": "example_class.ExampleClass", | ||
"method_id": "fully_accessible (get)", | ||
} | ||
) | ||
|
||
assert events[2].to_dict() == DictIncluding( | ||
{ | ||
"event": "call", | ||
"defined_class": "example_class.ExampleClass", | ||
"method_id": "fully_accessible (set)", | ||
} | ||
) | ||
|
||
assert events[4].to_dict() == DictIncluding( | ||
{ | ||
"event": "call", | ||
"defined_class": "example_class.ExampleClass", | ||
"method_id": "fully_accessible (del)", | ||
} | ||
) | ||
|
||
|
||
def test_writable_instrumented(events): | ||
from example_class import ExampleClass | ||
|
||
ec = ExampleClass() | ||
assert ExampleClass.write_only.__doc__ == "Write-only" | ||
|
||
with pytest.raises(AttributeError, match=r".*(has no getter|unreadable attribute).*"): | ||
_ = ec.write_only | ||
|
||
ec.write_only = "updated example" | ||
|
||
assert len(events) == 2 | ||
assert events[0].to_dict() == DictIncluding( | ||
{ | ||
"event": "call", | ||
"defined_class": "example_class.ExampleClass", | ||
"method_id": "set_write_only (set)", | ||
} | ||
) |
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